Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 126 → Rev 127

/trunk/DBViewer/DBViewer.pro
4,14 → 4,22
QT += network \
opengl \
sql \
xml
script \
scripttools \
svg \
xml \
xmlpatterns \
multimedia \
qt3support
TARGET = DBViewer
TEMPLATE = app
SOURCES += main.cpp \
mainwindow.cpp \
database.cpp \
delegate.cpp
delegate.cpp \
mymodel.cpp
HEADERS += mainwindow.h \
delegate.h
delegate.h \
mymodel.h
FORMS += mainwindow.ui
RESOURCES += dbviewer.qrc
/trunk/DBViewer/mymodel.cpp
New file
0,0 → 1,124
#include "mymodel.h"
 
MyModel::MyModel(QObject *parent) :
QSqlTableModel(parent)
{
setEditStrategy(QSqlTableModel::OnManualSubmit);
}
 
Qt::ItemFlags MyModel::flags(
const QModelIndex &index) const {
Qt::ItemFlags flags = QSqlTableModel::flags(index);
 
/***********************************************
 
if ((index.column() != 3) && (index.column() != 0))
flags |= Qt::ItemIsEditable;
//if (index.column() == 4)
// flags |= Qt::ItemIsUserCheckable;
else
{
if ((index.column() == 3) || (index.column() == 0)) flags &= ~Qt::ItemIsEditable; // çàïðåùàåì ðåäàêòèðîâàíèå òðåòüåãî ñòîëáöà
}
 
*************************************************/
 
 
 
return flags;
}
 
 
bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role) {
//// if (index.column()==3) return false; // â òðåòüåé êîëîíêå íå äàåì ïîìåíÿòü çíà÷åíèå
bool lResult = false;
 
/*
QString str_tmp;
if (index.column()==1) { // åñëè ìåíÿåì èìÿ êëàññà
str_tmp = value.toString(); // òî ïîìåíÿåì è èìÿ òàáëèöû
str_tmp.append(tr(" instance"));
}
*/
/*
QString str_tmp;
if (index.column()==0) { // åñëè ìåíÿåì èìÿ êëàññà
str_tmp = value.toString(); // òî ïîìåíÿåì è èìÿ òàáëèöû
str_tmp.append(tr("_instance"));
}
*/
lResult = QSqlTableModel::setData(index, value, role);
 
 
 
/*****************************************************8
 
if (lResult) {
QModelIndex newindex;
QSqlRecord rec = record(index.row());
 
rec.setValue(index.column(), value);
rec.setGenerated(index.column(), true);
 
 
 
lResult = updateRowInTable(index.row(), rec);
/// QSqlTableModel::setData(newindex, QVariant(str_tmp), Qt::EditRole);
 
 
}
**********************************************/
 
 
 
 
return lResult;
 
 
 
 
 
}
 
 
 
QVariant MyModel::data(const QModelIndex &index, int role) const {
 
QVariant value = QSqlTableModel::data(index, role);
switch (role) {
case Qt::DisplayRole: return value;
case Qt::EditRole: return value;
case Qt::TextColorRole:
if(index.column() == 1)
return qVariantFromValue(QColor(Qt::blue));
else
return value;
case Qt::TextAlignmentRole: return value;
case Qt::FontRole:
if(index.column() == 1) {
QFont font = QFont("Helvetica", 16, QFont::Bold);
return qVariantFromValue(font);
}else
return value;
 
case Qt::BackgroundColorRole: {
int a = (index.row() % 2) ? 14 : 0;
if(index.column() == 2)
return qVariantFromValue(QColor(220,240-a,230-a));
else if(index.column() == 4)
return qVariantFromValue(QColor(200,220-a,255-a));
else
return value;
}
 
 
 
case Qt::CheckStateRole: return value;
 
case Qt::SizeHintRole:return value;
 
}
return value;
}
 
 
/trunk/DBViewer/mymodel.h
New file
0,0 → 1,23
#ifndef MYMODEL_H
#define MYMODEL_H
 
#include <QObject>
#include <QtGui>
#include <QSqlQueryModel>
#include <QSqlTableModel>
 
class MyModel : public QSqlTableModel {
Q_OBJECT
public:
explicit MyModel(QObject *parent = 0);
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &, const QVariant &, int);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
signals:
 
public slots:
 
};
 
#endif // MYMODEL_H
/trunk/DBViewer/mainwindow.cpp
27,7 → 27,10
MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("7"));
MainWindow::initComboBox();
getDatabaseData();
sql_mogel = new QSqlTableModel();
//// sql_mogel = new QSqlTableModel();
sql_mogel = new MyModel();
 
 
model_is_build = true;
connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex)));
ui->pushButton_3->setEnabled(false);
/trunk/DBViewer/mainwindow.h
4,6 → 4,8
 
//#include "mysql.h"
 
#include "mymodel.h"
 
#include "delegate.h"
 
#include <QMainWindow>
84,7 → 86,11
QMap <QString, QString> getFieldsList(QString class_id); // ïîëó÷àåì ñïèñîê ïîëåé êëàññà
void initComboBox();
QList<QTreeWidgetItem *> rootItems; // ñïèñîê óêàçàòåëåé êîðíåâûõ óçëîâ (ìîäåëåé)
QSqlTableModel * sql_mogel;
 
/////// QSqlTableModel * sql_mogel;
 
MyModel * sql_mogel;
 
int pointer_index; //èíäåêñ ïîëÿ-óêàçàòåëÿ íà ðîäèòåëüñêèé êëàññ
QString parentObject_id;
 
/trunk/DBViewer/database.cpp
377,8 → 377,11
ID = item->text(2);
inctance = parent_item->text(3);
delete sql_mogel;
sql_mogel = new QSqlTableModel();
// sql_mogel = new QSqlTableModel(this);
 
///////sql_mogel = new QSqlTableModel();
sql_mogel = new MyModel();
 
// sql_mogel = new QSqlTableModel(this);
sql_mogel->setTable(inctance);
// sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange);
sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit);
429,8 → 432,13
// pointer_name = parent_item->text(4);
pointer_name = item->text(4);
delete sql_mogel;
sql_mogel = new QSqlTableModel();
// sql_mogel = new QSqlTableModel(this);
 
 
////// sql_mogel = new QSqlTableModel();
 
sql_mogel = new MyModel();
 
// sql_mogel = new QSqlTableModel(this);
sql_mogel->setTable(inctance);
// sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange);
sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit);