Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 127 → Rev 128

/trunk/DBViewer/database.cpp
394,6 → 394,8
filtr_tmp.append(tr("'"));
sql_mogel->setFilter(filtr_tmp);
sql_mogel->select();
 
 
ui->tableView->setModel(sql_mogel);
ui->tableView->resizeColumnsToContents();
 
463,8 → 465,23
 
sql_mogel->select();
 
QMap <QString, QString> pointersList = getPointersList(class_id);
QMap <int, QString> pointersToModel;
 
QStringList pointersNames = pointersList.keys(); //
QStringList parentInctancesList = pointersList.values();
 
for (i=0; i < pointersNames.size(); i++){
QString pointerName;
 
int pointerIndex;
pointerName = pointersNames.at(i);
pointerIndex = sql_mogel->record().indexOf(pointerName);
pointersToModel.insert(pointerIndex, parentInctancesList.at(i));
}
 
sql_mogel->setPointers(pointersToModel);
 
pointer_index = sql_mogel->record().indexOf(pointer_name);
 
ui->tableView->setModel(sql_mogel);
555,3 → 572,55
 
 
}
 
 
// ïîëó÷àåì ñïèñîê âñåõ ïîëåé-óêàçàòåëåé, â êà÷åñòâå êëþ÷åé ïîëó÷èì èìåíà ïîëåé-óêàçàòåëåé
// â êà÷åñòâå çíà÷åíèé ïîëó÷èì ñïèñîê òàáëèö-õðàíèëèù îáúåêòîâ ðîäèòåëüñêèõ êëàññîâ
 
QMap <QString, QString> MainWindow::getPointersList(QString class_id){
QMap <QString, QString> result_map;
QSqlQuery q;
QString sql_str;
QString str_tmp;
QString field;
QString result;
int field_name, field_default_value;
bool ok;
sql_str = tr("select * "
" from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`ClassIdentifer` = " //íàõîäèì âñå îáúåêòû êëàññà â òàáëèöå - õðàíèëèùå îáúåêòîâ êëàññà
);
 
sql_str.append(tr("'"));
sql_str.append(class_id);
sql_str.append(tr("' "));
// sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '"));
// sql_str.append(chield_class_id);
// sql_str.append(tr("'"));
q.prepare(sql_str);
 
ok = q.exec();
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return result_map;
}
field_name = q.record().indexOf(tr("FieldName"));
field_default_value = q.record().indexOf(tr("DefaultValue"));
while(q.next()){
QString pointerFieldName;
QString parentClassID;
QString parentClassInctance;
 
pointerFieldName = q.value(field_name).toString();
parentClassID = q.value(field_default_value).toString();
parentClassInctance = getClassInctance(parentClassID);
result_map.insert(pointerFieldName, parentClassInctance);
 
 
}
 
return result_map;
}
 
/trunk/DBViewer/mymodel.cpp
85,9 → 85,35
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;
QList <int> keys;
QStringList values;
keys = pointers_map.keys(); // ñïèñîê ñòîëáöîâ ñ óêàçàòåëÿìè
values = pointers_map.values(); // ñïèñîê òàáëèö-õðàíèëèù îáúåêòîâ ðîäèòåëüñêèõ êëàññîâ
 
switch (role) {
case Qt::DisplayRole:
{
int index_of_list;
index_of_list = keys.indexOf(index.column());
 
if (index_of_list == -1) return value;
else {
QString psrentInctance;
psrentInctance = values.at(index_of_list);
int ii;
ii++;
}
return value;
 
}
// if (index.column() == 1)
// return value.toString().prepend(tr("¹ "));
 
 
case Qt::EditRole: return value;
// if (index.column() == 1)
// return value.toString().prepend(tr("¹ "));
 
case Qt::TextColorRole:
if(index.column() == 1)
return qVariantFromValue(QColor(Qt::blue));
/trunk/DBViewer/mymodel.h
5,6 → 5,7
#include <QtGui>
#include <QSqlQueryModel>
#include <QSqlTableModel>
#include <QMap>
 
class MyModel : public QSqlTableModel {
Q_OBJECT
13,6 → 14,11
Qt::ItemFlags flags(const QModelIndex &index) const;
bool setData(const QModelIndex &, const QVariant &, int);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void setPointers(QMap <int, QString> newPointers){pointers_map = newPointers;}
QMap <int, QString> pointers(){return pointers_map;}
private:
QMap <int, QString> pointers_map; // â ýòîì ñâÿçàííîì ñïèñêå áóäåõ õðàíèòü â êà÷åñòâå êëþ÷à íîìåðÿ ñòîëáöîâ ñ óêàçàòåëÿìè
// à â êà÷åñòâå çíà÷åíèé - èìåíà òàáëèö - õðàíèëèù îáúåêòîâ ðîäèòåëüñêîãî êëàññà
 
signals:
 
/trunk/DBViewer/mainwindow.h
104,6 → 104,8
void showObjects(QTreeWidgetItem * parent_object_item, QTreeWidgetItem * model_item, QString filtr);// // îòîáðàçèì îáúåêòû êëàññîâà
QString getPointerFieldName(QString parent_class_id, QString chield_class_id); // îïðåäåëÿåì èìÿ ïîëÿ, â êîòîðîì õðÿíÿòñÿ óêàçàòåëè íà îáúåêòû ðîäèòåëüñêîãî êëàññà
 
QMap <QString, QString> getPointersList(QString class_id); // ïîëó÷àåì ñïèñîê âñåõ ïîëåé-óêàçàòåëåé, â êà÷åñòâå êëþ÷åé ïîëó÷èì èìåíà ïîëåé-óêàçàòåëåé
// â êà÷åñòâå çíà÷åíèé ïîëó÷èì ñïèñîê òàáëèö-õðàíèëèù îáúåêòîâ ðîäèòåëüñêèõ êëàññîâ
SpinBoxDelegate spinDelegate;