mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
Add view 'element_nomenclature_view' to projectDataBase
Add a view for the nomenclature to reduce the size of the query and make it more understandable
This commit is contained in:
@@ -90,7 +90,7 @@ QVector<QStringList> projectDataBase::elementsInfoFromQuery(const QString &query
|
|||||||
* @return the header according to @query.
|
* @return the header according to @query.
|
||||||
* Header can be false, notably when user create is own query.
|
* Header can be false, notably when user create is own query.
|
||||||
*/
|
*/
|
||||||
QStringList projectDataBase::headersFromElementsInfoQuery(const QString &query)
|
QStringList projectDataBase::headersFromElementNomenclatureViewQuery(const QString &query)
|
||||||
{
|
{
|
||||||
QStringList header_string;
|
QStringList header_string;
|
||||||
if (!query.startsWith("SELECT ") && !query.contains("FROM")) {
|
if (!query.startsWith("SELECT ") && !query.contains("FROM")) {
|
||||||
@@ -107,34 +107,27 @@ QStringList projectDataBase::headersFromElementsInfoQuery(const QString &query)
|
|||||||
return header_string;
|
return header_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0 ; i<list.size() ; i++)
|
for (int i=0 ; i<list.size() ; ++i)
|
||||||
{
|
{
|
||||||
auto str = list.at(i);
|
auto str = list.at(i);
|
||||||
|
|
||||||
if(str == "e.pos") { //Query in element table wich have only pose use in this case
|
if (str == "position") {
|
||||||
header_string.append(tr("Position"));
|
header_string.append(tr("Position"));
|
||||||
}
|
} else if (str == "diagram_position") {
|
||||||
else if (str.contains("ei.")) //Query in element_info table
|
|
||||||
{
|
|
||||||
str.remove(0,3);
|
|
||||||
header_string.append(QETApp::elementTranslatedInfoKey(str));
|
|
||||||
}
|
|
||||||
else if (str == "d.pos") { //query in diagram table wich have only pos use in this case
|
|
||||||
header_string.append(tr("Position du folio"));
|
header_string.append(tr("Position du folio"));
|
||||||
}
|
|
||||||
else if (str.contains("di.")) //query in diagram_info table
|
|
||||||
{
|
|
||||||
str.remove(0,3);
|
|
||||||
header_string.append(QETApp::diagramTranslatedInfoKey(str));
|
|
||||||
}
|
|
||||||
else //Default case
|
|
||||||
{
|
|
||||||
if (str == "pos") {
|
|
||||||
header_string.append(tr("Position"));
|
|
||||||
} else if (QETApp::elementInfoKeys().contains(str)) {
|
|
||||||
header_string.append(QETApp::elementTranslatedInfoKey(str));
|
|
||||||
} else {
|
} else {
|
||||||
header_string.append(QETApp::diagramTranslatedInfoKey(str));
|
auto elmt_str = QETApp::elementTranslatedInfoKey(str);
|
||||||
|
if (!elmt_str.isEmpty()) {
|
||||||
|
header_string.append(elmt_str);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto diagram_str = QETApp::diagramTranslatedInfoKey(str);
|
||||||
|
if (!diagram_str.isEmpty()) {
|
||||||
|
header_string.append(diagram_str);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header_string.append(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,12 +248,48 @@ bool projectDataBase::createDataBase(const QString &connection_name, const QStri
|
|||||||
if (!query_.exec(element_info_table)) {
|
if (!query_.exec(element_info_table)) {
|
||||||
qDebug() << " element_info_table query : " << query_.lastError();
|
qDebug() << " element_info_table query : " << query_.lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createElementNomenclatureView();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDB();
|
updateDB();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void projectDataBase::createElementNomenclatureView()
|
||||||
|
{
|
||||||
|
QString create_view ("CREATE VIEW element_nomenclature_view AS SELECT "
|
||||||
|
"ei.label AS label,"
|
||||||
|
"ei.plant AS plant,"
|
||||||
|
"ei.location AS location,"
|
||||||
|
"ei.comment AS comment,"
|
||||||
|
"ei.function AS function,"
|
||||||
|
"ei.tension_protocol AS tension_protocol,"
|
||||||
|
"ei.auxiliary1 AS auxiliary1,"
|
||||||
|
"ei.auxiliary2 AS auxiliary2,"
|
||||||
|
"ei.description AS description,"
|
||||||
|
"ei.designation AS designation,"
|
||||||
|
"ei.manufacturer AS manufacturer,"
|
||||||
|
"ei.manufacturer_reference AS manufacturer_reference,"
|
||||||
|
"ei.machine_manufacturer_reference AS machine_manufacturer_reference,"
|
||||||
|
"ei.supplier AS supplier,"
|
||||||
|
"ei.quantity AS quantity,"
|
||||||
|
"ei.unity AS unity,"
|
||||||
|
"d.pos AS diagram_position,"
|
||||||
|
"e.type AS element_type,"
|
||||||
|
"e.sub_type AS element_sub_type,"
|
||||||
|
"di.title AS title,"
|
||||||
|
"di.folio AS folio,"
|
||||||
|
"e.pos AS position "
|
||||||
|
" FROM element_info ei, diagram_info di, element e, diagram d"
|
||||||
|
" WHERE ei.element_uuid = e.uuid AND e.diagram_uuid = d.uuid AND di.diagram_uuid = d.uuid");
|
||||||
|
|
||||||
|
QSqlQuery query(m_data_base);
|
||||||
|
if (!query.exec(create_view)) {
|
||||||
|
qDebug() << query.lastError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void projectDataBase::populateDiagramTable()
|
void projectDataBase::populateDiagramTable()
|
||||||
{
|
{
|
||||||
QSqlQuery query_(m_data_base);
|
QSqlQuery query_(m_data_base);
|
||||||
|
|||||||
@@ -49,13 +49,14 @@ class projectDataBase : public QObject
|
|||||||
void updateDB();
|
void updateDB();
|
||||||
QETProject *project() const;
|
QETProject *project() const;
|
||||||
|
|
||||||
static QStringList headersFromElementsInfoQuery(const QString &query);
|
static QStringList headersFromElementNomenclatureViewQuery(const QString &query);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataBaseUpdated();
|
void dataBaseUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool createDataBase(const QString &connection_name= QString(), const QString &name = QString());
|
bool createDataBase(const QString &connection_name= QString(), const QString &name = QString());
|
||||||
|
void createElementNomenclatureView();
|
||||||
void populateDiagramTable();
|
void populateDiagramTable();
|
||||||
void populateElementTable();
|
void populateElementTable();
|
||||||
void populateElementInfoTable();
|
void populateElementInfoTable();
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ ElementQueryWidget::ElementQueryWidget(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_export_info.insert("e.pos", tr("Position"));
|
m_export_info.insert("position", tr("Position"));
|
||||||
m_export_info.insert("di.title", tr("Titre du folio"));
|
m_export_info.insert("title", tr("Titre du folio"));
|
||||||
m_export_info.insert("d.pos", tr("Position du folio"));
|
m_export_info.insert("diagram_position", tr("Position du folio"));
|
||||||
m_export_info.insert("di.folio", tr("Numéro du folio"));
|
m_export_info.insert("folio", tr("Numéro du folio"));
|
||||||
|
|
||||||
m_button_group.setExclusive(false);
|
m_button_group.setExclusive(false);
|
||||||
m_button_group.addButton(ui->m_all_cb, 0);
|
m_button_group.addButton(ui->m_all_cb, 0);
|
||||||
@@ -149,43 +149,39 @@ QString ElementQueryWidget::queryStr() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString from = " FROM element_info ei, element e, diagram d, diagram_info di";
|
QString from = " FROM element_nomenclature_view";
|
||||||
QString where = " WHERE ei.element_uuid = e.uuid"
|
|
||||||
" AND di.diagram_uuid = d.uuid"
|
|
||||||
" AND e.diagram_uuid = d.uuid";
|
|
||||||
|
|
||||||
|
QString where;
|
||||||
if (ui->m_all_cb->checkState() == Qt::PartiallyChecked)
|
if (ui->m_all_cb->checkState() == Qt::PartiallyChecked)
|
||||||
{
|
{
|
||||||
|
where = " WHERE ";
|
||||||
bool b = false;
|
bool b = false;
|
||||||
where += " AND (";
|
|
||||||
if (ui->m_terminal_cb->isChecked()) {
|
if (ui->m_terminal_cb->isChecked()) {
|
||||||
if (b) where +=" OR";
|
if (b) where +=" OR";
|
||||||
where += " e.type = 'Terminale'";
|
where += " element_type = 'Terminale'";
|
||||||
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 += " e.type = 'Simple'";
|
where += " element_type = '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 += " e.sub_type = 'commutator'";
|
where += " element_sub_type = '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 += " e.sub_type = 'coil'";
|
where += " element_sub_type = '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 += " e.sub_type = 'protection'";
|
where += " element_sub_type = 'protection'";
|
||||||
}
|
}
|
||||||
where += ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString q(select + column + from + where + filter_ + order_by);
|
QString q(select + column + from + where + filter_ + order_by);
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
@@ -233,8 +229,11 @@ void ElementQueryWidget::setUpItems()
|
|||||||
{
|
{
|
||||||
for(QString key : QETApp::elementInfoKeys())
|
for(QString key : QETApp::elementInfoKeys())
|
||||||
{
|
{
|
||||||
|
if (key == "formula")
|
||||||
|
continue;
|
||||||
|
|
||||||
auto item = new QListWidgetItem(QETApp::elementTranslatedInfoKey(key), ui->m_var_list);
|
auto item = new QListWidgetItem(QETApp::elementTranslatedInfoKey(key), ui->m_var_list);
|
||||||
item->setData(Qt::UserRole, "ei." + key);
|
item->setData(Qt::UserRole, key);
|
||||||
m_items_list << item;
|
m_items_list << item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ QETProject *NomenclatureModel::project() const {
|
|||||||
*/
|
*/
|
||||||
void NomenclatureModel::autoHeaders()
|
void NomenclatureModel::autoHeaders()
|
||||||
{
|
{
|
||||||
auto headers = projectDataBase::headersFromElementsInfoQuery(m_query);
|
auto headers = projectDataBase::headersFromElementNomenclatureViewQuery(m_query);
|
||||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
for (auto i=0 ; i<headers.size() ; ++i) {
|
||||||
this->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
this->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user