Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 224 → Rev 225

/trunk/DBViewer/delegate.cpp
587,6 → 587,66
 
 
 
// ïîëó÷àåì èìÿ òàáëèöû - õðàíèëèùà îáúåêòîâ êëàññà
QString FilterValueDelegate::getClassInctanc(QString class_id){
 
 
 
 
QSqlQuery q;
QString sql_str;
QString result;
QString classInctance;
int field_inctance;
bool ok;
sql_str = tr("select * "
" from ListOfClasses where ListOfClasses.ID = '" //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
);
sql_str.append(class_id);
sql_str.append(tr("'"));
q.prepare(sql_str);
 
ok = q.exec();
 
if (!ok) return result;
 
/*
if (!ok) {
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
return result;
}
 
*/
 
 
 
 
field_inctance = q.record().indexOf(tr("TableWhithInstance"));
while(q.next()){
 
classInctance = q.value(field_inctance).toString();
result.append(classInctance);
}
 
return result;
 
 
 
 
 
}
 
 
 
QString grtFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ
{
 
}
 
 
//! [1]
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
614,11 → 674,20
// editor->addItem("0");
 
// // // editor->addItems(Name_list);
// editor->setEditable(false);
editor->setEditable(true);
return editor;
}
//! [1]
 
 
 
 
 
 
 
 
 
 
//! [2]
void FilterValueDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
635,7 → 704,45
QString value = index.model()->data(index, Qt::EditRole).toString();
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
QString inctance; //õðàíèëèùå îáúåêòîâ êëàññà
QString fieldName;//èìÿ ïîëÿ
QSqlQuery q;
QString sql_str;
QStringList itemsList;
bool ok;
 
 
 
fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
 
 
inctance = FilterValueDelegate::getClassInctanc(class_id);
if (!inctance.isEmpty() && !fieldName.isEmpty()){
sql_str = tr("select `");
sql_str.append(fieldName);
sql_str.append(tr("` from `"));
sql_str.append(inctance);
sql_str.append(tr("`"));
ok = q.prepare(sql_str);
ok = q.exec();
 
while(q.next()){
QString tmp_str;
tmp_str = q.record().value(fieldName).asString();
itemsList.append(tmp_str);
FilterValueDelegate::items.append(tmp_str);
}
if(!itemsList.isEmpty()) {
comboBox->addItems(itemsList);
items = itemsList; // ãëîáàëüãàÿ ïåðåìåííàÿ
}
 
}
 
 
 
 
 
//QStringList ID_list;
//QStringList Name_list;
int curr_index;
643,7 → 750,7
//ID_list = items.keys();
//Name_list = items.values();
 
curr_index = items.indexOf(value);
curr_index = itemsList.indexOf(value);
if (curr_index==-1) return;
comboBox->setCurrentIndex(curr_index);
/****************************************************
658,7 → 765,7
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
******************************************************/
comboBox->setEditable(false);
comboBox->setEditable(true);
 
 
//comboBox->setItemText(0, value);
675,6 → 782,7
// int value = spinBox->value();
 
// model->setData(index, value, Qt::EditRole);
 
QStringList ID_list;
QStringList Name_list;
 
690,7 → 798,17
// QString value = ID_list.at(currIndex);
QString value = items.at(currIndex);
model->setData(index, value, Qt::EditRole);
 
 
}
 
 
 
 
 
 
 
 
//! [3]
 
//! [4]
/trunk/DBViewer/delegate.h
123,7 → 123,10
 
QString class_id; // òàáëèöà-õðàíèëèùå, îòêóäà áóäåì áðàòü ñïèñîê
// QMap <QString, QString> items; // çäåñü áóäåì õðàíèòü ñâÿçàííûé ñïèñîê èìåò îáúåêòîâ è èõ èäåíòèôèêàòîðîâ ID
QStringList items; // ñïèñîê
mutable QStringList items; // ñïèñîê
static QString getClassInctanc(QString class_id);//îïðåäåëÿåì õðàíèëèùå îáúåêòîâ
static QString grtFieldType(QString class_id, QString fieldName);//îïðåäåëÿåì òèï äàííûõ ïîëÿ
 
};