diff --git a/sources/factory/qetgraphicstablefactory.cpp b/sources/factory/qetgraphicstablefactory.cpp index bb813b86a..7c55a848d 100644 --- a/sources/factory/qetgraphicstablefactory.cpp +++ b/sources/factory/qetgraphicstablefactory.cpp @@ -46,7 +46,7 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram) { auto table_ = newTable(diagram, d.data()); if (d->adjustTableToFolio()) { - AdjustTableToFolio(table_); + QetGraphicsTableItem::adjustTableToFolio(table_); } @@ -68,7 +68,7 @@ void QetGraphicsTableFactory::createAndAddNomenclature(Diagram *diagram) table_->setTableName(d->tableName() + QString(" %1").arg(table_number)); //Adjust table if (d->adjustTableToFolio()) { - AdjustTableToFolio(table_); + QetGraphicsTableItem::adjustTableToFolio(table_); } //Update some variable for the next loop already_displayed_rows += table_->displayNRow(); @@ -114,26 +114,3 @@ QetGraphicsTableItem *QetGraphicsTableFactory::newTable(Diagram *diagram, AddTab return table; } - -/** - * @brief QetGraphicsTableFactory::AdjustTableToFolio - * Adjust @table to fit as better as possible to it's parent diagram. - * @param 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 9ce64e3e3..ab2ca2b70 100644 --- a/sources/factory/qetgraphicstablefactory.h +++ b/sources/factory/qetgraphicstablefactory.h @@ -33,7 +33,6 @@ class QetGraphicsTableFactory static void createAndAddNomenclature(Diagram *diagram); private: static QetGraphicsTableItem *newTable(Diagram *diagram, AddTableDialog *dialog, QetGraphicsTableItem *previous_table = nullptr); - static void AdjustTableToFolio(QetGraphicsTableItem *table); }; #endif // QETGRAPHICSTABLEFACTORY_H diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index d6278f84b..65feaf385 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -33,6 +33,34 @@ static int no_model_height = 20; static int no_model_width = 40; +/** + * @brief QetGraphicsTableItem::adjustTableToFolio + * Adjust the table @table to fit at best the folio + * @param table : table to adjust + * @param margins : margins between table and folio. + */ +void QetGraphicsTableItem::adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins) +{ + if (!table->diagram()) { + return; + } + + auto drawable_rect = table->diagram()->border_and_titleblock.insideBorderRect(); + table->setPos(drawable_rect.topLeft().x() + margins.left(), drawable_rect.topLeft().y() + margins.top() + table->headerItem()->rect().height()); + + auto size_ = table->size(); + size_.setWidth(int(drawable_rect.width() - (margins.left() + margins.right()))); + //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 +} + /** * @brief QetGraphicsTableItem::QetGraphicsTableItem * Default constructor diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h index 1d000539f..9b1741ccb 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h @@ -46,6 +46,9 @@ class QetGraphicsTableItem : public QetGraphicsItem Q_PROPERTY(QSize size READ size WRITE setSize) Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow) + public : + static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0)); + public: QetGraphicsTableItem(QGraphicsItem *parent= nullptr); virtual ~QetGraphicsTableItem() override; diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp index e27f90fa7..e3e573189 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp @@ -365,3 +365,51 @@ void GraphicsTablePropertiesEditor::on_m_next_pb_clicked() new_table->setSelected(true); old_table->setSelected(false); } + +/** + * @brief GraphicsTablePropertiesEditor::on_m_auto_geometry_pb_clicked + */ +void GraphicsTablePropertiesEditor::on_m_auto_geometry_pb_clicked() +{ + if (m_table_item) { + QetGraphicsTableItem::adjustTableToFolio(m_table_item); + } +} + +/** + * @brief GraphicsTablePropertiesEditor::on_m_apply_geometry_to_linked_table_pb_clicked + */ +void GraphicsTablePropertiesEditor::on_m_apply_geometry_to_linked_table_pb_clicked() +{ + if (m_table_item.isNull() || !m_table_item->diagram() || (!m_table_item->nextTable() && !m_table_item->previousTable())) { + return; + } + auto first_table = m_table_item; + while (first_table->previousTable()) { + first_table = first_table->previousTable(); + } + + //Get all linked tables. + QVector vector_; + vector_ << first_table; + while (first_table->nextTable()) + { + vector_ << first_table->nextTable(); + first_table = first_table->nextTable(); + } + vector_.removeAll(m_table_item); + + + auto new_pos = m_table_item->pos(); + auto new_size = m_table_item->size(); + auto new_displayN_row = m_table_item->displayNRow(); + //Apply to all linked table + auto parent_undo = new QUndoCommand(tr("Appliquer la géometrie d'un tableau aux tableau liée à celui-ci")); + for (auto table : vector_) + { + new QPropertyUndoCommand(table, "pos", table->pos(), new_pos, parent_undo); + new QPropertyUndoCommand(table, "size", table->size(), new_size, parent_undo); + new QPropertyUndoCommand(table, "displayNRow", table->displayNRow(), new_displayN_row, parent_undo); + } + m_table_item->diagram()->undoStack().push(parent_undo); +} diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h index 0e9194f9d..0df36aecf 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h @@ -56,7 +56,11 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget void on_m_previous_pb_clicked(); void on_m_next_pb_clicked(); - private: + void on_m_auto_geometry_pb_clicked(); + + void on_m_apply_geometry_to_linked_table_pb_clicked(); + + private: void setUpEditConnection(); private: diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui index d15459836..1922c0296 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui @@ -6,8 +6,8 @@ 0 0 - 467 - 672 + 524 + 600 @@ -37,10 +37,31 @@ - Position et lignes + Géometrie et lignes - - + + + + + Appliquer la géometrie à tous les tableaux liée à celui-ci + + + + + + + :/ico/22x22/all_pages.png:/ico/22x22/all_pages.png + + + + + + + 10000 + + + + QComboBox::InsertAtBottom @@ -52,37 +73,7 @@ - - - - Toutes - - - 999 - - - - - - - Lignes à afficher : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Y : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + true @@ -102,13 +93,10 @@ - - - - X : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + 10000 @@ -125,7 +113,92 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ajuster le tableau au folio + + + + + + + :/ico/22x22/zoom-fit-best.png:/ico/22x22/zoom-fit-best.png + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Lignes à afficher : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + X : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Toutes + + + 999 + + + + + + + Tableau précédent : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + true @@ -145,55 +218,10 @@ - - - - 10000 - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 10000 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + + - Tableau précédent : + Y : Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -211,6 +239,9 @@ + + + @@ -224,6 +255,32 @@ + + + + Marge + + + Qt::AlignCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -237,35 +294,6 @@ - - - - Marge - - - Qt::AlignCenter - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - -