mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Add new summary table (WIP)
This commit is contained in:
parent
80b5029cd1
commit
ec5f537da4
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
217
sources/dataBase/ui/summaryquerywidget.cpp
Normal file
217
sources/dataBase/ui/summaryquerywidget.cpp
Normal 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();
|
||||
}
|
||||
}
|
61
sources/dataBase/ui/summaryquerywidget.h
Normal file
61
sources/dataBase/ui/summaryquerywidget.h
Normal 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
|
176
sources/dataBase/ui/summaryquerywidget.ui
Normal file
176
sources/dataBase/ui/summaryquerywidget.ui
Normal 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>
|
@ -32,8 +32,8 @@
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "qetgraphicstableitem.h"
|
||||
#include "graphicstablepropertieseditor.h"
|
||||
#include "nomenclaturemodel.h"
|
||||
#include "nomenclaturemodelpropertieswidget.h"
|
||||
#include "projectdbmodelpropertieswidget.h"
|
||||
#include "projectdbmodel.h"
|
||||
|
||||
/**
|
||||
* @brief PropertiesEditorFactory::propertiesEditor
|
||||
@ -48,15 +48,15 @@ PropertiesEditorWidget *PropertiesEditorFactory::propertiesEditor(QAbstractItemM
|
||||
Q_UNUSED(editor)
|
||||
Q_UNUSED(parent)
|
||||
|
||||
if (auto m = static_cast<NomenclatureModel *>(model))
|
||||
if (auto m = static_cast<ProjectDBModel *>(model))
|
||||
{
|
||||
if (editor &&
|
||||
editor->metaObject()->className() == NomenclatureModelPropertiesWidget::staticMetaObject.className())
|
||||
editor->metaObject()->className() == ProjectDBModelPropertiesWidget::staticMetaObject.className())
|
||||
{
|
||||
static_cast<NomenclatureModelPropertiesWidget *>(editor)->setModel(m);
|
||||
static_cast<ProjectDBModelPropertiesWidget *>(editor)->setModel(m);
|
||||
return editor;
|
||||
}
|
||||
return new NomenclatureModelPropertiesWidget(m, parent);
|
||||
return new ProjectDBModelPropertiesWidget(m, parent);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -17,12 +17,14 @@
|
||||
*/
|
||||
#include "qetgraphicstablefactory.h"
|
||||
#include "qetgraphicstableitem.h"
|
||||
#include "nomenclaturemodel.h"
|
||||
#include "projectdbmodel.h"
|
||||
#include "elementquerywidget.h"
|
||||
#include "diagram.h"
|
||||
#include "qetgraphicsheaderitem.h"
|
||||
#include "addtabledialog.h"
|
||||
#include "qetutils.h"
|
||||
#include "elementquerywidget.h"
|
||||
#include "summaryquerywidget.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
@ -33,48 +35,72 @@ QetGraphicsTableFactory::QetGraphicsTableFactory()
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableFactory::createAndAddNomenclature
|
||||
* Create a nomenclature table, open a dialog for ask to user the config of the table,
|
||||
* Open a dialog for ask user the config of the table ,create a nomenclature table
|
||||
* and add it to diagram @diagram;
|
||||
* @param diagram
|
||||
*/
|
||||
void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
||||
{
|
||||
QScopedPointer<AddTableDialog> d(new AddTableDialog(diagram->views().first()));
|
||||
QScopedPointer<AddTableDialog> d(new AddTableDialog(new ElementQueryWidget(), diagram->views().first()));
|
||||
d->setWindowTitle(QObject::tr("Ajouter une nomenclature"));
|
||||
|
||||
if (d->exec())
|
||||
if (d->exec()) {
|
||||
create(diagram, d.data());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetGraphicsTableFactory::createAndAddSummary
|
||||
* Open a dialog for ask user the config of the table ,create a summary table
|
||||
* and add it to diagram @diagram;
|
||||
* @param diagram
|
||||
*/
|
||||
void QetGraphicsTableFactory::createAndAddSummary(Diagram *diagram)
|
||||
{
|
||||
QScopedPointer<AddTableDialog> d(new AddTableDialog(new SummaryQueryWidget(), diagram->views().first()));
|
||||
d->setWindowTitle(QObject::tr("Ajouter un sommaire"));
|
||||
|
||||
if (d->exec()) {
|
||||
create(diagram, d.data());
|
||||
}
|
||||
}
|
||||
|
||||
void QetGraphicsTableFactory::create(Diagram *diagram, AddTableDialog *dialog)
|
||||
{
|
||||
auto table_ = newTable(diagram, dialog);
|
||||
if (dialog->adjustTableToFolio()) {
|
||||
QetGraphicsTableItem::adjustTableToFolio(table_);
|
||||
}
|
||||
|
||||
|
||||
//Add new table if needed and option checked
|
||||
dialog->addNewTableToNewDiagram();
|
||||
qDebug() << "model " << table_->model();
|
||||
table_->model()->rowCount();
|
||||
table_->displayNRow();
|
||||
if (dialog->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow())
|
||||
{
|
||||
auto table_ = newTable(diagram, d.data());
|
||||
if (d->adjustTableToFolio()) {
|
||||
QetGraphicsTableItem::adjustTableToFolio(table_);
|
||||
}
|
||||
auto already_displayed_rows = table_->displayNRow();
|
||||
auto project_ = diagram->project();
|
||||
auto actual_diagram = diagram;
|
||||
auto previous_table = table_;
|
||||
|
||||
|
||||
//Add new table if needed and option checked
|
||||
if (d->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow())
|
||||
table_->setTableName(dialog->tableName() + QString(" 1"));
|
||||
int table_number = 2;
|
||||
while (already_displayed_rows < table_->model()->rowCount())
|
||||
{
|
||||
auto already_displayed_rows = table_->displayNRow();
|
||||
auto project_ = diagram->project();
|
||||
auto actual_diagram = diagram;
|
||||
auto previous_table = table_;
|
||||
|
||||
table_->setTableName(d->tableName() + QString(" 1"));
|
||||
int table_number = 2;
|
||||
while (already_displayed_rows < table_->model()->rowCount())
|
||||
{
|
||||
//Add a new diagram after the current one
|
||||
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
||||
table_ = newTable(actual_diagram, d.data(), previous_table);
|
||||
table_->setTableName(d->tableName() + QString(" %1").arg(table_number));
|
||||
//Adjust table
|
||||
if (d->adjustTableToFolio()) {
|
||||
QetGraphicsTableItem::adjustTableToFolio(table_);
|
||||
}
|
||||
//Update some variable for the next loop
|
||||
already_displayed_rows += table_->displayNRow();
|
||||
previous_table = table_;
|
||||
++table_number;
|
||||
//Add a new diagram after the current one
|
||||
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
||||
table_ = newTable(actual_diagram, dialog, previous_table);
|
||||
table_->setTableName(dialog->tableName() + QString(" %1").arg(table_number));
|
||||
//Adjust table
|
||||
if (dialog->adjustTableToFolio()) {
|
||||
QetGraphicsTableItem::adjustTableToFolio(table_);
|
||||
}
|
||||
//Update some variable for the next loop
|
||||
already_displayed_rows += table_->displayNRow();
|
||||
previous_table = table_;
|
||||
++table_number;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,8 +121,20 @@ QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTab
|
||||
|
||||
if (!previous_table)
|
||||
{
|
||||
auto model = new NomenclatureModel(diagram->project(), diagram->project());
|
||||
model->query(dialog->queryStr());
|
||||
QString identifier_;
|
||||
QString query_;
|
||||
|
||||
if (auto query_widget = dynamic_cast<ElementQueryWidget *>(dialog->contentWidget())) {
|
||||
identifier_ = query_widget->modelIdentifier();
|
||||
query_ = query_widget->queryStr();
|
||||
} else if (auto query_widget = dynamic_cast<SummaryQueryWidget *>(dialog->contentWidget())) {
|
||||
identifier_ = query_widget->modelIdentifier();
|
||||
query_ = query_widget->queryStr();
|
||||
}
|
||||
|
||||
auto model = new ProjectDBModel(diagram->project(), diagram->project());
|
||||
model->setIdentifier(identifier_);
|
||||
model->setQuery(query_);
|
||||
model->setData(model->index(0,0), int(dialog->tableAlignment()), Qt::TextAlignmentRole);
|
||||
model->setData(model->index(0,0), dialog->tableFont(), Qt::FontRole);
|
||||
model->setData(model->index(0,0), QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
||||
|
@ -31,7 +31,9 @@ class QetGraphicsTableFactory
|
||||
QetGraphicsTableFactory();
|
||||
|
||||
static void createAndAddNomenclature(Diagram *diagram);
|
||||
static void createAndAddSummary(Diagram *diagram);
|
||||
private:
|
||||
static void create(Diagram *diagram, AddTableDialog *dialog);
|
||||
static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog, QetGraphicsTableItem *previous_table = nullptr);
|
||||
};
|
||||
|
||||
|
@ -24,17 +24,21 @@
|
||||
#include <QFontDialog>
|
||||
|
||||
/**
|
||||
* @brief AddTableDialog::AddNomenclatureDialog
|
||||
* @param parent
|
||||
* @brief AddTableDialog::AddTableDialog
|
||||
* @param content_widget : the widget to display in the "content" tab.
|
||||
* This dialog take ownership of @content_widget.
|
||||
* @param parent : parent widget.
|
||||
*/
|
||||
AddTableDialog::AddTableDialog(QWidget *parent) :
|
||||
AddTableDialog::AddTableDialog(QWidget *content_widget, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AddTableDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->m_header_font_pb->setText(m_header_font.family());
|
||||
ui->m_table_font_pb->setText(m_table_font.family());
|
||||
ui->m_tab->addTab(m_query_widget, tr("Contenu"));
|
||||
m_content_widget = content_widget;
|
||||
content_widget->setParent(this);
|
||||
ui->m_tab->addTab(content_widget, tr("Contenu"));
|
||||
fillSavedQuery();
|
||||
|
||||
connect(ui->m_config_gb, &ConfigSaveLoaderWidget::saveClicked, this, &AddTableDialog::saveConfig);
|
||||
@ -58,14 +62,6 @@ void AddTableDialog::setQueryWidget(QWidget *widget) {
|
||||
Q_UNUSED(widget)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AddTableDialog::queryStr
|
||||
* @return
|
||||
*/
|
||||
QString AddTableDialog::queryStr() {
|
||||
return m_query_widget->queryStr();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AddTableDialog::adjustTableToFolio
|
||||
* @return
|
||||
@ -154,6 +150,10 @@ QFont AddTableDialog::tableFont() const {
|
||||
return m_table_font;
|
||||
}
|
||||
|
||||
QWidget *AddTableDialog::contentWidget() const {
|
||||
return m_content_widget;
|
||||
}
|
||||
|
||||
void AddTableDialog::on_m_header_font_pb_clicked()
|
||||
{
|
||||
bool b;
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "elementquerywidget.h"
|
||||
#include "qetapp.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -40,11 +39,10 @@ class AddTableDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AddTableDialog(QWidget *parent = nullptr);
|
||||
explicit AddTableDialog(QWidget *content_widget, QWidget *parent = nullptr);
|
||||
~AddTableDialog();
|
||||
|
||||
void setQueryWidget(QWidget *widget);
|
||||
QString queryStr();
|
||||
bool adjustTableToFolio() const;
|
||||
bool addNewTableToNewDiagram() const;
|
||||
|
||||
@ -57,6 +55,7 @@ class AddTableDialog : public QDialog
|
||||
QMargins tableMargins() const;
|
||||
Qt::Alignment tableAlignment() const;
|
||||
QFont tableFont() const;
|
||||
QWidget *contentWidget() const;
|
||||
|
||||
private slots:
|
||||
void on_m_header_font_pb_clicked();
|
||||
@ -69,7 +68,8 @@ class AddTableDialog : public QDialog
|
||||
|
||||
private:
|
||||
Ui::AddTableDialog *ui;
|
||||
ElementQueryWidget *m_query_widget = new ElementQueryWidget();
|
||||
|
||||
QWidget *m_content_widget = nullptr;
|
||||
|
||||
QMargins m_header_margins = QMargins(5,5,10,5),
|
||||
m_table_margins = QMargins(5,5,10,5);
|
||||
@ -77,6 +77,8 @@ class AddTableDialog : public QDialog
|
||||
QFont m_header_font = QETApp::diagramTextsFont();
|
||||
QFont m_table_font = QETApp::diagramTextsFont();
|
||||
|
||||
QString m_identifier;
|
||||
|
||||
};
|
||||
|
||||
#endif // ADDTABLEDIALOG_H
|
||||
|
@ -403,6 +403,14 @@ void QETDiagramEditor::setUpActions()
|
||||
}
|
||||
});
|
||||
|
||||
//Add a summary item
|
||||
m_add_summary = new QAction(QET::Icons::TableOfContent, tr("Ajouter un sommaire"), this);
|
||||
connect(m_add_summary, &QAction::triggered, [this]() {
|
||||
if(this->currentDiagramView()) {
|
||||
QetGraphicsTableFactory::createAndAddSummary(this->currentDiagramView()->diagram());
|
||||
}
|
||||
});
|
||||
|
||||
//Lauch the plugin of terminal generator
|
||||
m_project_terminalBloc = new QAction(QET::Icons::TerminalStrip, tr("Lancer le plugin de création de borniers"), this);
|
||||
connect(m_project_terminalBloc, &QAction::triggered, this, &QETDiagramEditor::generateTerminalBlock);
|
||||
@ -769,6 +777,7 @@ void QETDiagramEditor::setUpMenu() {
|
||||
menu_project -> addSeparator();
|
||||
menu_project -> addAction(m_project_folio_list);
|
||||
menu_project -> addAction(m_add_nomenclature);
|
||||
menu_project -> addAction(m_add_summary);
|
||||
menu_project -> addAction(m_csv_export);
|
||||
menu_project -> addAction(m_project_export_conductor_num);
|
||||
menu_project -> addAction(m_project_terminalBloc);
|
||||
@ -1449,6 +1458,7 @@ void QETDiagramEditor::slot_updateActions()
|
||||
m_clean_project -> setEnabled(editable_project);
|
||||
m_project_folio_list -> setEnabled(editable_project);
|
||||
m_add_nomenclature->setEnabled(editable_project);
|
||||
m_add_summary->setEnabled(editable_project);
|
||||
m_csv_export -> setEnabled(editable_project);
|
||||
m_export_diagram -> setEnabled(opened_diagram);
|
||||
m_print -> setEnabled(opened_diagram);
|
||||
|
@ -185,6 +185,7 @@ class QETDiagramEditor : public QETMainWindow
|
||||
QAction *m_project_folio_list; ///< Sommaire des schemas
|
||||
QAction *m_csv_export; ///< generate nomenclature
|
||||
QAction *m_add_nomenclature; ///< Add nomenclature graphics item;
|
||||
QAction *m_add_summary; ///<Add summary graphics item
|
||||
QAction *m_project_terminalBloc; ///< generate terminal block
|
||||
QAction *m_project_export_conductor_num; ///<Export the wire num to csv
|
||||
QAction *m_export_project_db; ///Export to file the internal database of the current project
|
||||
|
@ -1,365 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2020 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 "nomenclaturemodel.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetproject.h"
|
||||
#include "qetxml.h"
|
||||
|
||||
#include <QModelIndex>
|
||||
#include <QFont>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlRecord>
|
||||
#include <QSqlError>
|
||||
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::NomenclatureModel
|
||||
* @param project :project of this nomenclature
|
||||
* @param parent : parent QObject
|
||||
*/
|
||||
NomenclatureModel::NomenclatureModel(QETProject *project, QObject *parent) :
|
||||
QAbstractTableModel(parent),
|
||||
m_project(project)
|
||||
{
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::NomenclatureModel
|
||||
* @param other_model
|
||||
*/
|
||||
NomenclatureModel::NomenclatureModel(const NomenclatureModel &other_model):
|
||||
QAbstractTableModel(other_model.parent())
|
||||
{
|
||||
this->setParent(other_model.parent());
|
||||
m_project = other_model.m_project;
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
m_index_0_0_data = other_model.m_index_0_0_data;
|
||||
query(other_model.queryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::rowCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int NomenclatureModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_record.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::columnCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int NomenclatureModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
if (m_record.count()) {
|
||||
return m_record.first().count();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::setHeaderData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* Only horizontal orientation is accepted.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool NomenclatureModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return false;
|
||||
}
|
||||
auto hash_ = m_header_data.value(section);
|
||||
hash_.insert(role, value);
|
||||
m_header_data.insert(section, hash_);
|
||||
headerDataChanged(orientation, section, section);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::headerData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant NomenclatureModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (m_header_data.contains(section))
|
||||
{
|
||||
auto hash_ = m_header_data.value(section);
|
||||
if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt
|
||||
return hash_.value(Qt::EditRole);
|
||||
}
|
||||
return m_header_data.value(section).value(role);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::setData
|
||||
* Only store the data for the index 0.0
|
||||
* @param index
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool NomenclatureModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() != 0 || index.column() != 0) {
|
||||
return false;
|
||||
}
|
||||
m_index_0_0_data.insert(role, value);
|
||||
emit dataChanged(index, index, QVector<int>(role));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::data
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param index
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant NomenclatureModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() == 0 &&
|
||||
index.column() == 0 &&
|
||||
role != Qt::DisplayRole) {
|
||||
return m_index_0_0_data.value(role);
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QVariant v(m_record.at(index.row()).at(index.column()));
|
||||
return v;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::query
|
||||
* Query the internall bd with @query.
|
||||
* @param query
|
||||
*/
|
||||
void NomenclatureModel::query(const QString &query)
|
||||
{
|
||||
auto rm_ = m_query != query;
|
||||
if (rm_) {
|
||||
emit beginResetModel();
|
||||
}
|
||||
|
||||
m_query = query;
|
||||
|
||||
if (m_project)
|
||||
{
|
||||
if (rm_) {
|
||||
disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
m_project->dataBase()->updateDB();
|
||||
if (rm_) {
|
||||
setHeaderString();
|
||||
fillValue();
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &NomenclatureModel::dataBaseUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
if (rm_) { emit endResetModel();}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::queryString
|
||||
* @return the current query used by this model
|
||||
*/
|
||||
QString NomenclatureModel::queryString() const {
|
||||
return m_query;
|
||||
}
|
||||
|
||||
QETProject *NomenclatureModel::project() const {
|
||||
return m_project.data();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::toXml
|
||||
* Save the model to xml,since model can have unlimited data we only save few data (only these used by qelectrotech).
|
||||
* The query, all header data. and some data of index::(0,0). All other data are not saved.
|
||||
* @param document
|
||||
* @return
|
||||
*/
|
||||
QDomElement NomenclatureModel::toXml(QDomDocument &document) const
|
||||
{
|
||||
auto dom_element = document.createElement(xmlTagName());
|
||||
|
||||
//query
|
||||
auto dom_query = document.createElement("query");
|
||||
auto dom_query_txt = document.createTextNode(m_query);
|
||||
dom_query.appendChild(dom_query_txt);
|
||||
dom_element.appendChild(dom_query);
|
||||
|
||||
//Add index 0,0 data
|
||||
auto index_00 = document.createElement("index00");
|
||||
index_00.setAttribute("font", m_index_0_0_data.value(Qt::FontRole).toString());
|
||||
auto me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
index_00.setAttribute("alignment", me.valueToKey(m_index_0_0_data.value(Qt::TextAlignmentRole).toInt()));
|
||||
dom_element.appendChild(index_00);
|
||||
index_00.setAttribute("margins", m_index_0_0_data.value(Qt::UserRole+1).toString());
|
||||
|
||||
//header data
|
||||
QHash<int, QList<int>> horizontal_;
|
||||
for (auto key : m_header_data.keys())
|
||||
{
|
||||
//We save all data except the display role, because he was generated in the fly
|
||||
auto list = m_header_data.value(key).keys();
|
||||
list.removeAll(Qt::DisplayRole);
|
||||
|
||||
horizontal_.insert(key, list);
|
||||
}
|
||||
|
||||
dom_element.appendChild(QETXML::modelHeaderDataToXml(document, this, horizontal_, QHash<int, QList<int>>()));
|
||||
|
||||
return dom_element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::fromXml
|
||||
* Restore the model from xml
|
||||
* @param element
|
||||
*/
|
||||
void NomenclatureModel::fromXml(const QDomElement &element)
|
||||
{
|
||||
if (element.tagName() != xmlTagName())
|
||||
return;
|
||||
|
||||
query(element.firstChildElement("query").text());
|
||||
|
||||
//Index 0,0
|
||||
auto index_00 = element.firstChildElement("index00");
|
||||
QFont font_;
|
||||
font_.fromString(index_00.attribute("font"));
|
||||
m_index_0_0_data.insert(Qt::FontRole, font_);
|
||||
auto me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_index_0_0_data.insert(Qt::TextAlignmentRole, me.keyToValue(index_00.attribute("alignment").toStdString().data()));
|
||||
m_index_0_0_data.insert(Qt::UserRole+1, index_00.attribute("margins"));
|
||||
|
||||
QETXML::modelHeaderDataFromXml(element.firstChildElement("header_data"), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModel::dataBaseUpdated
|
||||
* slot called when the project database is updated
|
||||
*/
|
||||
void NomenclatureModel::dataBaseUpdated()
|
||||
{
|
||||
auto original_record = m_record;
|
||||
fillValue();
|
||||
auto new_record = m_record;
|
||||
m_record = original_record;
|
||||
|
||||
//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 beginResetModel();
|
||||
m_record = new_record;
|
||||
emit endResetModel();
|
||||
}
|
||||
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<int>(Qt::DisplayRole));
|
||||
}
|
||||
}
|
||||
|
||||
void NomenclatureModel::setHeaderString()
|
||||
{
|
||||
auto q = m_project->dataBase()->newQuery(m_query);
|
||||
auto record = q.record();
|
||||
|
||||
for (auto i=0 ; i<record.count() ; ++i)
|
||||
{
|
||||
auto field_name = record.fieldName(i);
|
||||
QString header_name;
|
||||
|
||||
if (field_name == "position") {
|
||||
header_name = tr("Position");
|
||||
} else if (field_name == "diagram_position") {
|
||||
header_name = tr("Position du folio");
|
||||
} else {
|
||||
header_name = QETApp::elementTranslatedInfoKey(field_name);
|
||||
if (header_name.isEmpty()) {
|
||||
header_name = QETApp::diagramTranslatedInfoKey(field_name);
|
||||
}
|
||||
if (header_name.isEmpty()) {
|
||||
header_name = field_name;
|
||||
}
|
||||
}
|
||||
this->setHeaderData(i, Qt::Horizontal, header_name);
|
||||
}
|
||||
}
|
||||
|
||||
void NomenclatureModel::fillValue()
|
||||
{
|
||||
m_record.clear();
|
||||
|
||||
auto query_ = m_project->dataBase()->newQuery(m_query);
|
||||
if (!query_.exec()) {
|
||||
qDebug() << "Query error : " << query_.lastError();
|
||||
}
|
||||
|
||||
while (query_.next())
|
||||
{
|
||||
QStringList record_;
|
||||
auto i=0;
|
||||
while (query_.value(i).isValid())
|
||||
{
|
||||
record_ << query_.value(i).toString();
|
||||
++i;
|
||||
}
|
||||
m_record << record_;
|
||||
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
Copyright 2006-2020 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 NOMENCLATUREMODEL_H
|
||||
#define NOMENCLATUREMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QPointer>
|
||||
#include <QDomElement>
|
||||
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The NomenclatureModel class
|
||||
* An element nomenclature Model.
|
||||
* This model represent a 2D data.
|
||||
*
|
||||
* NOTE : qelectrotech use the data Qt::UserRole+1 on this model to store a QMargins formated to a QString
|
||||
* This is important because to/from XML of this class store the data Qt::UserRole+1 as QString.
|
||||
*/
|
||||
class NomenclatureModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NomenclatureModel(QETProject *project, QObject *parent = nullptr);
|
||||
explicit NomenclatureModel (const NomenclatureModel &other_model);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
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);
|
||||
QString queryString() const;
|
||||
QETProject *project() const;
|
||||
|
||||
QDomElement toXml(QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
static QString xmlTagName() {return QString("nomenclature_model");}
|
||||
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
void setHeaderString();
|
||||
void fillValue();
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QString m_query;
|
||||
QVector<QStringList> m_record;
|
||||
QHash<int, QHash<int, QVariant>> m_header_data; //First int = section, second int = Qt::role, QVariant = value
|
||||
QHash<int, QVariant> m_index_0_0_data;
|
||||
};
|
||||
|
||||
#endif // NOMENCLATUREMODEL_H
|
378
sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp
Normal file
378
sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp
Normal file
@ -0,0 +1,378 @@
|
||||
/*
|
||||
Copyright 2006-2020 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 "projectdbmodel.h"
|
||||
#include "projectdatabase.h"
|
||||
#include "qetproject.h"
|
||||
#include "qetxml.h"
|
||||
#include "qetapp.h"
|
||||
|
||||
#include <QSqlError>
|
||||
#include <QSqlRecord>
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::ProjectDBModel
|
||||
* @param project :project of this nomenclature
|
||||
* @param parent : parent QObject
|
||||
*/
|
||||
ProjectDBModel::ProjectDBModel(QETProject *project, QObject *parent) :
|
||||
QAbstractTableModel(parent),
|
||||
m_project(project)
|
||||
{
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::ProjectDBModel
|
||||
* @param other_model
|
||||
*/
|
||||
ProjectDBModel::ProjectDBModel(const ProjectDBModel &other_model) :
|
||||
QAbstractTableModel(other_model.parent())
|
||||
{
|
||||
this->setParent(other_model.parent());
|
||||
m_project = other_model.m_project;
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated);
|
||||
m_index_0_0_data = other_model.m_index_0_0_data;
|
||||
setQuery(other_model.queryString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::rowCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int ProjectDBModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return m_record.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::columnCount
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
int ProjectDBModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
if (m_record.count()) {
|
||||
return m_record.first().count();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::setHeaderData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* Only horizontal orientation is accepted.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool ProjectDBModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return false;
|
||||
}
|
||||
auto hash_ = m_header_data.value(section);
|
||||
hash_.insert(role, value);
|
||||
m_header_data.insert(section, hash_);
|
||||
headerDataChanged(orientation, section, section);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::headerData
|
||||
* Reimplemented from QAbstractTableModel.
|
||||
* @param section
|
||||
* @param orientation
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant ProjectDBModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Vertical) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (m_header_data.contains(section))
|
||||
{
|
||||
auto hash_ = m_header_data.value(section);
|
||||
if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt
|
||||
return hash_.value(Qt::EditRole);
|
||||
}
|
||||
return m_header_data.value(section).value(role);
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::setData
|
||||
* Only store the data for the index 0.0
|
||||
* @param index
|
||||
* @param value
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
bool ProjectDBModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (!index.isValid() || index.row() != 0 || index.column() != 0) {
|
||||
return false;
|
||||
}
|
||||
m_index_0_0_data.insert(role, value);
|
||||
emit dataChanged(index, index, QVector<int>(role));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::data
|
||||
* Reimplemented for QAbstractTableModel
|
||||
* @param index
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
QVariant ProjectDBModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() == 0 &&
|
||||
index.column() == 0 &&
|
||||
role != Qt::DisplayRole) {
|
||||
return m_index_0_0_data.value(role);
|
||||
}
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QVariant v(m_record.at(index.row()).at(index.column()));
|
||||
return v;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::setQuery
|
||||
* Query the internall bd with @query.
|
||||
* @param query
|
||||
*/
|
||||
void ProjectDBModel::setQuery(const QString &query)
|
||||
{
|
||||
auto rm_ = m_query != query;
|
||||
if (rm_) {
|
||||
emit beginResetModel();
|
||||
}
|
||||
|
||||
m_query = query;
|
||||
|
||||
if (m_project)
|
||||
{
|
||||
if (rm_) {
|
||||
disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated);
|
||||
}
|
||||
m_project->dataBase()->updateDB();
|
||||
if (rm_) {
|
||||
setHeaderString();
|
||||
fillValue();
|
||||
connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
if (rm_) {
|
||||
emit endResetModel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::queryString
|
||||
* @return the current query used by this model
|
||||
*/
|
||||
QString ProjectDBModel::queryString() const {
|
||||
return m_query;
|
||||
}
|
||||
|
||||
QETProject *ProjectDBModel::project() const {
|
||||
return m_project.data();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::toXml
|
||||
* Save the model to xml,since model can have unlimited data we only save few data (only these used by qelectrotech).
|
||||
* The query, all header data. and some data of index::(0,0). All other data are not saved.
|
||||
* @param document
|
||||
* @return
|
||||
*/
|
||||
QDomElement ProjectDBModel::toXml(QDomDocument &document) const
|
||||
{
|
||||
auto dom_element = document.createElement(xmlTagName());
|
||||
|
||||
//Identifier
|
||||
auto dom_identifier = document.createElement("identifier");
|
||||
auto dom_identifier_text = document.createTextNode(m_identifier);
|
||||
dom_identifier.appendChild(dom_identifier_text);
|
||||
dom_element.appendChild(dom_identifier);
|
||||
|
||||
//query
|
||||
auto dom_query = document.createElement("query");
|
||||
auto dom_query_text = document.createTextNode(m_query);
|
||||
dom_query.appendChild(dom_query_text);
|
||||
dom_element.appendChild(dom_query);
|
||||
|
||||
//Add index 0,0 data
|
||||
auto index_00 = document.createElement("index00");
|
||||
index_00.setAttribute("font", m_index_0_0_data.value(Qt::FontRole).toString());
|
||||
auto me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
index_00.setAttribute("alignment", me.valueToKey(m_index_0_0_data.value(Qt::TextAlignmentRole).toInt()));
|
||||
dom_element.appendChild(index_00);
|
||||
index_00.setAttribute("margins", m_index_0_0_data.value(Qt::UserRole+1).toString());
|
||||
|
||||
//header data
|
||||
QHash<int, QList<int>> horizontal_;
|
||||
for (auto key : m_header_data.keys())
|
||||
{
|
||||
//We save all data except the display role, because he was generated in the fly
|
||||
auto list = m_header_data.value(key).keys();
|
||||
list.removeAll(Qt::DisplayRole);
|
||||
|
||||
horizontal_.insert(key, list);
|
||||
}
|
||||
|
||||
dom_element.appendChild(QETXML::modelHeaderDataToXml(document, this, horizontal_, QHash<int, QList<int>>()));
|
||||
|
||||
return dom_element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::fromXml
|
||||
* Restore the model from xml
|
||||
* @param element
|
||||
*/
|
||||
void ProjectDBModel::fromXml(const QDomElement &element)
|
||||
{
|
||||
if (element.tagName() != xmlTagName())
|
||||
return;
|
||||
|
||||
setIdentifier(element.firstChildElement("identifier").text());
|
||||
setQuery(element.firstChildElement("query").text());
|
||||
|
||||
//Index 0,0
|
||||
auto index_00 = element.firstChildElement("index00");
|
||||
QFont font_;
|
||||
font_.fromString(index_00.attribute("font"));
|
||||
m_index_0_0_data.insert(Qt::FontRole, font_);
|
||||
auto me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_index_0_0_data.insert(Qt::TextAlignmentRole, me.keyToValue(index_00.attribute("alignment").toStdString().data()));
|
||||
m_index_0_0_data.insert(Qt::UserRole+1, index_00.attribute("margins"));
|
||||
|
||||
QETXML::modelHeaderDataFromXml(element.firstChildElement("header_data"), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::setIdentifier
|
||||
* Set the identifier of this model to @identifier
|
||||
* @param identifier
|
||||
*/
|
||||
void ProjectDBModel::setIdentifier(const QString &identifier) {
|
||||
m_identifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ProjectDBModel::dataBaseUpdated
|
||||
* slot called when the project database is updated
|
||||
*/
|
||||
void ProjectDBModel::dataBaseUpdated()
|
||||
{
|
||||
auto original_record = m_record;
|
||||
fillValue();
|
||||
auto new_record = m_record;
|
||||
m_record = original_record;
|
||||
|
||||
//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 beginResetModel();
|
||||
m_record = new_record;
|
||||
emit endResetModel();
|
||||
}
|
||||
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<int>(Qt::DisplayRole));
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDBModel::setHeaderString()
|
||||
{
|
||||
auto q = m_project->dataBase()->newQuery(m_query);
|
||||
auto record = q.record();
|
||||
|
||||
for (auto i=0 ; i<record.count() ; ++i)
|
||||
{
|
||||
auto field_name = record.fieldName(i);
|
||||
QString header_name;
|
||||
|
||||
if (field_name == "position") {
|
||||
header_name = tr("Position");
|
||||
} else if (field_name == "diagram_position") {
|
||||
header_name = tr("Position du folio");
|
||||
} else {
|
||||
header_name = QETApp::elementTranslatedInfoKey(field_name);
|
||||
if (header_name.isEmpty()) {
|
||||
header_name = QETApp::diagramTranslatedInfoKey(field_name);
|
||||
}
|
||||
if (header_name.isEmpty()) {
|
||||
header_name = field_name;
|
||||
}
|
||||
}
|
||||
this->setHeaderData(i, Qt::Horizontal, header_name);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectDBModel::fillValue()
|
||||
{
|
||||
m_record.clear();
|
||||
|
||||
auto query_ = m_project->dataBase()->newQuery(m_query);
|
||||
if (!query_.exec()) {
|
||||
qDebug() << "Query error : " << query_.lastError();
|
||||
}
|
||||
|
||||
while (query_.next())
|
||||
{
|
||||
QStringList record_;
|
||||
auto i=0;
|
||||
while (query_.value(i).isValid())
|
||||
{
|
||||
record_ << query_.value(i).toString();
|
||||
++i;
|
||||
}
|
||||
m_record << record_;
|
||||
}
|
||||
}
|
||||
|
73
sources/qetgraphicsitem/ViewItem/projectdbmodel.h
Normal file
73
sources/qetgraphicsitem/ViewItem/projectdbmodel.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright 2006-2020 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 PROJECTDBMODEL_H
|
||||
#define PROJECTDBMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QPointer>
|
||||
#include <QDomElement>
|
||||
|
||||
class QETProject;
|
||||
|
||||
/**
|
||||
* @brief The ProjectDBModel class
|
||||
* This model is intended to be use with the @class projectDataBase
|
||||
* and is designed to be displayed by the @class QetGraphicsTableItem (but can be use by other view class since it inherit from QAbstractTableModel).
|
||||
* This class should be sufficient to display the content of the project data base from a query set by the method void ProjectDBModel::setQuery(const QString &query).
|
||||
* The indentifier method is used by widget editor to retrieve the good widget for edit the query. By defaut identifer return the string 'unknow'.
|
||||
* You should use setIdentfier method to set your custom identifier.
|
||||
*/
|
||||
class ProjectDBModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ProjectDBModel(QETProject *project, QObject *parent = nullptr);
|
||||
explicit ProjectDBModel (const ProjectDBModel &other_model);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
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 setQuery(const QString &setQuery);
|
||||
QString queryString() const;
|
||||
QETProject *project() const;
|
||||
|
||||
QDomElement toXml(QDomDocument &document) const;
|
||||
void fromXml(const QDomElement &element);
|
||||
void setIdentifier(const QString &identifier);
|
||||
QString indentifier() const {return m_identifier;}
|
||||
static QString xmlTagName() {return QString("project_data_base_model");}
|
||||
|
||||
private:
|
||||
void dataBaseUpdated();
|
||||
void setHeaderString();
|
||||
void fillValue();
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
QString m_query;
|
||||
QVector<QStringList> m_record;
|
||||
QHash<int, QHash<int, QVariant>> m_header_data; //First int = section, second int = Qt::role, QVariant = value
|
||||
QHash<int, QVariant> m_index_0_0_data;
|
||||
QString m_identifier = "unknow";
|
||||
};
|
||||
|
||||
#endif // PROJECTDBMODEL_H
|
@ -23,6 +23,7 @@
|
||||
#include "nomenclaturemodel.h"
|
||||
#include "elementprovider.h"
|
||||
#include "qetutils.h"
|
||||
#include "projectdbmodel.h"
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QFontMetrics>
|
||||
@ -343,7 +344,7 @@ void QetGraphicsTableItem::setPreviousTable(QetGraphicsTableItem *table)
|
||||
}
|
||||
else //Copie the model of old previous table
|
||||
{
|
||||
setModel(new NomenclatureModel(*static_cast<NomenclatureModel *>(old_previous_table->model())));
|
||||
setModel(new ProjectDBModel(*static_cast<ProjectDBModel *>(old_previous_table->model())));
|
||||
}
|
||||
|
||||
if (old_previous_table &&
|
||||
@ -473,8 +474,8 @@ QDomElement QetGraphicsTableItem::toXml(QDomDocument &dom_document) const
|
||||
{
|
||||
//Add model
|
||||
auto dom_model = dom_document.createElement("model");
|
||||
auto nomenclature_model = static_cast<NomenclatureModel *>(m_model);
|
||||
dom_model.appendChild(nomenclature_model->toXml(dom_document));
|
||||
auto project_db_model = static_cast<ProjectDBModel *>(m_model);
|
||||
dom_model.appendChild(project_db_model->toXml(dom_document));
|
||||
dom_table.appendChild(dom_model);
|
||||
|
||||
}
|
||||
@ -511,8 +512,8 @@ void QetGraphicsTableItem::fromXml(const QDomElement &dom_element)
|
||||
else if (this->diagram()) //The table haven't got a previous table, so there should be a model save to xml
|
||||
{
|
||||
//Get table
|
||||
auto model_ = new NomenclatureModel(this->diagram()->project(), this->diagram()->project());
|
||||
model_->fromXml(dom_element.firstChildElement("model").firstChildElement(NomenclatureModel::xmlTagName()));
|
||||
auto model_ = new ProjectDBModel(this->diagram()->project(), this->diagram()->project());
|
||||
model_->fromXml(dom_element.firstChildElement("model").firstChildElement(ProjectDBModel::xmlTagName()));
|
||||
this->setModel(model_);
|
||||
}
|
||||
|
||||
|
@ -15,48 +15,48 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "nomenclaturemodelpropertieswidget.h"
|
||||
#include "ui_nomenclaturemodelpropertieswidget.h"
|
||||
#include "nomenclaturemodel.h"
|
||||
#include "projectdbmodelpropertieswidget.h"
|
||||
#include "ui_projectdbmodelpropertieswidget.h"
|
||||
#include "projectdbmodel.h"
|
||||
#include "qetproject.h"
|
||||
#include "elementquerywidget.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget
|
||||
* @brief projectDBModelPropertiesWidget::projectDBModelPropertiesWidget
|
||||
* @param model
|
||||
* @param parent
|
||||
*/
|
||||
NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget(NomenclatureModel *model, QWidget *parent) :
|
||||
ProjectDBModelPropertiesWidget::ProjectDBModelPropertiesWidget(ProjectDBModel *model, QWidget *parent) :
|
||||
PropertiesEditorWidget(parent),
|
||||
ui(new Ui::NomenclatureModelPropertiesWidget)
|
||||
ui(new Ui::ProjectDBModelPropertiesWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setModel(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget
|
||||
* @brief projectDBModelPropertiesWidget::~projectDBModelPropertiesWidget
|
||||
*/
|
||||
NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget() {
|
||||
ProjectDBModelPropertiesWidget::~ProjectDBModelPropertiesWidget() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::setModel
|
||||
* @brief projectDBModelPropertiesWidget::setModel
|
||||
* @param model
|
||||
*/
|
||||
void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) {
|
||||
void ProjectDBModelPropertiesWidget::setModel(ProjectDBModel *model) {
|
||||
m_model = model;
|
||||
ui->m_edit_query_pb->setEnabled(m_model);
|
||||
ui->m_refresh_pb->setEnabled(m_model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked
|
||||
* @brief projectDBModelPropertiesWidget::on_m_edit_query_pb_clicked
|
||||
*/
|
||||
void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
void ProjectDBModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
{
|
||||
QDialog d(this);
|
||||
auto l = new QVBoxLayout;
|
||||
@ -73,7 +73,7 @@ void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
|
||||
if (d.exec())
|
||||
{
|
||||
m_model->query(query_widget->queryStr());
|
||||
m_model->setQuery(query_widget->queryStr());
|
||||
auto headers = query_widget->header();
|
||||
for (auto i=0 ; i<headers.size() ; ++i) {
|
||||
m_model->setHeaderData(i, Qt::Horizontal, headers.at(i));
|
||||
@ -81,7 +81,7 @@ void NomenclatureModelPropertiesWidget::on_m_edit_query_pb_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void NomenclatureModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
void ProjectDBModelPropertiesWidget::on_m_refresh_pb_clicked() {
|
||||
if (m_model && m_model->project()) {
|
||||
m_model->project()->dataBase()->updateDB();
|
||||
}
|
@ -15,38 +15,39 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef NOMENCLATUREMODELPROPERTIESWIDGET_H
|
||||
#define NOMENCLATUREMODELPROPERTIESWIDGET_H
|
||||
#ifndef PROJECTDBMODELPROPERTIESWIDGET_H
|
||||
#define PROJECTDBMODELPROPERTIESWIDGET_H
|
||||
|
||||
#include "PropertiesEditor/propertieseditorwidget.h"
|
||||
|
||||
class NomenclatureModel;
|
||||
class ProjectDBModel;
|
||||
|
||||
namespace Ui {
|
||||
class NomenclatureModelPropertiesWidget;
|
||||
class ProjectDBModelPropertiesWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The NomenclatureModelPropertiesWidget class
|
||||
* @brief The projectDBModelPropertiesWidget class
|
||||
* This class is an editor for a NomenclatureModel
|
||||
*/
|
||||
class NomenclatureModelPropertiesWidget : public PropertiesEditorWidget
|
||||
class ProjectDBModelPropertiesWidget : public PropertiesEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NomenclatureModelPropertiesWidget(NomenclatureModel *model = nullptr, QWidget *parent = nullptr);
|
||||
~NomenclatureModelPropertiesWidget();
|
||||
explicit ProjectDBModelPropertiesWidget(ProjectDBModel *model = nullptr, QWidget *parent = nullptr);
|
||||
~ProjectDBModelPropertiesWidget();
|
||||
|
||||
void setModel(NomenclatureModel *model);
|
||||
void setModel(ProjectDBModel *model);
|
||||
|
||||
private slots:
|
||||
void on_m_edit_query_pb_clicked();
|
||||
void on_m_refresh_pb_clicked();
|
||||
|
||||
private:
|
||||
Ui::NomenclatureModelPropertiesWidget *ui;
|
||||
NomenclatureModel *m_model = nullptr;
|
||||
Ui::ProjectDBModelPropertiesWidget *ui;
|
||||
ProjectDBModel *m_model = nullptr;
|
||||
};
|
||||
|
||||
#endif // NOMENCLATUREMODELPROPERTIESWIDGET_H
|
||||
#endif // PROJECTDBMODELPROPERTIESWIDGET_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NomenclatureModelPropertiesWidget</class>
|
||||
<widget class="QWidget" name="NomenclatureModelPropertiesWidget">
|
||||
<class>ProjectDBModelPropertiesWidget</class>
|
||||
<widget class="QWidget" name="ProjectDBModelPropertiesWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
Loading…
x
Reference in New Issue
Block a user