From 709280e3c1510ea1e0c4780a9fe387d9d978dc8b Mon Sep 17 00:00:00 2001 From: Claveau Joshua Date: Mon, 20 Jul 2020 19:38:52 +0200 Subject: [PATCH] QetGraphicsTableItem : add dialog to inform user When user edit the query of an existing table/s if the content to display is bigger than the content who can be displayed by the table/s a dialog is opened for inform user of the current situation. --- .../ViewItem/projectdbmodel.cpp | 2 - .../ViewItem/qetgraphicstableitem.cpp | 54 +++++++++++++++++++ .../ViewItem/qetgraphicstableitem.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp b/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp index fcfe08d86..7e4897f1d 100644 --- a/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp +++ b/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp @@ -309,8 +309,6 @@ void ProjectDBModel::dataBaseUpdated() 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(); diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index 05c26aff0..9d76db2e6 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -61,6 +61,56 @@ void QetGraphicsTableItem::adjustTableToFolio(QetGraphicsTableItem *table, QMarg 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::checkInsufficientRowsCount + * Check if the number of rows of @table + linked table is enough to display all + * content of the model, if not open a dialog to advise user what to do. + * @param table + */ +void QetGraphicsTableItem::checkInsufficientRowsCount(QetGraphicsTableItem *table) +{ + if (!table->diagram() || !table->model()) { + return; + } + + auto first_table = table; + while (first_table->previousTable()) + first_table = first_table->previousTable(); + + if (first_table->displayNRow() <= 0) //displayed rows is unlimited + return; + + int count_ = first_table->displayNRow(); + bool several_table = false; + while (first_table->nextTable()) + { + several_table = true; + first_table = first_table->nextTable(); + if (first_table->displayNRow() <= 0) { //displayed rows is unlimited + return; + } else { + count_ += first_table->displayNRow(); + first_table->displayNRowOffset(); + } + } + + if (count_ < first_table->model()->rowCount()) + { + QWidget *parent = first_table->diagram()->views().first() ? first_table->diagram()->views().first() : nullptr; + + QString text; + if (several_table) { + text = tr("Les information à afficher sont supérieurs à la quantité maximal pouvant être affiché par les tableaux.\n" + "Veuillez ajouter un nouveau tableau ou regler les tableaux existant afin d'afficher l'integralité des informations."); + } else { + text = tr("Les information à afficher sont supérieurs à la quantité maximal pouvant être affiché par le tableau.\n" + "Veuillez ajouter un nouveau tableau ou regler le tableau existant afin d'afficher l'integralité des informations."); + } + QMessageBox::information(parent, tr("Limitation de tableau"), text); + } + +} + /** * @brief QetGraphicsTableItem::QetGraphicsTableItem * Default constructor @@ -601,6 +651,10 @@ QVariant QetGraphicsTableItem::itemChange(QGraphicsItem::GraphicsItemChange chan void QetGraphicsTableItem::modelReseted() { dataChanged(m_model->index(0,0), m_model->index(0,0), QVector()); setToMinimumHeight(); + + if (!previousTable()) { //this is the head table + checkInsufficientRowsCount(this); + } } /** diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h index 9b1741ccb..90bb22215 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h @@ -48,6 +48,7 @@ class QetGraphicsTableItem : public QetGraphicsItem public : static void adjustTableToFolio(QetGraphicsTableItem *table, QMargins margins = QMargins(20,20,20,0)); + static void checkInsufficientRowsCount(QetGraphicsTableItem *first_table); public: QetGraphicsTableItem(QGraphicsItem *parent= nullptr);