diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index a42f5ee64..f0d09639d 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -39,7 +39,9 @@ #include "elementtextitemgroup.h" #include "iostream" +#include #include +#include static const QString plcTerminalKeys[] = { QETInformation::ELMT_PLC_T1, @@ -209,6 +211,21 @@ void Element::editProperty() //with the "text" tab of ElementPropertiesWidget, //the ui freeze, until user press escape key dialog.setWindowModality(Qt::WindowModal); + + // A PLC master carries a 6-column IO table: without an explicit + // size the dialog falls back to its (cramped) sizeHint, so open it + // at three times its natural width instead. The height stays at + // the natural one, and the width never exceeds the screen. + const ElementData data = elementData(); + if (data.m_type == ElementData::Master + && data.m_master_type == ElementData::PLC) { + const QSize natural = dialog.sizeHint(); + int width = natural.width() * 3; + if (QScreen *screen = QApplication::primaryScreen()) + width = qMin(width, screen->availableGeometry().width()); + dialog.resize(width, natural.height()); + } + dialog.exec(); } } diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp index 339938d06..94d56e145 100644 --- a/sources/ui/masterpropertieswidget.cpp +++ b/sources/ui/masterpropertieswidget.cpp @@ -539,7 +539,35 @@ void MasterPropertiesWidget::updateUi() tr("Type"), tr("Adresse"), tr("Fonction"), tr("Commentaire"), tr("Réf. croisée"), tr("Bornes") }); - m_plc_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + m_plc_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + m_plc_table->horizontalHeader()->setSectionsMovable(true); + m_plc_table->horizontalHeader()->resizeSection(0, 120); + m_plc_table->horizontalHeader()->resizeSection(1, 100); + m_plc_table->horizontalHeader()->resizeSection(2, 150); + m_plc_table->horizontalHeader()->resizeSection(3, 150); + m_plc_table->horizontalHeader()->resizeSection(4, 100); + m_plc_table->horizontalHeader()->resizeSection(5, 120); + + // Restore a previously saved column layout, if any + auto *plc_hdr = m_plc_table->horizontalHeader(); + QSettings plc_settings; + const QVariant plc_hdr_state = plc_settings.value( + QStringLiteral("masterpropertieswidget/plc-table-header-state")); + if (!plc_hdr_state.isNull()) + plc_hdr->restoreState(plc_hdr_state.toByteArray()); + + // Persist the column layout whenever the user resizes or moves a column + auto save_plc_header_state = [plc_hdr]() + { + QSettings settings; + settings.setValue(QStringLiteral("masterpropertieswidget/plc-table-header-state"), + plc_hdr->saveState()); + }; + connect(plc_hdr, &QHeaderView::sectionResized, + this, save_plc_header_state); + connect(plc_hdr, &QHeaderView::sectionMoved, + this, save_plc_header_state); + m_plc_table->setSelectionBehavior(QAbstractItemView::SelectItems); m_plc_table->setSelectionMode(QAbstractItemView::ExtendedSelection); m_plc_table->setMinimumHeight(200);