Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 218 → Rev 219

/trunk/DBViewer/mainwindow.h
109,7 → 109,10
/////// QSqlTableModel * sql_mogel;
 
MyModel * sql_mogel;
MyModel * filtr_model;
// MyModel * filtr_model;
 
QSqlTableModel * filtr_model;
 
QSqlTableModel * model_for_ListModelsTable;
 
void initListModelsTablle();
158,7 → 161,9
QItemDelegate standart_delegate;
CPictureDelegate * picture_delegate;
IconDelegate * iconDelegate;
FileDelegate * fileDelegate;
FileDelegate * fileDelegate; // äåëåãàò äëÿ òàáëèöû ñ ôèëüòðàìè, áóäêò îòîáðàæàòü ñïèñîê ïîëåé êëàññà
FilterSpinBoxDelegate filterSpinDelegate;
FilterConditionDelegate filterConditionDelegate, filterConditionDelegate_1, filterConditionDelegate_2;
bool comboBox_slot_enable; // äëÿ áëîêèðîâêè ñëîòà, êîãäà ìåíÿåì item_index èç ïðîãðàììû, à íå âðó÷íóþ
QList <int> boolFieldsIndexes_global; // ñïèñîê íîìåðîâ ñòîëáöîâ ñ òèïîì "BOOL"
 
/trunk/DBViewer/delegate.cpp
238,7 → 238,344
{
editor->setGeometry(option.rect);
}
 
 
 
 
 
 
 
 
 
 
 
//! [0]
FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
//! [0]
 
void FilterSpinBoxDelegate::setClassID(QString newClassID){
class_id = newClassID;
}
 
void FilterSpinBoxDelegate::getItems(){
QMap <QString, QString> result_map;
QSqlQuery q;
QString query_str;
bool ok;
 
if (FilterSpinBoxDelegate::class_id.isEmpty())
{
items.clear();
return;
}
 
query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '");
query_str.append(class_id);
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"));
items.clear();
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 *FilterSpinBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
//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");
editor->addItem("3");
editor->addItem("4");
editor->addItem("5");
editor->addItem("6");
editor->addItem("7");
editor->addItem("8");
editor->addItem("9");
*/
 
// editor->addItem("0");
 
editor->addItems(Name_list);
// editor->setEditable(false);
return editor;
}
//! [1]
 
//! [2]
void FilterSpinBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
// int value = index.model()->data(index, Qt::EditRole).toInt();
 
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// 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);
if (curr_index==-1) return;
comboBox->setCurrentIndex(curr_index);
/****************************************************
if (value == "0") comboBox->setCurrentIndex(0);
if (value == "1") comboBox->setCurrentIndex(1);
if (value == "2") comboBox->setCurrentIndex(2);
if (value == "3") comboBox->setCurrentIndex(3);
if (value == "4") comboBox->setCurrentIndex(4);
if (value == "5") comboBox->setCurrentIndex(5);
if (value == "6") comboBox->setCurrentIndex(6);
if (value == "7") comboBox->setCurrentIndex(7);
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
******************************************************/
comboBox->setEditable(false);
 
 
//comboBox->setItemText(0, value);
 
}
//! [2]
 
//! [3]
void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// spinBox->interpretText();
// 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();
if (currIndex==-1) return;
// QString value = comboBox->itemText(currIndex);
 
ID_list = items.keys();
Name_list = items.values();
 
// QString value = ID_list.at(currIndex);
QString value = Name_list.at(currIndex);
model->setData(index, value, Qt::EditRole);
}
//! [3]
 
//! [4]
void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
 
 
 
 
 
 
 
 
 
 
//! [0]
FilterConditionDelegate::FilterConditionDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
//! [0]
 
void FilterConditionDelegate::setClassID(QString newClassID){
class_id = newClassID;
}
 
 
 
//! [1]
QWidget *FilterConditionDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
QStringList Name_list;
 
Name_list = items;
 
QComboBox *editor = new QComboBox(parent);
 
/*
editor->addItem("0");
editor->addItem("1");
editor->addItem("2");
editor->addItem("3");
editor->addItem("4");
editor->addItem("5");
editor->addItem("6");
editor->addItem("7");
editor->addItem("8");
editor->addItem("9");
*/
 
// editor->addItem("0");
 
editor->addItems(Name_list);
// editor->setEditable(false);
return editor;
}
//! [1]
 
//! [2]
void FilterConditionDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
// int value = index.model()->data(index, Qt::EditRole).toInt();
 
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// 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 = items.indexOf(value);
if (curr_index==-1) return;
comboBox->setCurrentIndex(curr_index);
/****************************************************
if (value == "0") comboBox->setCurrentIndex(0);
if (value == "1") comboBox->setCurrentIndex(1);
if (value == "2") comboBox->setCurrentIndex(2);
if (value == "3") comboBox->setCurrentIndex(3);
if (value == "4") comboBox->setCurrentIndex(4);
if (value == "5") comboBox->setCurrentIndex(5);
if (value == "6") comboBox->setCurrentIndex(6);
if (value == "7") comboBox->setCurrentIndex(7);
if (value == "8") comboBox->setCurrentIndex(8);
if (value == "9") comboBox->setCurrentIndex(9);
******************************************************/
comboBox->setEditable(false);
 
 
//comboBox->setItemText(0, value);
 
}
//! [2]
 
//! [3]
void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
// QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
// spinBox->interpretText();
// 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();
if (currIndex==-1) return;
// QString 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);
}
//! [3]
 
//! [4]
void FilterConditionDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
 
 
 
 
 
 
 
 
 
 
//! [4]
MyDEDelegate::MyDEDelegate(
bool calpopup,
QObject *parent)
/trunk/DBViewer/mainwindow.cpp
877,6 → 877,7
QString class_id;
QString model_id;
QString filtr_str;
QStringList conditionList;
class_id = item->text(1);
model_id = item->text(6);
filtr_str = tr("`Model_ID` = ");
886,13 → 887,36
// filtr_str.append(tr("`"));
 
delete filtr_model;
filtr_model = new MyModel();
// filtr_model = new MyModel();
 
filtr_model = new QSqlTableModel();
filtr_model->setTable(tr("Filters"));
filtr_model->setFilter(filtr_str);
filtr_model->select();
ui->tableView_3->setModel(filtr_model);
 
 
ui->tableView_3->hideColumn(0);
ui->tableView_3->hideColumn(1);
ui->tableView_3->hideColumn(2);
 
 
filterSpinDelegate.setClassID(class_id);
filterSpinDelegate.getItems();
ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate);
 
 
conditionList <<"" << "and" << "or" << "(" << "and (" << "or (";
filterConditionDelegate.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate);
 
conditionList.clear();
conditionList <<"" << "=" << "<" << ">" ;
filterConditionDelegate_1.setItems(conditionList);
ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1);
 
 
 
ui->pushButton_9->setEnabled(true);
ui->pushButton_10->setEnabled(true);
 
/trunk/DBViewer/delegate.h
48,15 → 48,90
QString inctance; // òàáëèöà-õðàíèëèùå, îòêóäà áóäåì áðàòü ñïèñîê
QMap <QString, QString> items; // çäåñü áóäåì õðàíèòü ñâÿçàííûé ñïèñîê èìåò îáúåêòîâ è èõ èäåíòèôèêàòîðîâ ID
 
};
 
 
 
 
 
class FilterConditionDelegate : public QItemDelegate
{
Q_OBJECT
 
public:
FilterConditionDelegate(QObject *parent = 0);
 
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
 
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
 
 
 
void setClassID(QString newClassID);
// void getItems(); // ïîëó÷àåì ñâÿçàííûé ñïèñîê
 
void setItems(QStringList new_items){items = new_items;}
 
 
private:
 
 
QString class_id; // òàáëèöà-õðàíèëèùå, îòêóäà áóäåì áðàòü ñïèñîê
// QMap <QString, QString> items; // çäåñü áóäåì õðàíèòü ñâÿçàííûé ñïèñîê èìåò îáúåêòîâ è èõ èäåíòèôèêàòîðîâ ID
QStringList items; // ñïèñîê
};
 
 
 
 
//! [0]
class FilterSpinBoxDelegate : public QItemDelegate
{
Q_OBJECT
 
public:
FilterSpinBoxDelegate(QObject *parent = 0);
 
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
 
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
 
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
 
 
 
void setClassID(QString newClassID);
void getItems(); // ïîëó÷àåì ñâÿçàííûé ñïèñîê
 
 
 
 
private:
 
 
QString class_id; // òàáëèöà-õðàíèëèùå, îòêóäà áóäåì áðàòü ñïèñîê
QMap <QString, QString> items; // çäåñü áóäåì õðàíèòü ñâÿçàííûé ñïèñîê èìåò îáúåêòîâ è èõ èäåíòèôèêàòîðîâ ID
};
 
 
 
 
 
 
 
 
//! [0]
 
class MyDEDelegate : public QItemDelegate {
Q_OBJECT
public: