graphics table properties editor : Add two buttons new button

Add new two new buttons :
1. Adjust the selected table to fit as well into folio.
2. Set current geometry to all linked tables : Apply the geometry (pos,
height, width, row to display) of the selected table to all linked
tables.
This commit is contained in:
Claveau Joshua
2020-06-11 10:41:01 +02:00
parent 516435554a
commit 7e9fd8df98
7 changed files with 235 additions and 148 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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<QetGraphicsTableItem*> 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);
}

View File

@@ -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:

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>672</height>
<width>524</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
@@ -37,10 +37,31 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Position et lignes</string>
<string>Géometrie et lignes</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="4" colspan="2">
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0,0,0,0,0,0">
<item row="0" column="6">
<widget class="QPushButton" name="m_apply_geometry_to_linked_table_pb">
<property name="toolTip">
<string>Appliquer la géometrie à tous les tableaux liée à celui-ci</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/22x22/all_pages.png</normaloff>:/ico/22x22/all_pages.png</iconset>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QComboBox" name="m_previous_table_cb">
<property name="insertPolicy">
<enum>QComboBox::InsertAtBottom</enum>
@@ -52,37 +73,7 @@
</item>
</widget>
</item>
<item row="0" column="6" colspan="2">
<widget class="QSpinBox" name="m_display_n_row_sb">
<property name="specialValueText">
<string>Toutes</string>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="label">
<property name="text">
<string>Lignes à afficher :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="7">
<item row="1" column="6">
<widget class="QPushButton" name="m_next_pb">
<property name="enabled">
<bool>true</bool>
@@ -102,13 +93,10 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<item row="0" column="2">
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
@@ -125,7 +113,92 @@
</property>
</spacer>
</item>
<item row="1" column="6">
<item row="1" column="7">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="5">
<widget class="QPushButton" name="m_auto_geometry_pb">
<property name="toolTip">
<string>Ajuster le tableau au folio</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../../qelectrotech.qrc">
<normaloff>:/ico/22x22/zoom-fit-best.png</normaloff>:/ico/22x22/zoom-fit-best.png</iconset>
</property>
</widget>
</item>
<item row="2" column="1" colspan="6">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Lignes à afficher :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QSpinBox" name="m_display_n_row_sb">
<property name="specialValueText">
<string>Toutes</string>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tableau précédent :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QPushButton" name="m_previous_pb">
<property name="enabled">
<bool>true</bool>
@@ -145,55 +218,10 @@
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="m_x_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="2" column="1" colspan="7">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
<item row="0" column="4">
<widget class="QSpinBox" name="m_y_pos">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="0" column="8">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" colspan="2">
<widget class="QLabel" name="label_3">
<item row="1" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Tableau précédent :</string>
<string>Y :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -211,6 +239,9 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="2">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="2" column="4">
<spacer name="horizontalSpacer_4">
<property name="orientation">
@@ -224,6 +255,32 @@
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_header_left_margin">
<property name="suffix">
@@ -237,35 +294,6 @@
<item row="1" column="2">
<widget class="QSpinBox" name="m_header_top_margin"/>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Marge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="m_header_right_margin"/>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="m_header_bottom_margin"/>
</item>
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>