Tulip  4.8.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
CopyPropertyDialog.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 COPYPROPERTYDIALOG_H
22 #define COPYPROPERTYDIALOG_H
23 
24 #include <tulip/tulipconf.h>
25 
26 #include <QDialog>
27 
28 namespace Ui {
29 class CopyPropertyDialogData;
30 }
31 
32 namespace tlp {
33 class Graph;
34 class PropertyInterface;
35 
36 /**
37  * @brief Provide a dialog that allow user to copy a property in an existing property or in a new one.
38  *
39  * The easiest way to use this class is to use the copyProperty static function.
40  * @code
41  * Graph* g;
42  * PropertyInterface* source = g->getLocalProperty<BooleanProperty>("viewSelection");
43  * PropertyInterface* clonedProperty = CopyPropertyDialog::copyProperty(g, source);
44  * @endcode
45  *
46  *
47  **/
48 
49 class TLP_QT_SCOPE CopyPropertyDialog : public QDialog {
50  Q_OBJECT
51 public:
52  CopyPropertyDialog(QWidget *parent = NULL);
53  ~CopyPropertyDialog();
54 
55  /**
56  * @brief Init dialog with required parameters. To make the copy this dialog need to have a valid source property and destination graph.
57  **/
58  void init(tlp::Graph* graph,tlp::PropertyInterface* toCopy);
59 
60  /**
61  * @brief Perform the copy of the property in function of the parameters given by user. If parameters are invalid return a null pointer and fill the errorMsg with the description of the error.
62  *
63  * This function don't hold observers during the copy process. It's up to user to call Observable::holdObserver and Observable::unholdObserver before and after calling this funtion.
64  **/
65  tlp::PropertyInterface* copyProperty(QString& errorMsg);
66 
67  /**
68  * @brief Get the name of the destintation property.
69  **/
70  QString destinationPropertyName()const;
71 
72  enum PropertyScope {
73  NEW,
74  LOCAL,
75  INHERITED
76  };
77 
78  /**
79  * @brief Return the scope where the new property will be created.
80  **/
81  PropertyScope destinationPropertyScope()const;
82 
83  /**
84  * @brief This is a convenience static function that copy property in function of user parameters. If the user presses Cancel or an error occur, it returns a null pointer.
85  *
86  * The function creates a modal property copy dialog with the given source property, graph and parent widget.
87  *
88  * @param graph The graph to use as parent for the properties to create.
89  * @param source The property to copy.
90  * @param askBeforePropertyOverwriting If set to true and user try to create a new property with the same name than another existing ask user before overwriting them.
91  **/
92  static PropertyInterface* copyProperty(tlp::Graph* graph,tlp::PropertyInterface* source,bool askBeforePropertyOverwriting=false,QWidget* parent=NULL);
93 
94 private:
95  Ui::CopyPropertyDialogData *ui;
96  tlp::Graph* _graph;
97  tlp::PropertyInterface* _source;
98 
99 private slots:
100  void checkValidity();
101 };
102 }
103 #endif // COPYPROPERTYDIALOG_H
104 ///@endcond
PropertyInterface describes the interface of a graph property.