Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces 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 1 and Inria Bordeaux - Sud Ouest
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 <string>
25 #include <vector>
26 
27 #include <tulip/tulipconf.h>
28 #include <tulip/Iterator.h>
29 
30 #include <QtCore/QString>
31 #include <QtGui/QDialog>
32 #include <QtGui/QWidget>
33 
34 #ifdef _WIN32
35 // compilation pb workaround
36 #include <windows.h>
37 #endif
38 
39 
40 
41 namespace Ui {
42 class CopyPropertyDialogData;
43 }
44 
45 namespace tlp {
46 class Graph;
47 class PropertyInterface;
48 
49 /**
50  * @brief Provide a dialog that allow user to copy a property in an existing property or in a new one.
51  *
52  * The easiest way to use this class is to use the copyProperty static function.
53  * @code
54  * Graph* g;
55  * PropertyInterface* source = g->getLocalProperty<BooleanProperty>("viewSelection");
56  * QWidget* parent;
57  * PropertyInterface* clonedProperty = PropertyCreationDialog::createNewProperty(g,souce,parent);
58  * @endcode
59  *
60  *
61  **/
62 
63 class TLP_QT_SCOPE CopyPropertyDialog : public QDialog {
64  Q_OBJECT
65 public:
66  CopyPropertyDialog(QWidget *parent = NULL);
67  ~CopyPropertyDialog();
68 
69  /**
70  * @brief Init dialog with required parameters. To make the copy this dialog need to have a valid source property and destination graph.
71  **/
72  void init(tlp::Graph* graph,tlp::PropertyInterface* toCopy);
73 
74  /**
75  * @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.
76  *
77  * 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.
78  **/
79  tlp::PropertyInterface* copyProperty(QString& errorMsg);
80 
81  /**
82  * @brief Get the name of the destintation property.
83  **/
84  QString destinationPropertyName()const;
85 
86  enum PropertyScope {
87  NEW,
88  LOCAL,
89  INHERITED
90  };
91 
92  /**
93  * @brief Return the scope where the new property will be created.
94  **/
95  PropertyScope destinationPropertyScope()const;
96 
97  /**
98  * @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.
99  *
100  * The function creates a modal property copy dialog with the given source property, graph and parent widget.
101  *
102  * @param graph The graph to use as parent for the properties to create.
103  * @param source The property to copy.
104  * @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.
105  **/
106  static PropertyInterface* copyProperty(tlp::Graph* graph,tlp::PropertyInterface* source,bool askBeforePropertyOverwriting=false,QWidget* parent=NULL);
107 
108 private:
109  Ui::CopyPropertyDialogData *ui;
110  tlp::Graph* _graph;
111  tlp::PropertyInterface* _source;
112 
113 private slots:
114  void checkValidity();
115 };
116 }
117 #endif // COPYPROPERTYDIALOG_H
118 ///@endcond