Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 226 → Rev 227

/trunk/DBViewer/delegate.cpp
646,12 → 646,49
 
}
 
QMap<QString, QString> FilterValueDelegate::getItems(QString inctance){ // âîçâðàùàåì ñïèñîê âñåõ çíà÷åíèé èç òàáëèöû-õðàíèëèùà
QSqlQuery q;
QString sql_str;
QStringList keys_list;
QStringList values_list;
QMap<QString, QString> result_map;
 
 
 
 
bool ok;
sql_str = tr("select * from `");
sql_str.append(inctance);
sql_str.append(tr("`"));
ok = q.prepare(sql_str);
ok = q.exec();
if(!ok) return result_map;
while (q.next()){
QString key_tmp;
QString value_tmp;
 
key_tmp = q.record().value(0).asString(); //îïðåäåëÿåì id îáúåêòà
//keys_list.append(tmp_str); // äîáàâèì â ñïèñîê êëþ÷åé
 
value_tmp = q.record().value(1).asString(); //îïðåäåëÿåì èìÿ îáúåêòà
 
result_map.insert(key_tmp, value_tmp);
// values_list.append(tmp_str);
 
 
}
 
 
 
 
 
return result_map;
 
}
 
 
 
 
//! [1]
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
773,10 → 810,25
Field = getField(index);
 
 
if (Field.FieldType == tr("pointer")){ // åñëè äàííîå ïîëå õðàíèò óêàçàòåëè íà êëàññ-êîíòåéíåð
QString parent_inctance;
QMap<QString, QString> items_map;
QStringList items_list;
 
parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà
items_map = getItems(parent_inctance);
items_list = items_map.values();
 
comboBox->addItems(items_list);
if (items_list.indexOf(value)!=-1) comboBox->setCurrentIndex(items_list.indexOf(value));
return;
 
 
 
}
 
 
 
fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
 
 
847,21 → 899,71
 
// model->setData(index, value, Qt::EditRole);
 
QStringList ID_list;
QStringList Name_list;
 
QComboBox *comboBox = static_cast<QComboBox*>(editor);
int currIndex;
int currIndex;
currIndex = comboBox->currentIndex();
 
if (currIndex==-1) return;
// QString value = comboBox->itemText(currIndex);
 
QString new_value = comboBox->itemText(currIndex);
 
QString curr_value = model->data(index, Qt::EditRole).toString();//òåêóùåå çíà÷åíèå â ìîäåëè
 
 
 
QString class_id = model->data(model->index(index.row(),2), Qt::EditRole).toString();//îïðåäåëèì êëàññ, ê êîòîðîìó ïðåíàäëåæèò ïîëå
 
 
QStringList ID_list;
QStringList Name_list;
 
 
TField Field;
 
Field = getField(index);
 
if(Field.FieldType==tr("pointer")){
QString parent_inctance;
QMap<QString, QString> items_map;
QStringList keys_list; // ñïèñîê ID îáúåêòîâ ðîäèòåëüñêîãî êëàññà
QStringList values_list; //ñïèñîê èìåí îáúåêòîâ ðîäèòåëüñêîãî êëàññà
 
 
 
parent_inctance = getClassInctanc(Field.DefaultValue);// îïðåäåëÿåì õðàíèëèùå îáúåêòîâ êëàññà-êîíòåéíåðà
items_map = getItems(parent_inctance); //
keys_list = items_map.keys();
values_list = items_map.values();
 
if( values_list.indexOf(new_value)!=-1){ //
 
QString new_key = keys_list.at(values_list.indexOf(new_value)); // îïðåäåëÿåì íîâîå ØÂ
if (new_key != curr_value) model->setData(index, new_key, Qt::EditRole);
return;
}
 
 
 
 
}
 
 
 
 
 
 
 
// QString new_value = comboBox->itemText(currIndex);
 
 
 
 
// ID_list = items.keys();
// Name_list = items.values();
 
// QString value = ID_list.at(currIndex);
QString value = items.at(currIndex);
model->setData(index, value, Qt::EditRole);
// QString value = items.at(currIndex);
model->setData(index, new_value, Qt::EditRole);
 
 
}