QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
propertieseditordialog.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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 //Set dialog title
50 setWindowTitle(editor->title());
51 // Reparent the editor,
52 // to be deleted at the same time of this dialog
53 editor->setParent(this);
54
55 //Build the dialog
56 QVBoxLayout *vlayout = new QVBoxLayout(this);
57 vlayout->addWidget(editor);
58 QDialogButtonBox *button_box = new QDialogButtonBox (
59 QDialogButtonBox::Apply
60 | QDialogButtonBox::Cancel
61 | QDialogButtonBox::Reset,
62 this);
63 vlayout->addWidget(button_box);
64
65 //Setup connection between button box and the editor
66 connect(button_box,
67 &QDialogButtonBox::clicked,
68 [editor, button_box, this]
69 (QAbstractButton *button)
70 {
71 switch(button_box->buttonRole(button))
72 {
73 case QDialogButtonBox::RejectRole:
74 editor->reset();
75 this->reject();
76 break;
77 case QDialogButtonBox::ResetRole:
78 editor->reset();
79 break;
80 case QDialogButtonBox::ApplyRole:
81 editor->apply();
82 this->accept();
83 break;
84 default:
85 editor->reset();
86 this->reject();
87 }
88 });
89 }
90};
91
92#endif // PROPERTIESEDITORDIALOG_H
The PropertiesEditorDialog class Create a dialog to edit some properties of a thing....
Definition propertieseditordialog.h:42
PropertiesEditorDialog(T editor, QWidget *parent=nullptr)
Definition propertieseditordialog.h:46