Nomenclature now use properly the element type 'thumbnail'

Use function provided by ElementData to check element type and
master type instead of use plain text (code is more strong)
This commit is contained in:
joshua
2022-06-01 22:29:12 +02:00
parent 3dd0986c4f
commit 2e70d2e599
7 changed files with 79 additions and 39 deletions

View File

@@ -411,16 +411,17 @@ void projectDataBase::populateElementTable()
for (auto diagram : m_project->diagrams()) for (auto diagram : m_project->diagrams())
{ {
ElementProvider ep(diagram); const ElementProvider ep(diagram);
QList<Element *> elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master | Element::Thumbnail); const auto elmt_vector = ep.find(ElementData::Simple | ElementData::Terminale | ElementData::Master | ElementData::Thumbnail);
//Insert all value into the database //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(":uuid", elmt->uuid().toString());
m_insert_elements_query.bindValue(":diagram_uuid", diagram->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(":pos", diagram->convertPosition(elmt->scenePos()).toString());
m_insert_elements_query.bindValue(":type", elmt->linkTypeToString()); m_insert_elements_query.bindValue(":type", elmt_data.typeToString());
m_insert_elements_query.bindValue(":sub_type", elmt->kindInformations()["type"].toString()); m_insert_elements_query.bindValue(":sub_type", elmt_data.masterTypeToString());
if (!m_insert_elements_query.exec()) { if (!m_insert_elements_query.exec()) {
qDebug() << "projectDataBase::populateElementTable insert error : " << m_insert_elements_query.lastError(); qDebug() << "projectDataBase::populateElementTable insert error : " << m_insert_elements_query.lastError();
} }
@@ -435,22 +436,22 @@ void projectDataBase::populateElementTable()
void projectDataBase::populateElementInfoTable() void projectDataBase::populateElementInfoTable()
{ {
QSqlQuery query(m_data_base); 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); const ElementProvider ep(diagram);
QList<Element *> elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master | Element::Thumbnail); const auto elmt_vector = ep.find(ElementData::Simple | ElementData::Terminale | ElementData::Master | ElementData::Thumbnail);
//Insert all value into the database //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()); m_insert_element_info_query.bindValue(QStringLiteral(":uuid"), elmt->uuid().toString());
auto hash = elementInfoToString(elmt); const auto hash = elementInfoToString(elmt);
for (auto key : hash.keys()) for (const auto &key : hash.keys())
{ {
QString value = hash.value(key); QString value = hash.value(key);
QString bind = key.prepend(":"); QString bind = QStringLiteral(":") + key;
m_insert_element_info_query.bindValue(bind, value); m_insert_element_info_query.bindValue(bind, value);
} }

View File

@@ -17,6 +17,7 @@
*/ */
#include "elementquerywidget.h" #include "elementquerywidget.h"
#include "../../properties/elementdata.h"
#include "../../qetapp.h" #include "../../qetapp.h"
#include "../../qetinformation.h" #include "../../qetinformation.h"
#include "ui_elementquerywidget.h" #include "ui_elementquerywidget.h"
@@ -166,28 +167,27 @@ void ElementQueryWidget::setQuery(const QString &query)
where.remove(str_type); where.remove(str_type);
int c=0; 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()) { if (ui->m_simple_cb->isChecked()) {
++c; ++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()) { if (ui->m_terminal_cb->isChecked()) {
++c; ++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()) { if (ui->m_coil_cb->isChecked()) {
++c; ++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()) { if (ui->m_button_cb->isChecked()) {
++c; ++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) { if (ui->m_protection_cb) {
++c; ++c;
} }
ui->m_thumbnail_cb->setChecked (str_type.contains(ElementData::typeToString(ElementData::Thumbnail)) ? true : false);
ui->m_thumbnail_cb->setChecked (str_type.contains("Thumbnail") ? true : false);
if (ui->m_thumbnail_cb->isChecked()) { if (ui->m_thumbnail_cb->isChecked()) {
++c; ++c;
} }
@@ -340,32 +340,32 @@ QString ElementQueryWidget::queryStr() const
bool b = false; bool b = false;
if (ui->m_terminal_cb->isChecked()) { if (ui->m_terminal_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_type = 'Terminale'"; where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Terminale) += "'";
b = true; b = true;
} }
if (ui->m_thumbnail_cb->isChecked()) { if (ui->m_thumbnail_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_type = 'Thumbnail'"; where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Thumbnail) += "'";
b = true; b = true;
} }
if (ui->m_simple_cb->isChecked()) { if (ui->m_simple_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_type = 'Simple'"; where += QStringLiteral(" element_type = '") += ElementData::typeToString(ElementData::Simple) += "'";
b = true; b = true;
} }
if (ui->m_button_cb->isChecked()) { if (ui->m_button_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_sub_type = 'commutator'"; where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Commutator) += "'";
b = true; b = true;
} }
if (ui->m_coil_cb->isChecked()) { if (ui->m_coil_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_sub_type = 'coil'"; where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Coil) += "'";
b = true; b = true;
} }
if (ui->m_protection_cb->isChecked()) { if (ui->m_protection_cb->isChecked()) {
if (b) where +=" OR"; if (b) where +=" OR";
where += " element_sub_type = 'protection'"; where += QStringLiteral(" element_sub_type = '") += ElementData::masterTypeToString(ElementData::Protection) += "'";
} }
where.append(")"); where.append(")");

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>341</width> <width>738</width>
<height>557</height> <height>534</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -272,16 +272,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QCheckBox" name="m_coil_cb">
<property name="text">
<string>Contacteurs et relais</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="m_button_cb"> <widget class="QCheckBox" name="m_button_cb">
<property name="text"> <property name="text">
@@ -312,6 +302,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="m_coil_cb">
<property name="text">
<string>Contacteurs et relais</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@@ -96,6 +96,7 @@ QList <Element *> ElementProvider::fromUuids(QList<QUuid> uuid_list) const
@param filter @param filter
the filter for search element the filter for search element
(You can find all filter with the define in Element.h) (You can find all filter with the define in Element.h)
@obsolete use instead QVector<_Tp1> ElementProvider::find(ElementData::Type elmt_type) const
*/ */
QList <Element *> ElementProvider::find(const int filter) const QList <Element *> ElementProvider::find(const int filter) const
{ {
@@ -114,6 +115,29 @@ QList <Element *> ElementProvider::find(const int filter) const
return (elmt_); return (elmt_);
} }
/**
* @brief ElementProvider::find
* Search and return the element with the type given in parameter
* @param elmt_type
* @return
*/
QVector<QPointer<Element>> ElementProvider::find(ElementData::Types elmt_type) const
{
QVector<QPointer<Element>> 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<Element>(elmt_);
}
}
}
return returned_vector;
}
/** /**
@brief ElementProvider::table @brief ElementProvider::table
@param table @param table

View File

@@ -22,6 +22,8 @@
#include <QList> #include <QList>
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include "properties/elementdata.h"
class QETProject; class QETProject;
class Diagram; class Diagram;
class Element; class Element;
@@ -42,6 +44,7 @@ class ElementProvider
QList <Element *> freeElement(const int filter) const; QList <Element *> freeElement(const int filter) const;
QList <Element *> fromUuids(QList <QUuid>) const; QList <Element *> fromUuids(QList <QUuid>) const;
QList <Element *> find(const int filter) const; QList <Element *> find(const int filter) const;
QVector<QPointer<Element> > find(ElementData::Types elmt_type) const;
QVector <QetGraphicsTableItem *> table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr); QVector <QetGraphicsTableItem *> table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr);
QetGraphicsTableItem *tableFromUuid(const QUuid &uuid); QetGraphicsTableItem *tableFromUuid(const QUuid &uuid);
QVector<TerminalElement *> freeTerminal() const; QVector<TerminalElement *> freeTerminal() const;

View File

@@ -345,6 +345,13 @@ ElementData::Type ElementData::typeFromString(const QString &string)
return ElementData::Simple; 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) QString ElementData::masterTypeToString(ElementData::MasterType type)
{ {
switch (type) { switch (type) {

View File

@@ -43,6 +43,7 @@ class ElementData : public PropertiesInterface
Terminale = 32, Terminale = 32,
Thumbnail = 64}; Thumbnail = 64};
Q_ENUM(Type) Q_ENUM(Type)
Q_DECLARE_FLAGS(Types, Type)
enum MasterType { enum MasterType {
Coil, Coil,
@@ -109,6 +110,7 @@ class ElementData : public PropertiesInterface
static QString typeToString(ElementData::Type type); static QString typeToString(ElementData::Type type);
static ElementData::Type typeFromString(const QString &string); static ElementData::Type typeFromString(const QString &string);
QString masterTypeToString() const;
static QString masterTypeToString(ElementData::MasterType type); static QString masterTypeToString(ElementData::MasterType type);
static ElementData::MasterType masterTypeFromString(const QString &string); static ElementData::MasterType masterTypeFromString(const QString &string);
@@ -157,4 +159,7 @@ class ElementData : public PropertiesInterface
private: private:
void kindInfoFromXml(const QDomElement &xml_element); void kindInfoFromXml(const QDomElement &xml_element);
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementData::Types)
#endif // ELEMENTDATA_H #endif // ELEMENTDATA_H