mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 23:04:13 +02:00
a28e834185
QETElementEditor, QETDiagramEditor and QETTemplateEditor already persist their geometry via QSettings; none of the modal QDialog subclasses did, so any dialog resized to see more of its content (Search and Replace, Diagram properties, Export, ...) is back to its default size the next time it's opened. Adds QET::trackDialogGeometry(), one call at the end of each dialog constructor (after any default resize()), following the same restoreGeometry()/saveGeometry() pattern as the three editors above, stored under [dialoggeometry] and keyed by class name by default. An explicit key is used for PropertiesEditorDialog, a single class templated over several unrelated wrapped editors, so they don't all fight over one saved size. Covers the 36 dialogs of the original change (#691) plus seven added since: RenumberElementsDialog, MaterialEntryDialog, AiAssistantDialog, DuplicateOffsetDialog, ImageTransparentColorDialog, PdfPagesDialog and WiringListDialog. Deliberately not touched: BackupDialog and ImageCropDialog, which setFixedSize() themselves, and MaterialSelectionDialog, which already restores its own size. A size saved while the dialog sat partly off-screen is restored on screen: restoreGeometry() moves it back inside the available screen (checked: saved at 1502,972 on a 1600x1000 screen, reopened at 600,317). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
148 lines
4.1 KiB
C++
148 lines
4.1 KiB
C++
/*
|
|
Copyright 2006-2026 The QElectroTech Team
|
|
This file is part of QElectroTech.
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include "materialentrydialog.h"
|
|
#include "../qet.h"
|
|
|
|
#include "../qetmessagebox.h"
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QScrollArea>
|
|
#include <QVBoxLayout>
|
|
|
|
/**
|
|
@brief MaterialEntryDialog::MaterialEntryDialog
|
|
Build one field per column of the material file.
|
|
@param columns the columns of the file, in file order
|
|
@param parent parent widget
|
|
*/
|
|
MaterialEntryDialog::MaterialEntryDialog(const QStringList &columns, QWidget *parent) :
|
|
QDialog(parent),
|
|
m_columns(columns)
|
|
{
|
|
setWindowTitle(tr("Nouvelle entrée"));
|
|
|
|
//Two fields per row : the form shows the whole article at once
|
|
//instead of stacking twenty lines in a narrow column.
|
|
setMinimumSize(780, 560);
|
|
resize(1120, 800);
|
|
|
|
auto *main_layout = new QVBoxLayout(this);
|
|
|
|
auto *intro = new QLabel(
|
|
tr("Renseignez l'article à ajouter. Les champs laissés vides "
|
|
"restent vides dans le fichier."), this);
|
|
intro->setWordWrap(true);
|
|
main_layout->addWidget(intro);
|
|
|
|
auto *scroll_area = new QScrollArea(this);
|
|
scroll_area->setWidgetResizable(true);
|
|
scroll_area->setFrameShape(QFrame::NoFrame);
|
|
|
|
auto *container = new QWidget(scroll_area);
|
|
auto *grid = new QGridLayout(container);
|
|
|
|
for (int i = 0; i < m_columns.size(); ++i)
|
|
{
|
|
const QString column = m_columns.at(i);
|
|
|
|
auto *label = new QLabel(MaterialList::translatedColumn(column) + QLatin1Char(' '), container);
|
|
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
auto *edit = new QLineEdit(container);
|
|
edit->setClearButtonEnabled(true);
|
|
|
|
label->setBuddy(edit);
|
|
const int row = i / 2;
|
|
const int pair = i % 2;
|
|
grid->addWidget(label, row, pair * 2);
|
|
grid->addWidget(edit, row, pair * 2 + 1);
|
|
m_edits.append(edit);
|
|
}
|
|
grid->setColumnStretch(1, 1);
|
|
grid->setColumnStretch(3, 1);
|
|
|
|
scroll_area->setWidget(container);
|
|
main_layout->addWidget(scroll_area, 1);
|
|
|
|
auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
|
buttons->button(QDialogButtonBox::Ok)->setText(tr("Enregistrer"));
|
|
buttons->button(QDialogButtonBox::Cancel)->setText(tr("Annuler"));
|
|
connect(buttons, &QDialogButtonBox::accepted, this, &MaterialEntryDialog::accept);
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &MaterialEntryDialog::reject);
|
|
main_layout->addWidget(buttons);
|
|
|
|
if (!m_edits.isEmpty()) {
|
|
m_edits.first()->setFocus();
|
|
}
|
|
|
|
QET::trackDialogGeometry(this);
|
|
}
|
|
|
|
/**
|
|
@brief MaterialEntryDialog::~MaterialEntryDialog
|
|
Destructor
|
|
*/
|
|
MaterialEntryDialog::~MaterialEntryDialog() = default;
|
|
|
|
/**
|
|
@brief MaterialEntryDialog::record
|
|
@return the article described by the form. Empty fields are left out :
|
|
an empty column never means anything for an article which is being
|
|
created.
|
|
*/
|
|
MaterialRecord MaterialEntryDialog::record() const
|
|
{
|
|
MaterialRecord record;
|
|
|
|
for (int i = 0; i < m_columns.size() && i < m_edits.size(); ++i)
|
|
{
|
|
QString value = m_edits.at(i)->text();
|
|
value.remove(QLatin1Char('\r'));
|
|
value.remove(QLatin1Char('\n'));
|
|
value = value.trimmed();
|
|
if (!value.isEmpty()) {
|
|
record.setValue(m_columns.at(i), value);
|
|
}
|
|
}
|
|
|
|
return record;
|
|
}
|
|
|
|
/**
|
|
@brief MaterialEntryDialog::accept
|
|
Refuse an empty form: an article without any information is not worth
|
|
a line in the file.
|
|
*/
|
|
void MaterialEntryDialog::accept()
|
|
{
|
|
if (record().values.isEmpty())
|
|
{
|
|
QET::QetMessageBox::warning(this,
|
|
tr("Aucun renseignement"),
|
|
tr("Saisissez au moins un renseignement "
|
|
"pour créer une entrée."));
|
|
return;
|
|
}
|
|
|
|
QDialog::accept();
|
|
}
|