Merge pull request #1001 from Kellermorph/plc-table-size

Plc table size
This commit is contained in:
Laurent Trinques
2026-09-23 18:24:15 +02:00
committed by GitHub
2 changed files with 46 additions and 1 deletions
+17
View File
@@ -39,7 +39,9 @@
#include "elementtextitemgroup.h"
#include "iostream"
#include <QApplication>
#include <QCollator>
#include <QScreen>
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();
}
}
+29 -1
View File
@@ -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);