diff --git a/sources/factory/qetgraphicstablefactory.cpp b/sources/factory/qetgraphicstablefactory.cpp index 42bc415ce..44946a8ea 100644 --- a/sources/factory/qetgraphicstablefactory.cpp +++ b/sources/factory/qetgraphicstablefactory.cpp @@ -44,39 +44,76 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram) if (d->exec()) { - auto model = new NomenclatureModel(diagram->project(), diagram->project()); - model->query(d->queryStr()); - model->autoHeaders(); - model->setData(model->index(0,0), int(d->tableAlignment()), Qt::TextAlignmentRole); - model->setData(model->index(0,0), d->tableFont(), Qt::FontRole); - model->setData(model->index(0,0), QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1); - model->setHeaderData(0, Qt::Horizontal, int(d->headerAlignment()), Qt::TextAlignmentRole); - model->setHeaderData(0, Qt::Horizontal, d->headerFont(), Qt::FontRole); - model->setHeaderData(0, Qt::Horizontal, QETUtils::marginsToString(d->headerMargins()), Qt::UserRole+1); - - auto table = new QetGraphicsTableItem(); - table->setTableName(d->tableName()); - table->setModel(model); - diagram->addItem(table); - table->setPos(50,50); + auto table_ = newTable(diagram, d.data()); + if (d->adjustTableToFolio()) { + AdjustTableToFolio(table_); + } - if (d->adjustTableToFolio()) + if (d->addNewTableToNewDiagram() && table_->model()->rowCount() > table_->displayNRow()) { - auto drawable_rect = diagram->border_and_titleblock.insideBorderRect(); - table->setPos(drawable_rect.topLeft().x() + 20, drawable_rect.topLeft().y() + 20 + table->headerItem()->rect().height()); + auto already_displayed_rows = table_->displayNRow(); + auto project_ = diagram->project(); + auto actual_diagram = diagram; + auto previous_table = table_; - auto size_ = table->size(); - size_.setWidth(int(drawable_rect.width() - 40)); - //Size must be a multiple of 10, because the table adjust itself by step of 10. - while (size_.width()%10) { - --size_.rwidth(); } - table->setSize(size_); - - //Calcul the maximum row to display to fit the nomenclature into diagram - auto available_height = drawable_rect.height() - table->pos().y(); - auto min_row_height = table->minimumRowHeigth(); - table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok + int i = 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()); + table_->setTableName(d->tableName() + QString(" %1").arg(i)); + //Set the previous folio of table + table_->setPreviousTable(previous_table); + //Adjust table + if (d->adjustTableToFolio()) { + AdjustTableToFolio(table_); + } + //Update some variable for the next loop + already_displayed_rows += table_->displayNRow(); + previous_table = table_; + ++i; + } } } } + +QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTableDialog *dialog) +{ + auto model = new NomenclatureModel(diagram->project(), diagram->project()); + model->query(dialog->queryStr()); + model->autoHeaders(); + 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); + + auto table = new QetGraphicsTableItem(); + table->setTableName(dialog->tableName()); + table->setModel(model); + diagram->addItem(table); + table->setPos(50,50); + + return table; +} + +void QetGraphicsTableFactory::AdjustTableToFolio(QetGraphicsTableItem *table) +{ + auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect(); + table->setPos(drawable_rect.topLeft().x() + 20, drawable_rect.topLeft().y() + 20 + table->headerItem()->rect().height()); + + auto size_ = table->size(); + size_.setWidth(int(drawable_rect.width() - 40)); + //Size must be a multiple of 10, because the table adjust itself by step of 10. + while (size_.width()%10) { + --size_.rwidth(); } + table->setSize(size_); + + //Calcul the maximum row to display to fit the nomenclature into diagram + auto available_height = drawable_rect.height() - table->pos().y(); + auto min_row_height = table->minimumRowHeigth(); + table->setDisplayNRow(int(floor(available_height/min_row_height))); //Convert a double to int, but max_row_to_display is already rounded an integer so we assume everything is ok +} diff --git a/sources/factory/qetgraphicstablefactory.h b/sources/factory/qetgraphicstablefactory.h index b34284d3f..175f4f8bb 100644 --- a/sources/factory/qetgraphicstablefactory.h +++ b/sources/factory/qetgraphicstablefactory.h @@ -19,6 +19,8 @@ #define QETGRAPHICSTABLEFACTORY_H class Diagram; +class QetGraphicsTableItem; +class AddTableDialog; /** * @brief The QetGraphicsTableFactory class @@ -29,6 +31,9 @@ class QetGraphicsTableFactory QetGraphicsTableFactory(); static void createAndAddNomenclature(Diagram *diagram); + private: + static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog); + static void AdjustTableToFolio(QetGraphicsTableItem *table); }; #endif // QETGRAPHICSTABLEFACTORY_H diff --git a/sources/factory/ui/addtabledialog.ui b/sources/factory/ui/addtabledialog.ui index d4e48df67..9b2a6649b 100644 --- a/sources/factory/ui/addtabledialog.ui +++ b/sources/factory/ui/addtabledialog.ui @@ -40,7 +40,7 @@ - false + true Ajouter de nouveau folio et tableau si nécessaire.