Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 226 → Rev 227

/trunk/DBViewer/database.cpp
846,6 → 846,8
{
QString class_id;
QString model_id;
 
 
class_id = ui->treeWidget->currentItem()->text(1);
model_id = ui->treeWidget->currentItem()->text(6);
int row = filter_model->rowCount();
855,6 → 857,7
ui->pushButton_11->setEnabled(true);
ui->pushButton_12->setEnabled(true);
 
 
}
 
void MainWindow::on_pushButton_10_clicked()// íàæàòèå êíîïêè "Óäàëèòü ôèëüòð" (íà âêëàäêå ôèëüòðîâ)
887,6 → 890,18
model_is_build = true;
MainWindow::getDatabaseData();
 
disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
delete filter_model;
 
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
/// filter_model = new MyModel();
 
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
 
 
 
 
}
 
void MainWindow::on_pushButton_11_clicked()// íàæàòèå êíîïêè "Ïðèìåíèòü" (íà âêëàäêå ôèëüòðîâ)
900,6 → 915,17
MainWindow::readModels();
model_is_build = true;
MainWindow::getDatabaseData();
disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
delete filter_model;
 
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
/// filter_model = new MyModel();
 
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
 
 
 
}
 
void MainWindow::on_pushButton_12_clicked()// íàæàòèå êíîïêè "Ñáðîñèòü èçìåíåíèÿ" (íà âêëàäêå ôèëüòðîâ)
1456,9 → 1482,12
result_str.append(FieldName);
result_str.append(tr("`"));
result_str.append(ConditionalSymbol);
result_str.append(tr("'"));
result_str.append(ValueForComparison);
result_str.append(tr("' "));
 
if (!ValueForComparison.isEmpty()) {
result_str.append(tr("'"));
result_str.append(ValueForComparison);
result_str.append(tr("' "));
}
result_str.append(PostCondition);
 
 
/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);
 
 
}
/trunk/DBViewer/mainwindow.cpp
87,8 → 87,8
 
/// filter_model = new MyModel();
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
 
model_is_build = true;
connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex)));
connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex)));
869,6 → 869,7
 
filter_model = new QSqlTableModel();
/// filter_model = new MyModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
int index;
911,6 → 912,8
/// filter_model = new MyModel();
 
filter_model = new QSqlTableModel();
filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
 
connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex)));
filter_model->setTable(tr("Filters"));
filter_model->setFilter(filtr_str);
939,11 → 942,16
ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate);
 
conditionList.clear();
conditionList <<"" << "=" << "<" << ">" ;
conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL";
filterConditionDelegate_1.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1);
 
 
 
 
 
 
 
ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate);
 
 
/trunk/DBViewer/delegate.h
147,6 → 147,8
static QString getClassInctanc(QString class_id);//îïðåäåëÿåì õðàíèëèùå îáúåêòîâ
static QString getFieldType(QString class_id, QString fieldName);//îïðåäåëÿåì òèï äàííûõ ïîëÿ
static TField getField(const QModelIndex &index); // ïî èíäåêñó (â òàáëèöå ôèëüòðîâ) ïîëó÷èì èíôîðìàöèþ î ïîëå
static QMap<QString, QString> getItems(QString inctance); // âîçâðàùàåì ñïèñîê âñåõ çíà÷åíèé èç òàáëèöû-õðàíèëèùà
 
};