Tulip  5.3.0
Large graphs analysis and drawing
PropertyCreationDialog.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef PROPERTYCREATIONDIALOG_H
22 #define PROPERTYCREATIONDIALOG_H
23 
24 #include <QDialog>
25 
26 #include <tulip/tulipconf.h>
27 
28 namespace Ui {
29 class PropertyCreationDialog;
30 }
31 
32 namespace tlp {
33 
34 class PropertyInterface;
35 class Graph;
36 
37 /**
38  * @brief Provide a dialog that allow user to create a new property.
39  *
40  * The easiest way to use this class is to use the static function.
41  * @code
42  * Graph* g;
43  * QWidget* parent;
44  * PropertyCreationDialog::createNewProperty(g,parent);
45  * @endcode
46  *
47  *
48  **/
49 class TLP_QT_SCOPE PropertyCreationDialog : public QDialog {
50  Q_OBJECT
51 
52 public:
53  /**
54  * @brief Constructs a property creation dialog with the given parent.
55  **/
56  explicit PropertyCreationDialog(QWidget *parent = nullptr);
57  /**
58  * @brief Constructs a property creation dialog with the given parent graph and parent widget.
59  **/
60  explicit PropertyCreationDialog(tlp::Graph *graph, QWidget *parent = nullptr,
61  const std::string &selectedType = "");
62  ~PropertyCreationDialog() override;
63 
64  /**
65  * @brief Try to create a new property from the givent parameters.
66  * To get the created property use the createdProperty() function.
67  **/
68  void accept() override;
69 
70  /**
71  * @brief Change the graph to use as parent for the properties to create.
72  **/
73  void setGraph(tlp::Graph *graph);
74 
75  tlp::Graph *getGraph() const {
76  return _graph;
77  }
78 
79  /**
80  * @brief Return the property created. You need to call this function after the accept()
81  *function.
82  *
83  * @return The last created property or nullptr if no property there is an error during the
84  *property
85  *creation.
86  **/
87  tlp::PropertyInterface *createdProperty() const {
88  return _createdProperty;
89  }
90 
91  /**
92  * @brief This is a convenience static function that create a new property using user parameters.
93  *If the user presses Cancel or an error occur, it returns a null pointer.
94  *
95  * The function creates a modal property creation dialog with the given graph and parent widget.
96  *
97  * @param graph The graph to use as parent for the properties to create.
98  **/
99  static PropertyInterface *createNewProperty(tlp::Graph *graph, QWidget *parent = nullptr,
100  const std::string &selectedType = "");
101 private slots:
102  void checkValidity();
103 
104 private:
105  void initGui();
106 
107  Ui::PropertyCreationDialog *ui;
108  QPushButton *_createPropertyButton;
109  Graph *_graph;
110  PropertyInterface *_createdProperty;
111 };
112 } // namespace tlp
113 
114 #endif // PROPERTYCREATIONDIALOG_H
115 ///@endcond
PropertyInterface describes the interface of a graph property.