From 871b0d9ee9171a871231feac99d65378f0c38771 Mon Sep 17 00:00:00 2001 From: Claveau Joshua Date: Fri, 10 Apr 2020 21:27:47 +0200 Subject: [PATCH] Table can be splitted and and row number limited 1.Table can have a name. 2.User can define the maximum row to display. 3.Table can be linked together, this is useful when there is a large data to display in a single table. Point 1, 2 and 3 work like this : -Name a table (point 1). -Limit the number of row to display to fit the table into a diagram (point 2). -Create a second table in a new folio. -Link the second table to first table, you can search by table name (point 3). -the new table start to display where the first table end. The number of linked table is unlimited. --- sources/elementprovider.cpp | 63 +++- sources/elementprovider.h | 15 +- .../ViewItem/qetgraphicsheaderitem.cpp | 44 ++- .../ViewItem/qetgraphicsheaderitem.h | 2 +- .../ViewItem/qetgraphicstableitem.cpp | 232 ++++++++++++- .../ViewItem/qetgraphicstableitem.h | 22 +- .../ui/graphicstablepropertieseditor.cpp | 47 +++ .../ui/graphicstablepropertieseditor.h | 7 +- .../ui/graphicstablepropertieseditor.ui | 325 ++++++++++++++++-- .../ui/nomenclaturemodelpropertieswidget.cpp | 6 +- 10 files changed, 685 insertions(+), 78 deletions(-) diff --git a/sources/elementprovider.cpp b/sources/elementprovider.cpp index 042a5b1c1..be65b300c 100644 --- a/sources/elementprovider.cpp +++ b/sources/elementprovider.cpp @@ -19,6 +19,8 @@ #include "qetproject.h" #include "diagram.h" #include "qetgraphicsitem/element.h" +#include "qetgraphicstableitem.h" +#include /** * @brief ElementProvider::ElementProvider Constructor @@ -27,8 +29,8 @@ */ ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram) { - diag_list = prj->diagrams(); - diag_list.removeOne(diagram); + m_diagram_list = prj->diagrams(); + m_diagram_list.removeOne(diagram); } /** @@ -36,7 +38,7 @@ ElementProvider::ElementProvider(QETProject *prj, Diagram *diagram) * @param diag Diagram to search */ ElementProvider::ElementProvider(Diagram *diag) { - diag_list << diag; + m_diagram_list << diag; } /** @@ -52,7 +54,7 @@ QList ElementProvider::freeElement(const int filter) const{ QList free_elmt; //serch in all diagram - foreach (Diagram *d, diag_list) { + foreach (Diagram *d, m_diagram_list) { //get all element in diagram d QList elmt_list; elmt_list = d->elements(); @@ -72,7 +74,7 @@ QList ElementProvider::freeElement(const int filter) const{ QList ElementProvider::fromUuids(QList uuid_list) const { QList found_element; - foreach (Diagram *d, diag_list) { + foreach (Diagram *d, m_diagram_list) { foreach(Element *elmt, d->elements()) { if (uuid_list.contains(elmt->uuid())) { found_element << elmt; @@ -94,7 +96,7 @@ QList ElementProvider::find(const int filter) const { QList elmt_; //serch in all diagram - foreach (Diagram *d, diag_list) { + foreach (Diagram *d, m_diagram_list) { //get all element in diagram d QList elmt_list; elmt_list = d->elements(); @@ -105,3 +107,52 @@ QList ElementProvider::find(const int filter) const { } return (elmt_); } + +/** + * @brief ElementProvider::table + * @param table + * @param model + * @return All tables wich display the derivated class of @model (if set) and not already in all the chain of next/previous table of @table (if set) + * If table and model are nullptr, return every tables + */ +QVector ElementProvider::table(QetGraphicsTableItem *table, QAbstractItemModel *model) +{ + QVector v_; + QVector linked_vector; + + if (table) + { + auto linked_table = table->previousTable() ? table->previousTable() : table->nextTable(); //table can be inside a chain, at the head of a chain or alone + while (linked_table) { //Go to the first table + if (linked_table->previousTable()) + linked_table = linked_table->previousTable(); + else + break; + } + while (linked_table) { //Store each linked table in linked_vector + linked_vector.append(linked_table); + linked_table = linked_table->nextTable(); + } + } + + for (auto d : m_diagram_list) { + for (auto item_ : d->items()) + { + if(item_->type() == QetGraphicsTableItem::Type) + { + auto found_table = static_cast(item_); + + if (linked_vector.contains(found_table)) { + continue; + } + + if (!model || + (found_table->model() && + model->metaObject()->className() == found_table->model()->metaObject()->className())) + {v_.append(found_table);} + } + } + } + + return v_; +} diff --git a/sources/elementprovider.h b/sources/elementprovider.h index 9bbd51560..983dd3e2f 100644 --- a/sources/elementprovider.h +++ b/sources/elementprovider.h @@ -20,10 +20,12 @@ #include #include +#include class QETProject; class Diagram; class Element; +class QetGraphicsTableItem; /** this class can search in the given diagram or project some kind of element @@ -34,14 +36,15 @@ class Element; class ElementProvider { public: - ElementProvider(QETProject *prj, Diagram *diagram=nullptr); - ElementProvider(Diagram *diag); - QList freeElement(const int filter) const; - QList fromUuids(QList ) const; - QList find(const int filter) const; + ElementProvider(QETProject *prj, Diagram *diagram=nullptr); + ElementProvider(Diagram *diag); + QList freeElement(const int filter) const; + QList fromUuids(QList ) const; + QList find(const int filter) const; + QVector table(QetGraphicsTableItem *table = nullptr, QAbstractItemModel *model = nullptr); private: - QList diag_list; + QList m_diagram_list; }; #endif // ELEMENTPROVIDER_H diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp index c2c26d40a..ba813044e 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.cpp @@ -21,6 +21,8 @@ #include #include +static int no_model_height = 20; +static int no_model_width = 40; /** * @brief QetGraphicsHeaderItem::QetGraphicsHeaderItem * @param parent @@ -47,12 +49,18 @@ void QetGraphicsHeaderItem::setModel(QAbstractItemModel *model) } m_model = model; - connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged); - connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted); - connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted); - setUpMinimumSectionsSize(); - m_current_sections_width.clear(); - m_current_sections_width.resize(m_sections_minimum_width.size()); + if (m_model) + { + connect(m_model, &QAbstractItemModel::headerDataChanged, this, &QetGraphicsHeaderItem::headerDataChanged); + connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsHeaderItem::modelReseted); + connect(m_model, &QAbstractItemModel::columnsInserted, this, &QetGraphicsHeaderItem::modelReseted); + setUpMinimumSectionsSize(); + m_current_sections_width.clear(); + m_current_sections_width.resize(m_sections_minimum_width.size()); + + } else { + setUpMinimumSectionsSize(); + } adjustSize(); } @@ -97,7 +105,6 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI painter->setBrush(brush); painter->setPen(pen); - painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value()); painter->drawRect(m_current_rect); if (!m_model) @@ -105,6 +112,7 @@ void QetGraphicsHeaderItem::paint(QPainter *painter, const QStyleOptionGraphicsI painter->restore(); return; } + painter->setFont(m_model->headerData(0, Qt::Horizontal, Qt::FontRole).value()); //Draw vertical lines auto offset= 0; @@ -145,7 +153,20 @@ QRect QetGraphicsHeaderItem::rect() const { * @param size */ void QetGraphicsHeaderItem::resizeSection(int logicalIndex, int size) -{ +{ + if (!m_model) + { + m_current_sections_width.clear(); + m_current_sections_width.append(no_model_width); + m_sections_minimum_width.clear(); + m_sections_minimum_width.append(no_model_width); + m_current_rect.setWidth(no_model_width); + setUpBoundingRect(); + update(); + emit sectionResized(0, no_model_width); + return; + } + if (logicalIndex >= m_current_sections_width.size() || m_current_sections_width.at(logicalIndex) == size) { return; @@ -195,7 +216,12 @@ void QetGraphicsHeaderItem::setMargins(const QMargins &margins) */ void QetGraphicsHeaderItem::setUpMinimumSectionsSize() { - if (!m_model) { + if (!m_model) + { + m_minimum_section_height = no_model_height; + m_sections_minimum_width.clear(); + m_sections_minimum_width.append(no_model_width); + m_minimum_width = no_model_width; return; } diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h index d3d30fe44..efbe5eaaa 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicsheaderitem.h @@ -46,7 +46,7 @@ class QetGraphicsHeaderItem : public QGraphicsObject enum { Type = UserType + 1301 }; int type() const override { return Type; } - void setModel(QAbstractItemModel *model); + void setModel(QAbstractItemModel *model = nullptr); QAbstractItemModel *model() const; virtual QRectF boundingRect() const override; diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp index 529536df9..dff66e981 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp @@ -26,6 +26,9 @@ #include #include +static int no_model_height = 20; +static int no_model_width = 40; + /** * @brief QetGraphicsTableItem::QetGraphicsTableItem * Default constructor @@ -78,8 +81,11 @@ void QetGraphicsTableItem::setModel(QAbstractItemModel *model) adjustSize(); m_header_item->setPos(0, -m_header_item->rect().height()); - connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged); - connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted); + if (m_model) + { + connect(m_model, &QAbstractItemModel::dataChanged, this, &QetGraphicsTableItem::dataChanged); + connect(m_model, &QAbstractItemModel::modelReset, this, &QetGraphicsTableItem::modelReseted); + } } /** @@ -117,15 +123,25 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt pen.setWidthF(0.7); pen.setColor(Qt::black); painter->setPen(pen); - painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value()); - painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height()); + if (isSelected()) + { + painter->save(); + QColor color(Qt::darkBlue); + color.setAlpha(20); + painter->setBrush(QBrush (color)); + painter->setPen(Qt::NoPen); + painter->drawRect(0,0, m_header_item->rect().width(), m_current_size.height()); + painter->restore(); + } + if(!m_model) { painter->restore(); return; } + painter->setFont(m_model->data(model()->index(0,0), Qt::FontRole).value()); //Draw vertical lines auto offset= 0; @@ -137,9 +153,18 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt offset += m_header_item->sectionSize(i); } + //Calcule the number of rows to display. + auto row_count = m_model->rowCount(); + + if (m_previous_table) //Remove the number of row already displayed by previous tables + row_count -= m_previous_table->displayNRowOffset(); + + if (m_number_of_displayed_row > 0) //User override the number of row to display + row_count = std::min(row_count, m_number_of_displayed_row); + //Draw horizontal lines - auto cell_height = static_cast(m_current_size.height())/static_cast(m_model->rowCount()); - for(auto i= 1 ; i-1rowCount() ; ++i) + auto cell_height = static_cast(m_current_size.height())/static_cast(row_count); + for(auto i= 1 ; i-1rect().left(), cell_height*i); QPointF p2(m_header_item->rect().right(), cell_height*i); @@ -147,7 +172,7 @@ void QetGraphicsTableItem::paint(QPainter *painter, const QStyleOptionGraphicsIt } //Write text of each cell - for (auto i= 0 ; irowCount() ; ++i) + for (auto i=0 ; isectionSize(j) - m_margin.left() - m_margin.right(), static_cast(cell_height) - m_margin.top() - m_margin.bottom()); + auto index_row = m_previous_table ? i + m_previous_table->displayNRowOffset() : i; painter->drawText(QRectF(top_left, size), m_model->data(m_model->index(0,0), Qt::TextAlignmentRole).toInt(), - m_model->index(i, j).data().toString()); + m_model->index(index_row, j).data().toString()); } } @@ -218,10 +244,155 @@ QSize QetGraphicsTableItem::size() const */ QSize QetGraphicsTableItem::minimumSize() const { - QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*m_model->rowCount()); + if (!m_model) { + return QSize(no_model_width, no_model_height); + } + + auto row_count = m_model->rowCount(); + if (m_previous_table) { + row_count -= m_previous_table->displayNRowOffset(); + } + + if (m_number_of_displayed_row > 0) + row_count = std::min(row_count, m_number_of_displayed_row); + + + + QSize s(std::accumulate(m_minimum_column_width.begin(), m_minimum_column_width.end(), 0), m_minimum_row_height*row_count); return s; } +/** + * @brief QetGraphicsTableItem::setDisplayNRow + * Limit the number of row to display + * @param number : set to 0 or less to disabled the limit of row to display + */ +void QetGraphicsTableItem::setDisplayNRow(const int &number) { + m_number_of_displayed_row = number; + setToMinimumHeight(); + if (m_next_table) + m_next_table->previousTableDisplayRowChanged(); +} + +/** + * @brief QetGraphicsTableItem::displayNRow + * @return the number of row displayed. + * A value of 0 or less mean there is no limit + */ +int QetGraphicsTableItem::displayNRow() const { + return m_number_of_displayed_row; +} + +/** + * @brief QetGraphicsTableItem::setPreviousTable + * Set the previous table to @table. + * If this table already have a previous table, the previous table will be replaced. + * Set new table to nullptr to remove an existing previous table. + * The table uses the model of the new previous table. + * Since the table does not take ownership of the model, it is your responsibility to manage the old model. + * Linked tables (table with next and/or previous table) share the same model, a table always take the model of the previous table.. + * When remove a previous table (set to nullptr) from a table, the model is also removed, you need to set a new model + * @param table + */ +void QetGraphicsTableItem::setPreviousTable(QetGraphicsTableItem *table) +{ + if (m_previous_table == table) { + return; + } + + auto old_previous_table = m_previous_table; + m_previous_table = table; + if (m_previous_table) //set previous table and get her model + { + m_previous_table->setNextTable(this); + setModel(m_previous_table->m_model); + } + else //Remove model + { + setModel(nullptr); + } + + if (old_previous_table && + old_previous_table->nextTable() == this) { + old_previous_table->setNextTable(nullptr); + } + + //Set the m_model to every next table + auto next_ = m_next_table; + while (next_) { + next_->setModel(m_model); + next_ = next_->nextTable(); + } +} + +/** + * @brief QetGraphicsTableItem::setNextTable + * Set the next table to @table + * nullptr will remove an existing next table. + * @param table + */ +void QetGraphicsTableItem::setNextTable(QetGraphicsTableItem *table) +{ + if (m_next_table == table) { + return; + } + + auto old_next_table = m_next_table; + + m_next_table = table; + if (m_next_table) { + m_next_table->setPreviousTable(this); + } + + if (old_next_table && + old_next_table->previousTable() == this) { + old_next_table->setPreviousTable(nullptr); + } + +} + +void QetGraphicsTableItem::setTableName(const QString &name) { + m_name = name; +} + +QString QetGraphicsTableItem::tableName() const { + return m_name; +} + +/** + * @brief QetGraphicsTableItem::displayNRowOffset + * @return the offset (aka the last displayed row) of displayed row. + * If this item have a previous table, the previous offset is added. + */ +int QetGraphicsTableItem::displayNRowOffset() const +{ + auto offset_ = m_number_of_displayed_row; + if(m_previous_table) + offset_ += m_previous_table->displayNRowOffset(); + + return offset_; +} + +QetGraphicsTableItem *QetGraphicsTableItem::previousTable() const { + return m_previous_table; +} + +QetGraphicsTableItem *QetGraphicsTableItem::nextTable() const { + return m_next_table; +} + +/** + * @brief QetGraphicsTableItem::setToMinimumHeight + * Set the height to the the minimum. + * The width stay unchanged. + */ +void QetGraphicsTableItem::setToMinimumHeight() +{ + auto size_ = size(); + size_.setHeight(1); + setSize(size_); +} + /** * @brief QetGraphicsTableItem::hoverEnterEvent * Reimplemented from QetGraphicsItem @@ -229,9 +400,12 @@ QSize QetGraphicsTableItem::minimumSize() const */ void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - adjustHandlerPos(); - this->scene()->addItem(&m_handler_item); - m_handler_item.installSceneEventFilter(this); + if (m_model) + { + adjustHandlerPos(); + this->scene()->addItem(&m_handler_item); + m_handler_item.installSceneEventFilter(this); + } QGraphicsObject::hoverEnterEvent(event); } @@ -242,7 +416,9 @@ void QetGraphicsTableItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) */ void QetGraphicsTableItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - m_handler_item.scene()->removeItem(&m_handler_item); + if (m_model) { + m_handler_item.scene()->removeItem(&m_handler_item); + } QGraphicsObject::hoverLeaveEvent(event); } @@ -279,6 +455,7 @@ bool QetGraphicsTableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *even void QetGraphicsTableItem::modelReseted() { dataChanged(m_model->index(0,0), m_model->index(0,0), QVector()); + setToMinimumHeight(); } /** @@ -288,7 +465,10 @@ void QetGraphicsTableItem::modelReseted() { */ void QetGraphicsTableItem::setUpColumnAndRowMinimumSize() { - if (!m_model) { + if (!m_model) + { + m_minimum_row_height = no_model_height; + m_minimum_column_width = m_header_item->minimumSectionWidth(); return; } @@ -340,6 +520,8 @@ void QetGraphicsTableItem::setUpHandler() void QetGraphicsTableItem::handlerMousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event) + diagram()->clearSelection(); + this->setSelected(true); m_old_size = size(); //User start to resize the table, disconnect the signal to avoid double paint. disconnect(m_header_item, &QetGraphicsHeaderItem::sectionResized, this, &QetGraphicsTableItem::headerSectionResized); @@ -380,6 +562,15 @@ void QetGraphicsTableItem::handlerMouseReleaseEvent(QGraphicsSceneMouseEvent *ev */ void QetGraphicsTableItem::adjustColumnsWidth() { + if (!m_model) + { + auto h_ = m_header_item->minimumSectionWidth(); + for (auto i=0 ; iresizeSection(i, h_.at(i)); + } + return; + } + auto a = m_current_size.width() - minimumSize().width(); auto b = a/std::max(1,m_model->columnCount()); //avoid divide by 0 @@ -423,6 +614,12 @@ void QetGraphicsTableItem::headerSectionResized() */ void QetGraphicsTableItem::adjustSize() { + //If there is no model, set the size to minimum + if (!m_model) { + setSize(minimumSize()); + return; + } + if (m_current_size.height() < minimumSize().height()) { prepareGeometryChange(); @@ -440,3 +637,10 @@ void QetGraphicsTableItem::adjustSize() update(); } } + +void QetGraphicsTableItem::previousTableDisplayRowChanged() { + setToMinimumHeight(); + if (m_next_table) { + m_next_table->previousTableDisplayRowChanged(); + } +} diff --git a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h index 7ce417a37..95f3219f0 100644 --- a/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h +++ b/sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2020 QElectroTech Team This file is part of QElectroTech. @@ -44,6 +44,7 @@ class QetGraphicsTableItem : public QetGraphicsItem Q_PROPERTY(QMargins margins READ margins WRITE setMargins) Q_PROPERTY(QSize size READ size WRITE setSize) + Q_PROPERTY(int displayNRow READ displayNRow WRITE setDisplayNRow) public: QetGraphicsTableItem(QGraphicsItem *parent= nullptr); @@ -52,7 +53,7 @@ class QetGraphicsTableItem : public QetGraphicsItem enum { Type = UserType + 1300 }; int type() const override { return Type; } - void setModel(QAbstractItemModel *model); + void setModel(QAbstractItemModel *model = nullptr); QAbstractItemModel *model() const; virtual QRectF boundingRect() const override; @@ -63,6 +64,16 @@ class QetGraphicsTableItem : public QetGraphicsItem void setSize(const QSize &size); QSize size() const; QSize minimumSize() const; + void setDisplayNRow(const int &number); + int displayNRow() const; + void setPreviousTable(QetGraphicsTableItem *table = nullptr); + void setNextTable(QetGraphicsTableItem *table = nullptr); + void setTableName(const QString &name); + QString tableName() const; + int displayNRowOffset() const; + QetGraphicsTableItem *previousTable() const; + QetGraphicsTableItem *nextTable() const; + void setToMinimumHeight(); protected: virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; @@ -82,6 +93,7 @@ class QetGraphicsTableItem : public QetGraphicsItem void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); void headerSectionResized(); void adjustSize(); + void previousTableDisplayRowChanged(); private: QAbstractItemModel *m_model= nullptr; @@ -89,6 +101,7 @@ class QetGraphicsTableItem : public QetGraphicsItem QMargins m_margin; QVector m_minimum_column_width; int m_minimum_row_height; + int m_number_of_displayed_row = 0; QSize m_current_size, m_old_size; @@ -97,6 +110,11 @@ class QetGraphicsTableItem : public QetGraphicsItem QetGraphicsHandlerItem m_handler_item; QetGraphicsHeaderItem *m_header_item = nullptr; + + QetGraphicsTableItem *m_previous_table = nullptr, + *m_next_table = nullptr; + + QString m_name; }; #endif // QetGraphicsTableItem_H diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp index b1b3bbcf0..55d9bb1bd 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.cpp @@ -23,6 +23,7 @@ #include "QPropertyUndoCommand/qpropertyundocommand.h" #include "itemmodelcommand.h" #include "propertieseditorfactory.h" +#include "elementprovider.h" #include #include @@ -74,6 +75,7 @@ void GraphicsTablePropertiesEditor::setTable(QetGraphicsTableItem *table) { ui->m_content_layout->removeWidget(m_current_model_editor); m_current_model_editor->deleteLater(); + m_current_model_editor = nullptr; } } @@ -129,6 +131,12 @@ QUndoCommand *GraphicsTablePropertiesEditor::associatedUndo() const return undo; } + if (ui->m_display_n_row_sb->value() != m_table_item->displayNRow()) { + auto undo = new QPropertyUndoCommand(m_table_item.data(), "displayNRow", m_table_item->displayNRow(), ui->m_display_n_row_sb->value()); + undo->setText(tr("Modifier le nombre de ligne affiché par un tableau")); + return undo; + } + QMargins header_margins(ui->m_header_left_margin->value(), ui->m_header_top_margin->value(), ui->m_header_right_margin->value(), @@ -241,8 +249,33 @@ void GraphicsTablePropertiesEditor::updateUi() } m_edit_connection.clear(); + ui->m_table_name_le->setText(m_table_item->tableName()); ui->m_x_pos->setValue(m_table_item->pos().x()); ui->m_y_pos->setValue(m_table_item->pos().y()); + ui->m_display_n_row_sb->setValue(m_table_item->displayNRow()); + + ui->m_previous_table_cb->clear(); + m_other_table_vector.clear(); + + ui->m_previous_table_cb->addItem(tr("Aucun")); //Add no previous table + + if (auto item_ = m_table_item->previousTable()) //Add the current previous table + { + m_other_table_vector.append(item_); + ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_)); + ui->m_previous_table_cb->setCurrentIndex(ui->m_previous_table_cb->findData(m_other_table_vector.indexOf(item_))); + } + + ElementProvider ep(m_table_item->diagram()->project()); + for (auto item_ : ep.table(m_table_item, m_table_item->model())) //Add available tables + { + if (item_ != m_table_item && + item_->nextTable() == nullptr) + { + m_other_table_vector.append(item_); + ui->m_previous_table_cb->addItem(item_->tableName(), m_other_table_vector.indexOf(item_)); + } + } auto margin = m_table_item->headerItem()->margins(); ui->m_header_top_margin ->setValue(margin.top()); @@ -294,5 +327,19 @@ void GraphicsTablePropertiesEditor::setUpEditConnection() m_edit_connection << connect(ui->m_table_bottom_margin, QOverload::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply); m_edit_connection << connect(m_table_button_group, QOverload::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply); m_edit_connection << connect(m_header_button_group, QOverload::of(&QButtonGroup::buttonClicked), this, &GraphicsTablePropertiesEditor::apply); + m_edit_connection << connect(ui->m_display_n_row_sb, QOverload::of(&QSpinBox::valueChanged), this, &GraphicsTablePropertiesEditor::apply); + } +} + +void GraphicsTablePropertiesEditor::on_m_table_name_le_textEdited(const QString &arg1) { + m_table_item->setTableName(arg1); +} + +void GraphicsTablePropertiesEditor::on_m_previous_table_cb_activated(int index) +{ + if (index == 0) { + m_table_item->setPreviousTable(); + } else { + m_table_item->setPreviousTable(m_other_table_vector.at(ui->m_previous_table_cb->currentData().toInt())); } } diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h index b69f6c4b6..dba91b6e4 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2020 The QElectroTech Team This file is part of QElectroTech. @@ -51,8 +51,10 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget void on_m_header_font_pb_clicked(); void on_m_table_font_pb_clicked(); virtual void updateUi() override; + void on_m_table_name_le_textEdited(const QString &arg1); + void on_m_previous_table_cb_activated(int index); - private: + private: void setUpEditConnection(); private: @@ -63,6 +65,7 @@ class GraphicsTablePropertiesEditor : public PropertiesEditorWidget QButtonGroup *m_header_button_group = nullptr, *m_table_button_group = nullptr; QWidget *m_current_model_editor = nullptr; + QVector m_other_table_vector; }; Q_DECLARE_METATYPE(QMargins) diff --git a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui index e13308c32..0f6ebc268 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui +++ b/sources/qetgraphicsitem/ViewItem/ui/graphicstablepropertieseditor.ui @@ -6,8 +6,8 @@ 0 0 - 353 - 534 + 467 + 672 @@ -24,30 +24,55 @@ Affichage + + + + + + + Nom du tableau + + + - Position + Position et lignes - - - + + + + + QComboBox::InsertAtBottom + + + + Aucun + + + + + + + + Toutes + + + 999 + + + + + - X : + Lignes à afficher : Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - 10000 - - - - + Y : @@ -57,13 +82,124 @@ - + + + + false + + + Tableau suivant + + + + + + + :/ico/16x16/arrow-right.png:/ico/16x16/arrow-right.png + + + true + + + + + + + X : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Tableau précédent + + + + + + + :/ico/16x16/arrow-left.png:/ico/16x16/arrow-left.png + + + true + + + + + + + 10000 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 10000 + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Tableau précédent : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -75,16 +211,33 @@ - - - - - - - - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + Marge @@ -94,9 +247,25 @@ - + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -114,6 +283,19 @@ 0 + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -142,6 +324,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -150,6 +345,9 @@ Police + + false + @@ -163,19 +361,32 @@ - - - - - - - + - + - + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Marge @@ -185,6 +396,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -202,6 +426,19 @@ 0 + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -230,6 +467,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -238,6 +488,9 @@ Police + + false + @@ -282,6 +535,8 @@ - + + + diff --git a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp index 4c9ea6cee..de43b747a 100644 --- a/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp +++ b/sources/qetgraphicsitem/ViewItem/ui/nomenclaturemodelpropertieswidget.cpp @@ -33,9 +33,7 @@ NomenclatureModelPropertiesWidget::NomenclatureModelPropertiesWidget(Nomenclatur ui(new Ui::NomenclatureModelPropertiesWidget) { ui->setupUi(this); - if (model) { - setModel(model); - } + setModel(model); } /** @@ -51,6 +49,8 @@ NomenclatureModelPropertiesWidget::~NomenclatureModelPropertiesWidget() { */ void NomenclatureModelPropertiesWidget::setModel(NomenclatureModel *model) { m_model = model; + ui->m_edit_query_pb->setEnabled(m_model); + ui->m_refresh_pb->setEnabled(m_model); } /**