2020-05-05 20:38:31 +02:00
|
|
|
/*
|
|
|
|
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 "qetgraphicstablefactory.h"
|
|
|
|
#include "qetgraphicstableitem.h"
|
|
|
|
#include "nomenclaturemodel.h"
|
|
|
|
#include "elementquerywidget.h"
|
|
|
|
#include "diagram.h"
|
|
|
|
#include "qetgraphicsheaderitem.h"
|
2020-05-08 00:08:57 +02:00
|
|
|
#include "addtabledialog.h"
|
|
|
|
#include "qetutils.h"
|
2020-05-05 20:38:31 +02:00
|
|
|
|
|
|
|
#include <QDialog>
|
2020-05-08 00:08:57 +02:00
|
|
|
|
2020-05-05 20:38:31 +02:00
|
|
|
QetGraphicsTableFactory::QetGraphicsTableFactory()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief QetGraphicsTableFactory::createAndAddNomenclature
|
|
|
|
* Create a nomenclature table, open a dialog for ask to user the config of the table,
|
|
|
|
* and add it to diagram @diagram;
|
|
|
|
* @param diagram
|
|
|
|
*/
|
|
|
|
void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram)
|
|
|
|
{
|
|
|
|
QScopedPointer<AddTableDialog> d(new AddTableDialog(diagram->views().first()));
|
|
|
|
d->setWindowTitle(QObject::tr("Ajouter une nomenclature"));
|
|
|
|
|
|
|
|
if (d->exec())
|
|
|
|
{
|
2020-05-24 17:17:17 +02:00
|
|
|
auto table_ = newTable(diagram, d.data());
|
|
|
|
if (d->adjustTableToFolio()) {
|
2020-06-11 10:41:01 +02:00
|
|
|
QetGraphicsTableItem::adjustTableToFolio(table_);
|
2020-05-24 17:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-24 17:23:11 +02:00
|
|
|
//Add new table if needed and option checked
|
2020-05-24 17:17:17 +02:00
|
|
|
if (d->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow())
|
2020-05-24 15:03:56 +02:00
|
|
|
{
|
2020-05-24 17:17:17 +02:00
|
|
|
auto already_displayed_rows = table_->displayNRow();
|
|
|
|
auto project_ = diagram->project();
|
|
|
|
auto actual_diagram = diagram;
|
|
|
|
auto previous_table = table_;
|
|
|
|
|
2020-05-24 17:23:11 +02:00
|
|
|
table_->setTableName(d->tableName() + QString(" 1"));
|
|
|
|
int table_number = 2;
|
2020-05-24 17:17:17 +02:00
|
|
|
while (already_displayed_rows < table_->model()->rowCount())
|
|
|
|
{
|
|
|
|
//Add a new diagram after the current one
|
|
|
|
actual_diagram = project_->addNewDiagram(project_->folioIndex(actual_diagram)+1);
|
2020-05-26 22:00:32 +02:00
|
|
|
table_ = newTable(actual_diagram, d.data(), previous_table);
|
2020-05-24 17:23:11 +02:00
|
|
|
table_->setTableName(d->tableName() + QString(" %1").arg(table_number));
|
2020-05-24 17:17:17 +02:00
|
|
|
//Adjust table
|
|
|
|
if (d->adjustTableToFolio()) {
|
2020-06-11 10:41:01 +02:00
|
|
|
QetGraphicsTableItem::adjustTableToFolio(table_);
|
2020-05-24 17:17:17 +02:00
|
|
|
}
|
|
|
|
//Update some variable for the next loop
|
|
|
|
already_displayed_rows += table_->displayNRow();
|
|
|
|
previous_table = table_;
|
2020-05-24 17:23:11 +02:00
|
|
|
++table_number;
|
2020-05-24 17:17:17 +02:00
|
|
|
}
|
2020-05-24 15:03:56 +02:00
|
|
|
}
|
2020-05-05 20:38:31 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-24 17:17:17 +02:00
|
|
|
|
2020-05-26 22:00:32 +02:00
|
|
|
/**
|
|
|
|
* @brief QetGraphicsTableFactory::newTable
|
|
|
|
* Create a new table .
|
|
|
|
* @param diagram : Diagram where we must add the new table.
|
|
|
|
* @param dialog : dialog conf, it's used to setup the model.
|
|
|
|
* @param previous_table : If you know that the new table will have a previous table and you already now the previous table,
|
|
|
|
* set it now they will improve time needed for creating the new table by avoiding to create a new model.
|
|
|
|
* @return the new table
|
|
|
|
*/
|
|
|
|
QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTableDialog *dialog, QetGraphicsTableItem *previous_table)
|
2020-05-24 17:17:17 +02:00
|
|
|
{
|
|
|
|
auto table = new QetGraphicsTableItem();
|
|
|
|
table->setTableName(dialog->tableName());
|
2020-05-26 22:00:32 +02:00
|
|
|
|
|
|
|
if (!previous_table)
|
|
|
|
{
|
|
|
|
auto model = new NomenclatureModel(diagram->project(), diagram->project());
|
|
|
|
model->query(dialog->queryStr());
|
|
|
|
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);
|
|
|
|
model->setHeaderData(0, Qt::Horizontal, int(dialog->headerAlignment()), Qt::TextAlignmentRole);
|
|
|
|
model->setHeaderData(0, Qt::Horizontal, dialog->headerFont(), Qt::FontRole);
|
|
|
|
model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(dialog->headerMargins()), Qt::UserRole+1);
|
|
|
|
table->setModel(model);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
table->setPreviousTable(previous_table);
|
|
|
|
}
|
|
|
|
|
2020-05-24 17:17:17 +02:00
|
|
|
diagram->addItem(table);
|
|
|
|
table->setPos(50,50);
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|