Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 125 → Rev 126

/trunk/DBViewer/delegate.cpp
60,6 → 60,66
}
//! [0]
 
void SpinBoxDelegate::setInctance(QString newInctance){
inctance = newInctance;
}
 
void SpinBoxDelegate::getItems(){
QMap <QString, QString> result_map;
QSqlQuery q;
QString query_str;
bool ok;
 
if (SpinBoxDelegate::inctance.isEmpty())
{
items.clear();
return;
}
 
query_str = tr("select * from `");
query_str.append(inctance);
query_str.append( tr("`"));
 
q.prepare(query_str);
 
 
ok = q.exec();
 
 
 
 
if (!ok) {
/*
QString error_str;
error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
error_str.append(inctance);
QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
this, // Ðîäèòåëüñêèé âèäæåò.
QObject::tr("Database Error"), // Çàãîëîâîê.
q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
// tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
 
*/
items.clear();
return;
}
 
 
// field_inctance = q.record().indexOf(tr("TableWhithInstance"));
while(q.next()){
 
QString ID;
QString Name;
ID = q.value(0).toString(); // îïðåäåëÿåì ID
Name = q.value(1).toString(); // îïðåäåëÿåì Name
items.insert(ID, Name);
}
 
 
// return result_map;
}
 
 
//! [1]
QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
68,7 → 128,21
//QSpinBox *editor = new QSpinBox(parent);
//editor->setMinimum(0);
//editor->setMaximum(100);
QStringList ID_list;
QStringList Name_list;
 
// getItems();
 
 
 
 
 
ID_list = items.keys();
Name_list = items.values();
 
QComboBox *editor = new QComboBox(parent);
 
/*
editor->addItem("0");
editor->addItem("1");
editor->addItem("2");
79,8 → 153,11
editor->addItem("7");
editor->addItem("8");
editor->addItem("9");
// editor->addItem("0");
*/
 
// editor->addItem("0");
 
editor->addItems(Name_list);
return editor;
}
//! [1]
95,6 → 172,17
// spinBox->setValue(value);
QString value = index.model()->data(index, Qt::EditRole).toString();
QComboBox *comboBox = static_cast<QComboBox*>(editor);
 
QStringList ID_list;
QStringList Name_list;
int curr_index;
 
ID_list = items.keys();
Name_list = items.values();
 
curr_index = ID_list.indexOf(value);
comboBox->setCurrentIndex(curr_index);
/****************************************************
if (value == "0") comboBox->setCurrentIndex(0);
if (value == "1") comboBox->setCurrentIndex(1);
if (value == "2") comboBox->setCurrentIndex(2);
105,6 → 193,7
if (value == "7") comboBox->setCurrentIndex(7);
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
******************************************************/
comboBox->setEditable(true);
 
 
122,11 → 211,18
// int value = spinBox->value();
 
// model->setData(index, value, Qt::EditRole);
QStringList ID_list;
QStringList Name_list;
 
QComboBox *comboBox = static_cast<QComboBox*>(editor);
int currIndex;
currIndex = comboBox->currentIndex();
QString value = comboBox->itemText(currIndex);
// QString value = comboBox->itemText(currIndex);
 
ID_list = items.keys();
Name_list = items.values();
 
QString value = ID_list.at(currIndex);
model->setData(index, value, Qt::EditRole);
}
//! [3]