diff --git a/qelectrotech.pro b/qelectrotech.pro index 250751189..78c51d530 100644 --- a/qelectrotech.pro +++ b/qelectrotech.pro @@ -102,7 +102,8 @@ INCLUDEPATH += sources \ sources/NameList/ui \ sources/utils \ sources/pugixml \ - sources/dataBase + sources/dataBase \ + sources/dataBase/ui # Fichiers sources @@ -132,7 +133,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \ $$files(sources/NameList/ui/*.h) \ $$files(sources/utils/*.h) \ $$files(sources/pugixml/*.hpp) \ - $$files(sources/dataBase/*.h) + $$files(sources/dataBase/*.h) \ + $$files(sources/dataBase/ui/*.h) SOURCES += $$files(sources/*.cpp) \ $$files(sources/editor/*.cpp) \ @@ -161,7 +163,8 @@ SOURCES += $$files(sources/*.cpp) \ $$files(sources/NameList/ui/*.cpp) \ $$files(sources/utils/*.cpp) \ $$files(sources/pugixml/*.cpp) \ - $$files(sources/dataBase/*.cpp) + $$files(sources/dataBase/*.cpp) \ + $$files(sources/dataBase/ui/*.cpp) # Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt RESOURCES += qelectrotech.qrc @@ -184,7 +187,8 @@ FORMS += $$files(sources/richtext/*.ui) \ $$files(sources/ui/configpage/*.ui) \ $$files(sources/SearchAndReplace/ui/*.ui) \ $$files(sources/NameList/ui/*.ui) \ - $$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) + $$files(sources/qetgraphicsitem/ViewItem/ui/*.ui) \ + $$files(sources/dataBase/ui/*.ui) UI_SOURCES_DIR = sources/ui/ UI_HEADERS_DIR = sources/ui/ diff --git a/sources/dataBase/projectdatabase.cpp b/sources/dataBase/projectdatabase.cpp index ed0e218e8..76732cd9a 100644 --- a/sources/dataBase/projectdatabase.cpp +++ b/sources/dataBase/projectdatabase.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2020 QElectroTech Team This file is part of QElectroTech. @@ -20,6 +20,8 @@ #include "qetproject.h" #include "elementprovider.h" #include "element.h" +#include "diagram.h" +#include "diagramposition.h" #include @@ -36,6 +38,13 @@ projectDataBase::projectDataBase(QETProject *project, QObject *parent) : createDataBase(); } +projectDataBase::projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent) : + QObject(parent), + m_project(project) +{ + createDataBase(connection_name, path); +} + /** * @brief projectDataBase::~projectDataBase * Destructor @@ -75,6 +84,39 @@ QVector projectDataBase::elementsInfoFromQuery(const QString &query return result_; } +/** + * @brief projectDataBase::headersFromElementsInfoQuery + * @param query + * @return the header according to @query. + * Header can be false, notably when user create is own query. + */ +QStringList projectDataBase::headersFromElementsInfoQuery(const QString &query) +{ + QStringList header_string; + if (query.startsWith("SELECT ") && query.contains("FROM")) + { + auto header = query; + header.remove(0, 7); //Remove SELECT from the string; + header.truncate(header.indexOf("FROM")); //Now we only have the string between SELECT and FROM + header.replace(" ", ""); //remove white space + QStringList list = header.split(","); + + if (!list.isEmpty()) + { + for (int i=0 ; iuuid().toString()); + + QString connect_name=connection_name; + if (connect_name.isEmpty()) { + connect_name = "qet_project_db_" + m_project->uuid().toString(); + } if (m_data_base.connectionNames().contains(connect_name)) { m_data_base = QSqlDatabase::database(connect_name); } else { m_data_base = QSqlDatabase::addDatabase("QSQLITE", connect_name); + m_data_base.setDatabaseName(name); if(!m_data_base.open()) { m_data_base.close(); @@ -177,6 +232,7 @@ void projectDataBase::populateElementsTable() query.bindValue(":element_type", elmt->linkTypeToString()); query.bindValue(":element_subtype", elmt->kindInformations()["type"].toString()); + query.bindValue(":pos", elmt->diagram()->convertPosition(elmt->scenePos()).toString()); if (!query.exec()) { qDebug() << "projectDataBase::populateElementsTable insert error : " << query.lastError(); @@ -210,10 +266,47 @@ QHash projectDataBase::elementInfoToString(Element *elmt) * @brief projectDataBase::elementsInfoKeys * @return QETApp::elementInfoKeys() + "element_type" and "element_subtype" */ -QStringList projectDataBase::elementsInfoKeys() const +QStringList projectDataBase::elementsInfoKeys() { auto keys_ = QETApp::elementInfoKeys(); - keys_<< "element_type" << "element_subtype"; + keys_<< "element_type" << "subtype" << "pos"; return keys_; } + +/** + * @brief projectDataBase::exportDb + * @param parent + * @param caption + * @param dir + * @param filter + * @param selectedFilter + * @param options + */ +void projectDataBase::exportDb(projectDataBase *db, QWidget *parent, const QString &caption, const QString &dir) +{ + auto caption_ = caption; + if (caption_.isEmpty()) { + caption_ = tr("Exporter la base de données interne du projet"); + } + + auto dir_ = dir; + if(dir_.isEmpty()) { + dir_ = db->project()->filePath(); + if (dir_.isEmpty()) { + dir_ = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first(); + dir_ += QString("/") += tr("sans_nom") += ".sqlite"; + } else { + dir_.remove(".qet"); + dir_.append(".sqlite"); + } + } + + auto path_ = QFileDialog::getSaveFileName(parent, caption_, dir_, "*.sqlite"); + if (path_.isNull()) { + return; + } + + //Database is filled at creation, work is done. + projectDataBase file_db(db->project(), "export_project_db_" + db->project()->uuid().toString(), path_); +} diff --git a/sources/dataBase/projectdatabase.h b/sources/dataBase/projectdatabase.h index 0b89a202a..44da85046 100644 --- a/sources/dataBase/projectdatabase.h +++ b/sources/dataBase/projectdatabase.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2020 QElectroTech Team This file is part of QElectroTech. @@ -22,6 +22,7 @@ #include #include #include +#include class Element; class QETProject; @@ -39,24 +40,33 @@ class projectDataBase : public QObject public: projectDataBase(QETProject *project, QObject *parent = nullptr); + private: + projectDataBase(QETProject *project, const QString &connection_name, const QString &path, QObject *parent = nullptr); + public: virtual ~projectDataBase() override; QVector elementsInfoFromQuery(const QString &query); void updateDB(); + QETProject *project() const; + + static QStringList elementsInfoKeys(); + static QStringList headersFromElementsInfoQuery(const QString &query); signals: void dataBaseUpdated(); private: - bool createDataBase(); + bool createDataBase(const QString &connection_name= QString(), const QString &name = QString()); void populateElementsTable(); static QHash elementInfoToString(Element *elmt); - QStringList elementsInfoKeys() const; private: QPointer m_project; QSqlDatabase m_data_base; QSqlQuery m_insert_elements_query; + + public: + static void exportDb(projectDataBase *db, QWidget *parent = nullptr, const QString &caption = QString(), const QString &dir = QString()); }; #endif // PROJECTDATABASE_H diff --git a/sources/dataBase/ui/elementquerywidget.cpp b/sources/dataBase/ui/elementquerywidget.cpp new file mode 100644 index 000000000..236987b13 --- /dev/null +++ b/sources/dataBase/ui/elementquerywidget.cpp @@ -0,0 +1,274 @@ +/* + Copyright 2006-2020 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "elementquerywidget.h" +#include "ui_elementquerywidget.h" +#include "qetapp.h" + +/** + * @brief ElementQueryWidget::ElementQueryWidget + * @param parent + */ +ElementQueryWidget::ElementQueryWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::ElementQueryWidget) +{ + ui->setupUi(this); + + m_export_info.insert("pos", tr("Position")); +// m_export_info.insert("folio_title", tr("Titre du folio")); +// m_export_info.insert("folio_pos", tr("Position de folio")); +// m_export_info.insert("folio_num", tr("Numéro de folio")); +// m_export_info.insert("designation_qty", tr("Quantité (Numéro d'article)")); + + m_button_group.setExclusive(false); + m_button_group.addButton(ui->m_all_cb, 0); + m_button_group.addButton(ui->m_terminal_cb, 1); + m_button_group.addButton(ui->m_simple_cb, 2); + m_button_group.addButton(ui->m_button_cb, 3); + m_button_group.addButton(ui->m_coil_cb, 4); + m_button_group.addButton(ui->m_protection_cb, 5); + connect(&m_button_group, static_cast(&QButtonGroup::buttonClicked), [this](int id) + { + auto check_box = static_cast(m_button_group.button(0)); + if (id == 0) + { + switch (check_box->checkState()) { + case Qt::Checked : + for (auto button : m_button_group.buttons()) { + button->setChecked(true); + } + break; + case Qt::Unchecked : + for (auto button : m_button_group.buttons()) { + button->setChecked(false); + } + break; + default: break; + } + } + else + { + int checked = 0; + for (int i=1 ; i<5 ; ++i) { + if (m_button_group.button(i)->isChecked()) {++checked;} + } + + switch (checked) + { + case 0 : + check_box->setCheckState(Qt::Unchecked); + break; + case 5: + check_box->setCheckState(Qt::Checked); + break; + default: + check_box->setCheckState(Qt::PartiallyChecked); + break; + } + } + + updateQueryLine(); + }); + + setUpItems(); +} + +/** + * @brief ElementQueryWidget::~ElementQueryWidget + */ +ElementQueryWidget::~ElementQueryWidget() { + delete ui; +} + +/** + * @brief ElementQueryWidget::queryStr + * @return The current query + */ +QString ElementQueryWidget::queryStr() const +{ + //User define is own query + if (ui->m_edit_sql_query_cb->isChecked()) { + return ui->m_sql_query->text(); + } + //Made a string list with the colomns (keys) choosen by the user + QStringList keys = selectedKeys(); + + QString select ="SELECT "; + QString order_by = " ORDER BY "; + + QString column; + bool first = true; + for (auto key: keys) { + if (first) { + first = false; + } else { + column += ", "; + order_by += ", "; + } + column += key; + order_by += key; + } + + QString from = " FROM element_info"; + QString where; + if (ui->m_all_cb->checkState() == Qt::PartiallyChecked) + { + if (ui->m_terminal_cb->isChecked()) { + where = " WHERE element_type = 'Terminale'"; + } + if (ui->m_simple_cb->isChecked()) { + auto str = where.isEmpty() ? " WHERE element_type = 'Simple'" : " AND element_type = 'Simple'"; + where += str; + } + if (ui->m_button_cb->isChecked()) { + auto str = where.isEmpty() ? " WHERE element_subtype = 'commutator'" : " AND element_subtype = 'commutator'"; + where += str; + } + if (ui->m_coil_cb->isChecked()) { + auto str = where.isEmpty() ? " WHERE element_subtype = 'coil'" : " AND element_subtype = 'coil'"; + where += str; + } + if (ui->m_protection_cb->isChecked()) { + auto str = where.isEmpty() ? " WHERE element_subtype = 'protection'" : " AND element_subtype = 'protection'"; + where += str; + } + } + + QString q(select + column + from + where + order_by); + return q; +} + +/** + * @brief ElementQueryWidget::updateQueryLine + */ +void ElementQueryWidget::updateQueryLine() { + ui->m_sql_query->setText(queryStr()); +} + +/** + * @brief ElementQueryWidget::selectedKeys + * @return the current keys of selected infos to be exported + */ +QStringList ElementQueryWidget::selectedKeys() const +{ + //Made a string list with the colomns (keys) choosen by the user + QStringList keys; + int row = 0; + while (auto *item = ui->m_choosen_list->item(row)) + { + keys.append(item->data(Qt::UserRole).toString()); + ++row; + } + + return keys; +} + +void ElementQueryWidget::setUpItems() +{ + for(QString key : QETApp::elementInfoKeys()) + { + auto item = new QListWidgetItem(QETApp::elementTranslatedInfoKey(key), ui->m_var_list); + item->setData(Qt::UserRole, key); + m_items_list << item; + } + + for (auto key : m_export_info.keys()) + { + auto item = new QListWidgetItem(m_export_info.value(key), ui->m_var_list); + item->setData(Qt::UserRole, key); + m_items_list << item; + } +} + +/** + * @brief ElementQueryWidget::on_m_up_pb_clicked + */ +void ElementQueryWidget::on_m_up_pb_clicked() +{ + auto row = ui->m_choosen_list->currentRow(); + if(row <= 0) { + return; + } + + auto *item = ui->m_choosen_list->takeItem(row); + ui->m_choosen_list->insertItem(row-1, item); + ui->m_choosen_list->setCurrentItem(item); + + updateQueryLine(); +} + +/** + * @brief ElementQueryWidget::on_m_add_pb_clicked + */ +void ElementQueryWidget::on_m_add_pb_clicked() +{ + if (auto *item = ui->m_var_list->takeItem(ui->m_var_list->currentRow())) { + ui->m_choosen_list->addItem(item); + } + + updateQueryLine(); +} + +/** + * @brief ElementQueryWidget::on_m_remove_pb_clicked + */ +void ElementQueryWidget::on_m_remove_pb_clicked() +{ + if (auto *item = ui->m_choosen_list->takeItem(ui->m_choosen_list->currentRow())) { + ui->m_var_list->addItem(item); + } + + updateQueryLine(); +} + +/** + * @brief ElementQueryWidget::on_m_down_pb_clicked + */ +void ElementQueryWidget::on_m_down_pb_clicked() +{ + auto row = ui->m_choosen_list->currentRow(); + if (row == -1) { + return; + } + + auto *item = ui->m_choosen_list->takeItem(row); + ui->m_choosen_list->insertItem(row+1, item); + ui->m_choosen_list->setCurrentItem(item); + + updateQueryLine(); +} + +/** + * @brief ElementQueryWidget::on_m_edit_sql_query_cb_clicked + */ +void ElementQueryWidget::on_m_edit_sql_query_cb_clicked() +{ + ui->m_sql_query->setEnabled(ui->m_edit_sql_query_cb->isChecked()); + ui->m_info_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); + ui->m_parametre_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); + + if (ui->m_edit_sql_query_cb->isChecked() && !m_custom_query.isEmpty()) + { + ui->m_sql_query->setText(m_custom_query); + } + else if (!ui->m_edit_sql_query_cb->isChecked()) + { + m_custom_query = ui->m_sql_query->text(); + updateQueryLine(); + } +} diff --git a/sources/dataBase/ui/elementquerywidget.h b/sources/dataBase/ui/elementquerywidget.h new file mode 100644 index 000000000..4b9e126ba --- /dev/null +++ b/sources/dataBase/ui/elementquerywidget.h @@ -0,0 +1,64 @@ +/* + Copyright 2006-2020 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef ELEMENTQUERYWIDGET_H +#define ELEMENTQUERYWIDGET_H + +#include +#include + +class QListWidgetItem; + +namespace Ui { +class ElementQueryWidget; +} + +/** + * @brief The ElementQueryWidget class + * A widget use to edit a sql query for get element information + * This widget only work to get information from ProjectDataBase + */ +class ElementQueryWidget : public QWidget +{ + Q_OBJECT + + public: + explicit ElementQueryWidget(QWidget *parent = nullptr); + ~ElementQueryWidget(); + + QString queryStr() const; + + private slots: + void on_m_up_pb_clicked(); + void on_m_add_pb_clicked(); + void on_m_remove_pb_clicked(); + void on_m_down_pb_clicked(); + void on_m_edit_sql_query_cb_clicked(); + + void updateQueryLine(); + QStringList selectedKeys() const; + void setUpItems(); + + private: + Ui::ElementQueryWidget *ui; + QHash m_export_info; + QButtonGroup m_button_group; + QList m_items_list; + QString m_custom_query; +}; + +#endif // ELEMENTQUERYWIDGET_H diff --git a/sources/dataBase/ui/elementquerywidget.ui b/sources/dataBase/ui/elementquerywidget.ui new file mode 100644 index 000000000..deacb2419 --- /dev/null +++ b/sources/dataBase/ui/elementquerywidget.ui @@ -0,0 +1,363 @@ + + + ElementQueryWidget + + + + 0 + 0 + 341 + 457 + + + + Form + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Informations disponibles + + + Qt::AlignCenter + + + + + + + Informations à exporter + + + Qt::AlignCenter + + + 0 + + + + + + + + + + + + + 6 + + + QLayout::SetDefaultConstraint + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Monter la sélection + + + + + + + :/ico/16x16/go-up.png:/ico/16x16/go-up.png + + + false + + + + + + + Ajouter la sélection + + + + + + + :/ico/16x16/list-add.png:/ico/16x16/list-add.png + + + + + + + Supprimer la sélection + + + + + + + :/ico/16x16/list-remove.png:/ico/16x16/list-remove.png + + + + + + + Descendre la sélection + + + + + + + :/ico/16x16/go-down.png:/ico/16x16/go-down.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Type d'éléments + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + Simples + + + true + + + + + + + Tous + + + true + + + + + + + Contacteurs et relais + + + true + + + + + + + Boutons et commutateurs + + + true + + + + + + + Borniers + + + true + + + + + + + Organes de protection + + + true + + + + + + + + + + + + + Qt::Horizontal + + + + + + + Configuration + + + + + + true + + + Ouvrir la configuration sélectionné + + + + + + + :/ico/16x16/folder-open.png:/ico/16x16/folder-open.png + + + + + + + false + + + + + + + + + + false + + + Sauvegarder la configuration actuelle + + + + + + + :/ico/16x16/document-save.png:/ico/16x16/document-save.png + + + false + + + + + + + + + + QFrame::Sunken + + + Qt::Horizontal + + + + + + + + + Requête SQL personnalisée + + + + + + + + + + Requête SQL : + + + + + + + false + + + + + + + + + + + + diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index ccd4e5dc2..b4bbd335d 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -412,16 +412,11 @@ void QETDiagramEditor::setUpActions() /*******ONLY FOR TEST DURING DEVEL*********/ auto model = new NomenclatureModel(this->currentProject(), this->currentProject()); - model->query("SELECT plant, location, label, comment, description FROM element_info ORDER BY plant, location, label, comment, description"); + model->query("SELECT plant, location, label, pos, comment, description FROM element_info ORDER BY plant, location, label, comment, description"); model->setData(model->index(0,0), Qt::AlignLeft, Qt::TextAlignmentRole); model->setData(model->index(0,0), QETApp::diagramTextsFont(), Qt::FontRole); model->setHeaderData(0, Qt::Horizontal, Qt::AlignHCenter, Qt::TextAlignmentRole); model->setHeaderData(0, Qt::Horizontal, QETApp::diagramTextsFont(), Qt::FontRole); - model->setHeaderData(0, Qt::Horizontal, "Installation"); - model->setHeaderData(1, Qt::Horizontal, "Localisation"); - model->setHeaderData(2, Qt::Horizontal, "Label"); - model->setHeaderData(3, Qt::Horizontal, "Commentaire"); - model->setHeaderData(4, Qt::Horizontal, "Description"); table->setModel(model); /******************************************/ @@ -444,6 +439,11 @@ void QETDiagramEditor::setUpActions() wne.toCsv(); } }); + + m_export_project_db = new QAction(QET::Icons::DocumentSpreadsheet, tr("Exporter la base de donnée interne du projet"), this); + connect(m_export_project_db, &QAction::triggered, [this]() { + projectDataBase::exportDb(this->currentProject()->dataBase(), this); + }); //MDI view style m_tabbed_view_mode = new QAction(tr("en utilisant des onglets"), this); @@ -789,6 +789,8 @@ void QETDiagramEditor::setUpMenu() { menu_project -> addAction(m_csv_export); menu_project -> addAction(m_project_export_conductor_num); menu_project -> addAction(m_project_terminalBloc); + menu_project -> addSeparator(); + menu_project -> addAction(m_export_project_db); main_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils principale")); view_tool_bar -> toggleViewAction() -> setStatusTip(tr("Affiche ou non la barre d'outils Affichage")); diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 0f3948eb3..1b9130c5e 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -187,6 +187,7 @@ class QETDiagramEditor : public QETMainWindow QAction *m_add_nomenclature; ///< Add nomenclature graphics item; QAction *m_project_terminalBloc; ///< generate terminal block QAction *m_project_export_conductor_num; ///setHeaderData(i, Qt::Horizontal, headers.at(i)); + } + emit beginResetModel(); + } + m_query = query; - if (m_project) { + if (m_project) + { + if (rm_) { + disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated); + } m_project->dataBase()->updateDB(); + if (rm_) { + m_record = m_project->dataBase()->elementsInfoFromQuery(m_query); + connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated); + } } + + if (rm_) { emit endResetModel();} +} + +QETProject *NomenclatureModel::project() const { + return m_project.data(); } /** @@ -173,10 +201,22 @@ void NomenclatureModel::query(const QString &query) */ void NomenclatureModel::dataBaseUpdated() { - m_record.clear(); - m_record = m_project->dataBase()->elementsInfoFromQuery(m_query); + auto new_record = m_project->dataBase()->elementsInfoFromQuery(m_query); - auto row = m_record.size(); - auto col = row ? m_record.first().count() : 1; - emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); + //This a very special case, if this nomenclature model is added + //befor any element, column count return 0, so in this case we emit column inserted + if (new_record.size() != m_record.size()) + { + emit beginInsertColumns(index(0,0), 0, m_record.size()-1); + m_record = new_record; + emit endInsertColumns(); + } + else + { + m_record = new_record; + auto row = m_record.size(); + auto col = row ? m_record.first().count() : 1; + + emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); + } } diff --git a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h index bdc45c196..b9f9cecc3 100644 --- a/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h +++ b/sources/qetgraphicsitem/ViewItem/nomenclaturemodel.h @@ -42,6 +42,7 @@ class NomenclatureModel : public QAbstractTableModel bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void query(const QString &query); + QETProject *project() const; private: void dataBaseUpdated(); diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp index 29a6a3ef0..c2c26d40a 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp @@ -42,10 +42,14 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model) { if (m_model) { disconnect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged); + disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted); + disconnect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted); } m_model = model; connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged); + connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted); + connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted); setUpMinimumSectionsSize(); m_current_sections_width.clear(); m_current_sections_width.resize(m_sections_minimum_width.size()); @@ -264,3 +268,11 @@ void QetGraphicsHeaderItem::adjustSize() update(); } + +void QetGraphicsHeaderItem::modelReseted() +{ + setUpMinimumSectionsSize(); + m_current_sections_width.clear(); + m_current_sections_width.resize(m_sections_minimum_width.size()); + adjustSize(); +} diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h index e192c5eb4..d3d30fe44 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h @@ -68,6 +68,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject void setUpBoundingRect(); void headerDataChanged(Qt::Orientations orientation, int first, int last); void adjustSize(); + void modelReseted(); private: QRectF m_bounding_rect; diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index 899a33247..529536df9 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -66,8 +66,10 @@ QetGraphicsTableItem::~QetGraphicsTableItem() */ void QetGraphicsTableItem::setModel(QAbstractItemModel *model) { - if (m_model) { + if (m_model) + { disconnect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged); + disconnect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted); } m_model = model; m_header_item->setModel(model); @@ -77,6 +79,7 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model) m_header_item->setPos(0, -m_header_item->rect().height()); connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged); + connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted); } /** @@ -274,6 +277,10 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even return false; } +void QetGraphicsTableItem::modelReseted() { + dataChanged(m_model->index(0,0), m_model->index(0,0), QVector()); +} + /** * @brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize * Calcule the minimum row height and the minimum column width for each columns @@ -377,7 +384,8 @@ void QetGraphicsTableItem::adjustColumnsWidth() auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0 for(auto i= 0 ; icolumnCount() ; ++i) { - m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(i), m_header_item->minimumSectionWidth().at(i)) + b); + m_header_item->resizeSection(i, std::max(m_minimum_column_width.at(std::min(m_minimum_column_width.size()-1, i)), + m_header_item->minimumSectionWidth().at(std::min(m_header_item->minimumSectionWidth().size()-1, i))) + b); } } @@ -391,7 +399,6 @@ void QetGraphicsTableItem::dataChanged(const QModelIndex &topLeft, const QModelI setUpColumnAndRowMinimumSize(); adjustSize(); setSize(size_); - qDebug() << "data changed"; } /** diff --git a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp index 811d8975b..35355aad5 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp +++ b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp @@ -18,6 +18,10 @@ #include "nomenclaturemodelpropertieswidget.h" #include "ui_nomenclaturemodelpropertieswidget.h" #include "nomenclaturemodel.h" +#include "qetproject.h" +#include "elementquerywidget.h" + +#include /** * @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget @@ -49,11 +53,30 @@ void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) { m_model = model; } +/** + * @brief NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked + */ void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked() -{} +{ + QDialog d(this); + auto l = new QVBoxLayout(this); + d.setLayout(l); -void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() { - if (m_model) { - m_model->query("SELECT plant, location, label, comment, description FROM element_info ORDER BY plant, location, label, comment, description"); + auto query_widget = new ElementQueryWidget(&d); + l->addWidget(query_widget); + + auto button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + l->addWidget(button_box); + connect(button_box, &QDialogButtonBox::accepted, &d, &QDialog::accept); + connect(button_box, &QDialogButtonBox::rejected, &d, &QDialog::reject); + + if (d.exec()) { + m_model->query(query_widget->queryStr()); + } +} + +void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() { + if (m_model && m_model->project()) { + m_model->project()->dataBase()->updateDB(); } } diff --git a/sources/ui/bomexportdialog.h b/sources/ui/bomexportdialog.h index 6eaa1dbeb..f743fe7d3 100644 --- a/sources/ui/bomexportdialog.h +++ b/sources/ui/bomexportdialog.h @@ -54,13 +54,12 @@ class BOMExportDialog : public QDialog void on_m_save_current_conf_pb_clicked(); void on_m_load_pb_clicked(); - private: + private: void setUpItems(); QString getBom(); QString headers() const; bool createDataBase(); void populateDataBase(); - void prepareQuery(QStringList keys); QHash elementInfoToString(Element *elmt) const; QString queryStr() const; void updateQueryLine(); diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index bc3ba80f3..a97e5257f 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -1,5 +1,5 @@ /* - Copyright 2006-2019 The QElectroTech Team + Copyright 2006-2020 The QElectroTech Team This file is part of QElectroTech. QElectroTech is free software: you can redistribute it and/or modify