diff --git a/sources/dataBase/projectdatabase.cpp b/sources/dataBase/projectdatabase.cpp index 360054e33..e23963d96 100644 --- a/sources/dataBase/projectdatabase.cpp +++ b/sources/dataBase/projectdatabase.cpp @@ -411,16 +411,17 @@ void projectDataBase::populateElementTable() for (auto diagram : m_project->diagrams()) { - ElementProvider ep(diagram); - QList elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master | Element::Thumbnail); + const ElementProvider ep(diagram); + const auto elmt_vector = ep.find(ElementData::Simple | ElementData::Terminale | ElementData::Master | ElementData::Thumbnail); //Insert all value into the database - for (auto elmt : elements_list) + for (const auto &elmt : elmt_vector) { + const auto elmt_data = elmt->elementData(); m_insert_elements_query.bindValue(":uuid", elmt->uuid().toString()); m_insert_elements_query.bindValue(":diagram_uuid", diagram->uuid().toString()); m_insert_elements_query.bindValue(":pos", diagram->convertPosition(elmt->scenePos()).toString()); - m_insert_elements_query.bindValue(":type", elmt->linkTypeToString()); - m_insert_elements_query.bindValue(":sub_type", elmt->kindInformations()["type"].toString()); + m_insert_elements_query.bindValue(":type", elmt_data.typeToString()); + m_insert_elements_query.bindValue(":sub_type", elmt_data.masterTypeToString()); if (!m_insert_elements_query.exec()) { qDebug() << "projectDataBase::populateElementTable insert error : " << m_insert_elements_query.lastError(); } @@ -435,22 +436,22 @@ void projectDataBase::populateElementTable() void projectDataBase::populateElementInfoTable() { QSqlQuery query(m_data_base); - query.exec("DELETE FROM element_info"); + query.exec(QStringLiteral("DELETE FROM element_info")); - for (auto *diagram : m_project->diagrams()) + for (const auto &diagram : m_project->diagrams()) { - ElementProvider ep(diagram); - QList elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master | Element::Thumbnail); + const ElementProvider ep(diagram); + const auto elmt_vector = ep.find(ElementData::Simple | ElementData::Terminale | ElementData::Master | ElementData::Thumbnail); //Insert all value into the database - for (auto elmt : elements_list) + for (const auto &elmt : elmt_vector) { - m_insert_element_info_query.bindValue(":uuid", elmt->uuid().toString()); - auto hash = elementInfoToString(elmt); - for (auto key : hash.keys()) + m_insert_element_info_query.bindValue(QStringLiteral(":uuid"), elmt->uuid().toString()); + const auto hash = elementInfoToString(elmt); + for (const auto &key : hash.keys()) { QString value = hash.value(key); - QString bind = key.prepend(":"); + QString bind = QStringLiteral(":") + key; m_insert_element_info_query.bindValue(bind, value); } diff --git a/sources/dataBase/ui/elementquerywidget.cpp b/sources/dataBase/ui/elementquerywidget.cpp index 2cb425eb1..1e3b4423d 100644 --- a/sources/dataBase/ui/elementquerywidget.cpp +++ b/sources/dataBase/ui/elementquerywidget.cpp @@ -17,6 +17,7 @@ */ #include "elementquerywidget.h" +#include "../../properties/elementdata.h" #include "../../qetapp.h" #include "../../qetinformation.h" #include "ui_elementquerywidget.h" @@ -166,28 +167,27 @@ void ElementQueryWidget::setQuery(const QString &query) where.remove(str_type); int c=0; - ui->m_simple_cb->setChecked (str_type.contains("Simple") ? true : false); + ui->m_simple_cb->setChecked (str_type.contains(ElementData::typeToString(ElementData::Simple)) ? true : false); if (ui->m_simple_cb->isChecked()) { ++c; } - ui->m_terminal_cb->setChecked (str_type.contains("Terminale") ? true : false); + ui->m_terminal_cb->setChecked (str_type.contains(ElementData::typeToString(ElementData::Terminale)) ? true : false); if (ui->m_terminal_cb->isChecked()) { ++c; } - ui->m_coil_cb->setChecked (str_type.contains("coil") ? true : false); + ui->m_coil_cb->setChecked (str_type.contains(ElementData::masterTypeToString(ElementData::Coil)) ? true : false); if (ui->m_coil_cb->isChecked()) { ++c; } - ui->m_button_cb->setChecked (str_type.contains("commutator") ? true : false); + ui->m_button_cb->setChecked (str_type.contains(ElementData::masterTypeToString(ElementData::Commutator)) ? true : false); if (ui->m_button_cb->isChecked()) { ++c; } - ui->m_protection_cb->setChecked(str_type.contains("protection") ? true : false); + ui->m_protection_cb->setChecked(str_type.contains(ElementData::masterTypeToString(ElementData::Protection)) ? true : false); if (ui->m_protection_cb) { ++c; } - - ui->m_thumbnail_cb->setChecked (str_type.contains("Thumbnail") ? true : false); + ui->m_thumbnail_cb->setChecked (str_type.contains(ElementData::typeToString(ElementData::Thumbnail)) ? true : false); if (ui->m_thumbnail_cb->isChecked()) { ++c; } @@ -340,32 +340,32 @@ QString ElementQueryWidget::queryStr() const bool b = false; if (ui->m_terminal_cb->isChecked()) { if (b) where +=" OR"; - where += " element_type = 'Terminale'"; + where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Terminale) += "'"; b = true; } if (ui->m_thumbnail_cb->isChecked()) { if (b) where +=" OR"; - where += " element_type = 'Thumbnail'"; + where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Thumbnail) += "'"; b = true; } if (ui->m_simple_cb->isChecked()) { if (b) where +=" OR"; - where += " element_type = 'Simple'"; + where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Simple) += "'"; b = true; } if (ui->m_button_cb->isChecked()) { if (b) where +=" OR"; - where += " element_sub_type = 'commutator'"; + where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Commutator) += "'"; b = true; } if (ui->m_coil_cb->isChecked()) { if (b) where +=" OR"; - where += " element_sub_type = 'coil'"; + where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Coil) += "'"; b = true; } if (ui->m_protection_cb->isChecked()) { if (b) where +=" OR"; - where += " element_sub_type = 'protection'"; + where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Protection) += "'"; } where.append(")"); diff --git a/sources/dataBase/ui/elementquerywidget.ui b/sources/dataBase/ui/elementquerywidget.ui index f16469e24..d1b04f227 100644 --- a/sources/dataBase/ui/elementquerywidget.ui +++ b/sources/dataBase/ui/elementquerywidget.ui @@ -6,8 +6,8 @@ 0 0 - 341 - 557 + 738 + 534 @@ -272,16 +272,6 @@ - - - - Contacteurs et relais - - - true - - - @@ -312,6 +302,16 @@ + + + + Contacteurs et relais + + + true + + + diff --git a/sources/elementprovider.cpp b/sources/elementprovider.cpp index d530f32ae..e456b0beb 100644 --- a/sources/elementprovider.cpp +++ b/sources/elementprovider.cpp @@ -96,6 +96,7 @@ QList ElementProvider::fromUuids(QList uuid_list) const @param filter the filter for search element (You can find all filter with the define in Element.h) + @obsolete use instead QVector<_Tp1> ElementProvider::find(ElementData::Type elmt_type) const */ QList ElementProvider::find(const int filter) const { @@ -114,6 +115,29 @@ QList ElementProvider::find(const int filter) const return (elmt_); } +/** + * @brief ElementProvider::find + * Search and return the element with the type given in parameter + * @param elmt_type + * @return + */ +QVector> ElementProvider::find(ElementData::Types elmt_type) const +{ + QVector> returned_vector; + for (const auto &diagram_ : qAsConst(m_diagram_list)) + { + const auto elmt_list = diagram_->elements(); + for (const auto &elmt_ : elmt_list) + { + if (elmt_type & elmt_->elementData().m_type) { + returned_vector << QPointer(elmt_); + } + } + } + + return returned_vector; +} + /** @brief ElementProvider::table @param table diff --git a/sources/elementprovider.h b/sources/elementprovider.h index 9fbbabd4a..7dbcdad88 100644 --- a/sources/elementprovider.h +++ b/sources/elementprovider.h @@ -22,6 +22,8 @@ #include #include +#include "properties/elementdata.h" + class QETProject; class Diagram; class Element; @@ -42,6 +44,7 @@ class ElementProvider QList freeElement(const int filter) const; QList fromUuids(QList ) const; QList find(const int filter) const; + QVector > find(ElementData::Types elmt_type) const; QVector table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr); QetGraphicsTableItem *tableFromUuid(const QUuid &uuid); QVector freeTerminal() const; diff --git a/sources/properties/elementdata.cpp b/sources/properties/elementdata.cpp index 762bfb877..bbcaf045e 100644 --- a/sources/properties/elementdata.cpp +++ b/sources/properties/elementdata.cpp @@ -345,6 +345,13 @@ ElementData::Type ElementData::typeFromString(const QString &string) return ElementData::Simple; } +QString ElementData::masterTypeToString() const { + if (m_type == Master) + return masterTypeToString(m_master_type); + else + return QLatin1String(); +} + QString ElementData::masterTypeToString(ElementData::MasterType type) { switch (type) { diff --git a/sources/properties/elementdata.h b/sources/properties/elementdata.h index 54414b58f..9e57fbfab 100644 --- a/sources/properties/elementdata.h +++ b/sources/properties/elementdata.h @@ -43,6 +43,7 @@ class ElementData : public PropertiesInterface Terminale = 32, Thumbnail = 64}; Q_ENUM(Type) + Q_DECLARE_FLAGS(Types, Type) enum MasterType { Coil, @@ -109,6 +110,7 @@ class ElementData : public PropertiesInterface static QString typeToString(ElementData::Type type); static ElementData::Type typeFromString(const QString &string); + QString masterTypeToString() const; static QString masterTypeToString(ElementData::MasterType type); static ElementData::MasterType masterTypeFromString(const QString &string); @@ -157,4 +159,7 @@ class ElementData : public PropertiesInterface private: void kindInfoFromXml(const QDomElement &xml_element); }; + +Q_DECLARE_OPERATORS_FOR_FLAGS(ElementData::Types) + #endif // ELEMENTDATA_H