Add new summary table (WIP)

This commit is contained in:
Claveau Joshua
2020-06-18 18:52:29 +02:00
parent 80b5029cd1
commit ec5f537da4
21 changed files with 1079 additions and 524 deletions

View File

@@ -176,12 +176,16 @@ bool projectDataBase::createDataBase(const QString &connection_name, const QStri
}
createElementNomenclatureView();
createSummaryView();
}
updateDB();
return true;
}
/**
* @brief projectDataBase::createElementNomenclatureView
*/
void projectDataBase::createElementNomenclatureView()
{
QString create_view ("CREATE VIEW element_nomenclature_view AS SELECT "
@@ -216,6 +220,29 @@ void projectDataBase::createElementNomenclatureView()
}
}
/**
* @brief projectDataBase::createSummaryView
*/
void projectDataBase::createSummaryView()
{
QString create_view ("CREATE VIEW project_summary_view AS SELECT "
"di.title AS title,"
"di.author AS author,"
"di.folio AS folio,"
"di.plant AS plant,"
"di.locmach AS locmach,"
"di.indexrev AS indexrev,"
"di.date AS date,"
"d.pos AS pos"
" FROM diagram_info di, diagram d"
" WHERE di.diagram_uuid = d.uuid");
QSqlQuery query(m_data_base);
if (!query.exec(create_view)) {
qDebug() << query.lastError();
}
}
void projectDataBase::populateDiagramTable()
{
QSqlQuery query_(m_data_base);

View File

@@ -55,6 +55,7 @@ class projectDataBase : public QObject
private:
bool createDataBase(const QString &connection_name= QString(), const QString &name = QString());
void createElementNomenclatureView();
void createSummaryView();
void populateDiagramTable();
void populateElementTable();
void populateElementInfoTable();

View File

@@ -44,6 +44,8 @@ class ElementQueryWidget : public QWidget
QString queryStr() const;
QStringList header() const;
static QString modelIdentifier() {return "nomenclature";}
private slots:
void on_m_up_pb_clicked();
void on_m_add_pb_clicked();

View File

@@ -0,0 +1,217 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#include "summaryquerywidget.h"
#include "ui_summaryquerywidget.h"
#include "qetapp.h"
#include <QListWidgetItem>
/**
* @brief SummaryQueryWidget::SummaryQueryWidget
* @param parent
*/
SummaryQueryWidget::SummaryQueryWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SummaryQueryWidget)
{
ui->setupUi(this);
ui->m_config_gb->setDisabled(true);
setUpItems();
fillSavedQuery();
}
/**
* @brief SummaryQueryWidget::~SummaryQueryWidget
*/
SummaryQueryWidget::~SummaryQueryWidget()
{
delete ui;
}
/**
* @brief SummaryQueryWidget::queryStr
* @return
*/
QString SummaryQueryWidget::queryStr() const
{
//User define is own query
if (ui->m_edit_sql_query_cb->isChecked()) {
return ui->m_user_query_le->text();
}
//Made a string list with the colomns (keys) choosen by the user
QStringList keys = selectedKeys();
QString select ="SELECT ";
QString column;
bool first = true;
for (auto key: keys) {
if (first) {
first = false;
} else {
column += ", ";
}
column += key;
}
QString from = " FROM project_summary_view";
QString q(select + column + from);
return q;
}
/**
* @brief SummaryQueryWidget::setUpItems
*/
void SummaryQueryWidget::setUpItems()
{
for (auto key : QETApp::diagramInfoKeys())
{
if (key == "filename" || key == "display_folio") {
continue;
}
auto item = new QListWidgetItem(QETApp::diagramTranslatedInfoKey(key), ui->m_available_list);
item->setData(Qt::UserRole, key);
m_items_list << item;
}
auto item = new QListWidgetItem(tr("Position"), ui->m_available_list);
item->setData(Qt::UserRole, "pos");
m_items_list << item;
}
void SummaryQueryWidget::fillSavedQuery()
{
}
/**
* @brief SummaryQueryWidget::updateQueryLine
*/
void SummaryQueryWidget::updateQueryLine() {
ui->m_user_query_le->setText(queryStr());
}
/**
* @brief SummaryQueryWidget::selectedKeys
* @return
*/
QStringList SummaryQueryWidget::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 SummaryQueryWidget::on_m_available_list_itemDoubleClicked(QListWidgetItem *item)
{
Q_UNUSED(item)
on_m_add_pb_clicked();
}
/**
* @brief SummaryQueryWidget::on_m_choosen_list_itemDoubleClicked
* @param item
*/
void SummaryQueryWidget::on_m_choosen_list_itemDoubleClicked(QListWidgetItem *item)
{
Q_UNUSED(item)
on_m_remove_pb_clicked();
}
/**
* @brief SummaryQueryWidget::on_m_up_pb_clicked
*/
void SummaryQueryWidget::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 SummaryQueryWidget::on_m_add_pb_clicked
*/
void SummaryQueryWidget::on_m_add_pb_clicked()
{
if (auto *item = ui->m_available_list->takeItem(ui->m_available_list->currentRow())) {
ui->m_choosen_list->addItem(item);
}
updateQueryLine();
}
/**
* @brief SummaryQueryWidget::on_m_remove_pb_clicked
*/
void SummaryQueryWidget::on_m_remove_pb_clicked()
{
if (auto *item = ui->m_choosen_list->takeItem(ui->m_choosen_list->currentRow())) {
ui->m_available_list->addItem(item);
}
updateQueryLine();
}
/**
* @brief SummaryQueryWidget::on_m_down_pb_clicked
*/
void SummaryQueryWidget::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();
}
void SummaryQueryWidget::on_m_edit_sql_query_cb_clicked()
{
ui->m_user_query_le->setEnabled(ui->m_edit_sql_query_cb->isChecked());
ui->m_info_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked());
if (ui->m_edit_sql_query_cb->isChecked() && !m_custom_query.isEmpty())
{
ui->m_user_query_le->setText(m_custom_query);
}
else if (!ui->m_edit_sql_query_cb->isChecked())
{
m_custom_query = ui->m_user_query_le->text();
updateQueryLine();
}
}

View File

@@ -0,0 +1,61 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef SUMMARYQUERYWIDGET_H
#define SUMMARYQUERYWIDGET_H
#include <QWidget>
class QListWidgetItem;
namespace Ui {
class SummaryQueryWidget;
}
class SummaryQueryWidget : public QWidget
{
Q_OBJECT
public:
explicit SummaryQueryWidget(QWidget *parent = nullptr);
~SummaryQueryWidget();
static QString modelIdentifier() {return "summary";}
QString queryStr() const;
private:
void setUpItems();
void fillSavedQuery();
void updateQueryLine();
QStringList selectedKeys() const;
private slots:
void on_m_available_list_itemDoubleClicked(QListWidgetItem *item);
void on_m_choosen_list_itemDoubleClicked(QListWidgetItem *item);
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();
private:
Ui::SummaryQueryWidget *ui;
QList <QListWidgetItem *> m_items_list;
QString m_custom_query;
};
#endif // SUMMARYQUERYWIDGET_H

View File

@@ -0,0 +1,176 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SummaryQueryWidget</class>
<widget class="QWidget" name="SummaryQueryWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>347</width>
<height>277</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="m_info_widget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="2">
<widget class="QListWidget" name="m_choosen_list"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Informations disponibles</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QListWidget" name="m_available_list"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Information à afficher</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_up_pb">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/go-up.png</normaloff>:/ico/16x16/go-up.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_add_pb">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_remove_pb">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/list-remove.png</normaloff>:/ico/16x16/list-remove.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_down_pb">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qelectrotech.qrc">
<normaloff>:/ico/16x16/go-down.png</normaloff>:/ico/16x16/go-down.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="ConfigSaveLoaderWidget" name="m_config_gb">
<property name="title">
<string>Configuration</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="m_edit_sql_query_cb">
<property name="text">
<string>Requête SQL :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_user_query_le">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ConfigSaveLoaderWidget</class>
<extends>QGroupBox</extends>
<header>configsaveloaderwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../qelectrotech.qrc"/>
</resources>
<connections/>
</ui>