mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-01 09:09:58 +01:00
Add new summary table (WIP)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user