QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
propertieseditordialog.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef PROPERTIESEDITORDIALOG_H
19#define PROPERTIESEDITORDIALOG_H
20
21#include <QDialog>
22#include <QDialogButtonBox>
23#include <QVBoxLayout>
24#include <QAbstractButton>
25
41class PropertiesEditorDialog : public QDialog
42{
43 Q_OBJECT
44 public:
45 template<typename T>
46 PropertiesEditorDialog(T editor, QWidget *parent = nullptr) :
47 QDialog (parent)
48 {
49 // Without this, a QWidget-modal QDialog with a parent falls
50 // back to macOS's automatic sheet presentation, which some
51 // Qt/Cocoa versions render stuck centered on screen and
52 // non-draggable rather than as a proper attached sheet
53 // (bugtracker #275). Other dialogs in this codebase already
54 // opt in explicitly (see ElementDialog, DiagramPropertiesDialog)
55 // -- this one was missing it.
56 setWindowModality(Qt::WindowModal);
57#ifdef Q_OS_MACOS
58 setWindowFlags(Qt::Sheet);
59#endif
60
61 //Set dialog title
62 setWindowTitle(editor->title());
63 // Reparent the editor,
64 // to be deleted at the same time of this dialog
65 editor->setParent(this);
66
67 //Build the dialog
68 QVBoxLayout *vlayout = new QVBoxLayout(this);
69 vlayout->addWidget(editor);
70 QDialogButtonBox *button_box = new QDialogButtonBox (
71 QDialogButtonBox::Apply
72 | QDialogButtonBox::Cancel
73 | QDialogButtonBox::Reset,
74 this);
75 vlayout->addWidget(button_box);
76
77 //Setup connection between button box and the editor
78 connect(button_box,
79 &QDialogButtonBox::clicked,
80 [editor, button_box, this]
81 (QAbstractButton *button)
82 {
83 switch(button_box->buttonRole(button))
84 {
85 case QDialogButtonBox::RejectRole:
86 editor->reset();
87 this->reject();
88 break;
89 case QDialogButtonBox::ResetRole:
90 editor->reset();
91 break;
92 case QDialogButtonBox::ApplyRole:
93 editor->apply();
94 this->accept();
95 break;
96 default:
97 editor->reset();
98 this->reject();
99 }
100 });
101 }
102};
103
104#endif // PROPERTIESEDITORDIALOG_H
PropertiesEditorDialog(T editor, QWidget *parent=nullptr)
Definition propertieseditordialog.h:46