QElectroTech  0.70
propertieseditordialog.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 
37 class PropertiesEditorDialog : public QDialog
38 {
39  Q_OBJECT
40  public:
41  template<typename T>
42  PropertiesEditorDialog(T editor, QWidget *parent = nullptr) :
43  QDialog (parent)
44  {
45  //Set dialog title
46  setWindowTitle(editor->title());
47  //Reparent the editor, to be deleted at the same time of this dialog
48  editor->setParent(this);
49 
50  //Build the dialog
51  QVBoxLayout *vlayout = new QVBoxLayout(this);
52  vlayout->addWidget(editor);
53  QDialogButtonBox *button_box = new QDialogButtonBox (QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset, this);
54  vlayout->addWidget(button_box);
55 
56  //Setup connection between button box and the editor
57  connect(button_box, &QDialogButtonBox::clicked, [editor, button_box, this](QAbstractButton *button)
58  {
59  switch(button_box->buttonRole(button))
60  {
61  case QDialogButtonBox::RejectRole:
62  editor->reset();
63  this->reject();
64  break;
65  case QDialogButtonBox::ResetRole:
66  editor->reset();
67  break;
68  case QDialogButtonBox::ApplyRole:
69  editor->apply();
70  this->accept();
71  break;
72  default:
73  editor->reset();
74  this->reject();
75  }
76  });
77  }
78 };
79 
80 #endif // PROPERTIESEDITORDIALOG_H
The PropertiesEditorDialog class Create a dialog to edit some properties of a thing. Only create a instance of this class and call exec, all is done for you in this class. The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow : QString::title() void::apply() void::reset() You can subclass the interface PropertiesEditorWidget who provide all this methods. This dialog take ownership of the editor, so the editor will be deleted by this dialog.
PropertiesEditorDialog(T editor, QWidget *parent=nullptr)
QIcon Cancel
Definition: qeticons.cpp:34