SymbolSelectorDialog.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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 Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/se/SymbolSelectorDialog.h
22 
23  \brief A dialog used to select a specific symbol.
24 */
25 
26 #ifndef __TERRALIB_QT_WIDGETS_SE_INTERNAL_SYMBOLSELECTORDIALOG_H
27 #define __TERRALIB_QT_WIDGETS_SE_INTERNAL_SYMBOLSELECTORDIALOG_H
28 
29 // TerraLib
30 #include "../Config.h"
31 
32 // Qt
33 #include <QDialog>
34 #include <QStringListIterator>
35 
36 // STL
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
41 // Forward declaraion
42 class QTreeWidgetItem;
43 class QTreeWidget;
44 class QString;
45 
46 namespace Ui
47 {
48  class SymbolSelectorDialogForm;
49 }
50 
51 namespace te
52 {
53  // Forward declarations
54  namespace se
55  {
56  class Rule;
57  }
58  namespace qt
59  {
60  namespace widgets
61  {
62  // Forward declarations
63  class Symbol;
64  struct SymbolInfo;
65  class SymbolPreviewWidget;
66  class SymbolNode;
67 
68  /*!
69  \class SymbolSelectorDialog
70 
71  \brief A dialog used to select a specific symbol.
72  */
73  class TEQTWIDGETSEXPORT SymbolSelectorDialog : public QDialog
74  {
75  Q_OBJECT
76 
77  private:
78 
79  /*!
80  \enum NodeType
81 
82  \brief Auxiliary internal enumeration to control the tree nodes.
83  */
84  enum NodeType
85  {
86  GROUP = 0, /*!< Library root node. */
87  SYMBOL = 1, /*!< Symbol node. */
88  };
89 
90  public:
91 
92  /** @name Initializer Methods
93  * Methods related to instantiation and destruction.
94  */
95  //@{
96 
97  /*!
98  \brief Constructs a symbol selector dialog which is a child of parent, with widget flags set to f.
99 
100  \note field names from dataset for text symbolizer (no geometry)
101 
102  */
103  SymbolSelectorDialog(const std::vector<std::string>& fieldsNames, QWidget* parent = 0, Qt::WindowFlags f = 0);
104 
105  /*! \brief Destructor. */
107 
108  /*! \brief Auxiliary internal method that returns the selected symbol.
109  */
111 
112  /*!
113  \brief Gets the selected symbol.
114 
115  \return The selected fill element.
116 
117  \note The caller will take the ownership of the returned symbol.
118  \note It return a NULL pointer if there is not a selected symbol.
119  */
120  Symbol* getSymbol() const;
121 
122  private slots:
123 
124  void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
125 
127 
129 
131 
132  void onSearchLineEditTextChanged(const QString& text);
133 
135 
137 
139 
141 
143 
145 
147 
149 
151 
152  void onDropEvent();
153 
155 
156  private:
157 
158  /*! \brief Initialize the dialog. */
159  void initialize();
160 
161  /*! \brief Auxiliary internal method to filter the symbols. */
162  void filter(const QList<QTreeWidgetItem*>& items);
163 
164  /*! \brief Auxiliary internal method that returns the symbol given a list widget item. */
165  Symbol* getSymbolFromItem(QTreeWidgetItem* item) const;
166 
167  /*! \brief Auxiliary internal method to format a symbol info to be used on tool tips. */
168  QString formatSymbolInfo(const SymbolInfo& info) const;
169 
170  /*! \brief Add new symbol to a symbol library. */
171  bool addSymbol(Symbol* symbol, const QString& groupParentId);
172 
173  /*!
174  \brief Update the current selected symbol.
175 
176  \note The symbol with the old state will be removed, and a new one with the same id and name will be added to the library.
177  */
179 
180  /*!
181  \brief Remove a symbol from a symbol library .
182 
183  \note The symbol is removed, but the pointer is not deleted.
184  */
185  bool removeSymbol(Symbol* symbol);
186 
187  /*!
188  \brief Remove a symbol from a symbol library .
189 
190  \note The symbol is removed, but the pointer is not deleted.
191  */
192  bool eraseSymbol(Symbol* symbol);
193 
194  /*!
195  \brief Remove the current selected symbol from a symbol library.
196 
197  \note The symbol is removed, but the pointer is not deleted.
198  */
200 
201  /*! \brief Add new symbol to a symbol library. */
202  bool addGroup(const QString& groupName, const QString& groupParentId);
203 
204  /*!
205  \brief Update the current selected symbol.
206 
207  \note The symbol with the old state will be removed, and a new one with the same id and name will be added to the library.
208  */
209  bool updateCurrentGroup(const QString& newGroupName, const QString& groupId);
210 
211  /*!
212  \brief Remove a symbol from a symbol library .
213 
214  \note The symbol is removed, but the pointer is not deleted.
215  */
216  bool eraseGroup(const QString& groupId);
217 
218  /*!
219  \brief Remove the current selected symbol from a symbol library.
220 
221  \note The symbol is removed, but the pointer is not deleted.
222  */
224 
225  /*!
226  \brief Get the current selected symbol.
227  */
228  QTreeWidgetItem* getSelectedItem() const;
229 
230  void buildTree(SymbolNode* node, QTreeWidgetItem* parent);
231 
232  QTreeWidgetItem* createItemFromGroup(SymbolNode* node, QTreeWidgetItem* parent = nullptr);
233 
234  QTreeWidgetItem* createItemFromGroup(SymbolNode* node, QTreeWidget* parent);
235 
236  QTreeWidgetItem* createItemFromSymbol(Symbol* symbol, QTreeWidgetItem* parent = nullptr);
237 
238  QTreeWidgetItem* createItemFromSymbol(Symbol* symbol, QTreeWidget* parent);
239 
240  void configItemFromSymbol(Symbol* symbol, QTreeWidgetItem* item);
241 
242  void enableSymbolItem(bool enable);
243 
244  void enableGroupItem(bool enable);
245 
246  QTreeWidgetItem* getCurrentGroupItem();
247 
249 
250  QTreeWidgetItem* searchParentGroup(QTreeWidgetItem* item);
251 
252  QString getSelectedItemID();
253 
254  bool isRootItem(QTreeWidgetItem* item);
255 
256  private:
257 
258  std::unique_ptr<Ui::SymbolSelectorDialogForm> m_ui; //!< Dialog form.
259  SymbolPreviewWidget* m_preview; //!< Preview Widget used to visualize the symbol.
260  std::vector<std::string> m_fieldsNames; //!< Dataset fields names for text symbolizer (no geometry)
261  QTreeWidgetItem* m_currentDragDropItem;
262  };
263 
264  } // end namespace widgets
265  } // end namespace qt
266 } // end namespace te
267 
268 #endif // __TERRALIB_QT_WIDGETS_SE_INTERNAL_SYMBOLSELECTORDIALOG_H
A widget used to preview symbol elements.
A dialog used to create or edit a specific symbol.
QString formatSymbolInfo(const SymbolInfo &info) const
Auxiliary internal method to format a symbol info to be used on tool tips.
Symbol * getSelectedSymbol() const
Auxiliary internal method that returns the selected symbol.
SymbolSelectorDialog(const std::vector< std::string > &fieldsNames, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a symbol selector dialog which is a child of parent, with widget flags set to f.
bool updateCurrentSymbol(Symbol *symbol)
Update the current selected symbol.
SymbolPreviewWidget * m_preview
Preview Widget used to visualize the symbol.
void onSearchLineEditTextChanged(const QString &text)
QTreeWidgetItem * searchParentGroup(QTreeWidgetItem *item)
bool eraseSymbol(Symbol *symbol)
Remove a symbol from a symbol library .
bool eraseCurrentGroup()
Remove the current selected symbol from a symbol library.
bool addSymbol(Symbol *symbol, const QString &groupParentId)
Add new symbol to a symbol library.
QTreeWidgetItem * getCurrentGroupItem()
void configItemFromSymbol(Symbol *symbol, QTreeWidgetItem *item)
QTreeWidgetItem * createItemFromSymbol(Symbol *symbol, QTreeWidgetItem *parent=nullptr)
QTreeWidgetItem * getSelectedItem() const
Get the current selected symbol.
bool updateCurrentGroup(const QString &newGroupName, const QString &groupId)
Update the current selected symbol.
NodeType
Auxiliary internal enumeration to control the tree nodes.
void buildTree(SymbolNode *node, QTreeWidgetItem *parent)
bool removeSymbol(Symbol *symbol)
Remove a symbol from a symbol library .
void filter(const QList< QTreeWidgetItem * > &items)
Auxiliary internal method to filter the symbols.
bool isRootItem(QTreeWidgetItem *item)
void initialize()
Initialize the dialog.
QTreeWidgetItem * createItemFromGroup(SymbolNode *node, QTreeWidgetItem *parent=nullptr)
bool eraseGroup(const QString &groupId)
Remove a symbol from a symbol library .
bool addGroup(const QString &groupName, const QString &groupParentId)
Add new symbol to a symbol library.
std::unique_ptr< Ui::SymbolSelectorDialogForm > m_ui
Dialog form.
QTreeWidgetItem * createItemFromGroup(SymbolNode *node, QTreeWidget *parent)
std::vector< std::string > m_fieldsNames
Dataset fields names for text symbolizer (no geometry)
bool eraseCurrentSymbol()
Remove the current selected symbol from a symbol library.
Symbol * getSymbol() const
Gets the selected symbol.
void onCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
QTreeWidgetItem * createItemFromSymbol(Symbol *symbol, QTreeWidget *parent)
virtual ~SymbolSelectorDialog()
Destructor.
Symbol * getSymbolFromItem(QTreeWidgetItem *item) const
Auxiliary internal method that returns the symbol given a list widget item.
This class represents a symbol. TODO: More description!
Definition: Symbol.h:55
TerraLib.
#define slots
Information about a given Symbol.
Definition: SymbolInfo.h:61
#define TEQTWIDGETSEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63