SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
qtUIManager.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 #ifndef smtk_extension_qtUIManager_h
11 #define smtk_extension_qtUIManager_h
12 
13 #include "smtk/attribute/Categories.h"
14 #include "smtk/attribute/Resource.h"
15 
16 #include "smtk/common/Deprecation.h"
17 #include "smtk/common/TypeContainer.h"
18 
19 #include "smtk/operation/Manager.h"
20 #include "smtk/resource/Manager.h"
21 #include "smtk/view/Configuration.h"
22 #include "smtk/view/Manager.h"
23 #include "smtk/view/Selection.h"
24 
25 #include "smtk/extension/qt/Exports.h"
26 #include "smtk/extension/qt/qtItem.h"
27 
28 #include <QColor>
29 #include <QFont>
30 #include <QMap>
31 #include <QPixmap>
32 #include <QPointer>
33 #include <QTextEdit>
34 #include <QVariant>
35 #include <map>
36 
37 class QTableWidget;
38 class QTableWidgetItem;
39 class QComboBox;
40 
41 namespace smtk
42 {
43 namespace extension
44 {
45 class qtItem;
46 class qtFileItem;
47 class qtModelEntityItem;
48 class qtBaseView;
49 
50 typedef qtItem* (*qtItemConstructor)(const qtAttributeItemInfo& info);
51 
57 class SMTKQTEXT_EXPORT qtUIManager : public QObject
58 {
59  Q_OBJECT
60 
61  Q_PROPERTY(QColor defaultValueColor READ defaultValueColor WRITE setDefaultValueColor);
62  Q_PROPERTY(
63  QVariantList defaultValueColorRgbF READ defaultValueColorRgbF WRITE setDefaultValueColorRgbF);
64 
65  Q_PROPERTY(QColor invalidValueColor READ invalidValueColor WRITE setInvalidValueColor);
66  Q_PROPERTY(
67  QVariantList invalidValueColorRgbF READ invalidValueColorRgbF WRITE setInvalidValueColorRgbF);
68 
69 public:
72  const smtk::operation::OperationPtr& operation,
73  const smtk::resource::ManagerPtr& resourceManager,
74  const smtk::view::ManagerPtr& viewManager);
76  const smtk::resource::ManagerPtr& resourceManager,
77  const smtk::view::ManagerPtr& viewManager);
78  ~qtUIManager() override;
79 
80  void initializeUI(QWidget* pWidget, bool useInternalFileBrowser = false);
81  void initializeUI(const smtk::view::Information& v, bool useInternalFileBrowser = false);
82 
84  smtk::view::ConfigurationPtr findOrCreateOperationView() const;
85 
87  smtk::operation::OperationPtr operation() const { return m_operation; }
88 
91  qtBaseView* setSMTKView(const smtk::view::ConfigurationPtr& v);
92  qtBaseView* setSMTKView(
94  QWidget* pWidget,
95  bool useInternalFileBrowser = true);
96  qtBaseView* setSMTKView(const smtk::view::Information& v, bool useInternalFileBrowser = true);
97  smtk::view::ConfigurationPtr smtkView() const { return m_smtkView; }
98  const smtk::view::Configuration::Component& findStyle(
100  const std::string& styleName = "") const;
102 
104  {
105  return m_managers.get<smtk::resource::ManagerPtr>();
106  }
107 
109  {
110  m_managers.get<smtk::resource::ManagerPtr>() = mgr;
111  }
112 
114  {
115  return m_managers.get<smtk::operation::ManagerPtr>();
116  }
117 
119  {
120  m_managers.get<smtk::operation::ManagerPtr>() = mgr;
121  }
122 
124 
126  {
127  m_managers.get<smtk::view::ManagerPtr>() = mgr;
128  }
129 
130  const smtk::common::TypeContainer& managers() const { return m_managers; }
131  smtk::common::TypeContainer& managers() { return m_managers; }
132 
135  void setDefaultValueColor(const QColor& color);
136  void setDefaultValueColorRgbF(const QVariantList& color);
137  QColor defaultValueColor() const { return this->DefaultValueColor; }
138  QVariantList defaultValueColorRgbF() const;
140 
143  void setInvalidValueColor(const QColor& color);
144  void setInvalidValueColorRgbF(const QVariantList& color);
145  QColor invalidValueColor() const { return this->InvalidValueColor; }
146  QVariantList invalidValueColorRgbF() const;
152  QColor correctedInvalidValueColor() const;
153  QColor correctedNormalValueColor() const;
154  QColor correctedDefaultValueColor() const;
156 
159  void setAdvanceFontStyleBold(bool val);
160  bool advanceFontStyleBold() const;
161  void setAdvanceFontStyleItalic(bool val);
162  bool advanceFontStyleItalic() const;
163 
164  void setAdvancedBold(bool b) { this->AdvancedBold = b; }
165  bool advancedBold() { return this->AdvancedBold; }
166  void setAdvancedItalic(bool i) { this->AdvancedItalic = i; }
167  bool advancedItalic() { return this->AdvancedItalic; }
169 
172  int maxValueLabelLength() const { return m_maxValueLabelLength; }
173  void setMaxValueLabelLength(int w) { m_maxValueLabelLength = w; }
174  int minValueLabelLength() const { return m_minValueLabelLength; }
175  void setMinValueLabelLength(int w) { m_minValueLabelLength = w; }
177 
179  bool hasViewConstructor(const std::string& vtype) const;
180 
182  void registerItemConstructor(const std::string& vtype, qtItemConstructor f);
184  bool hasItemConstructor(const std::string& vtype) const
185  {
186  return m_itemConstructors.find(vtype) != m_itemConstructors.end();
187  }
188 
189  qtBaseView* topView() { return m_topView; }
190  static QString clipBoardText();
191  static void setClipBoardText(QString& text);
192  std::string currentCategory();
193  bool categoryEnabled();
194  void clearRoot();
195 
199  //
200  // TODO: We may not want to define color in smtk::core. Instead, we may want
201  // to use Qt's convention of naming entities within a color palette
202  // rather than hard-coding colors; these descriptions should also live
203  // in the smtk::extensions::qt library, where they are used.
204  static QColor contrastWithText(const QColor&);
205 
206  bool passAdvancedCheck(int level);
207 
208  const QFont& advancedFont() { return this->advFont; }
209  int advanceLevel() const { return m_currentAdvLevel; }
210  void initAdvanceLevels(QComboBox* combo);
211 
212  void setWidgetColorToInvalid(QWidget* widget);
213  void setWidgetColorToDefault(QWidget* widget);
214  void setWidgetColorToNormal(QWidget* widget);
215  bool getExpressionArrayString(smtk::attribute::GroupItemPtr dataItem, QString& strValues);
216 
217  static void updateArrayTableWidget(smtk::attribute::GroupItemPtr dataItem, QTableWidget* widget);
218  static void updateTableColRows(smtk::attribute::ItemPtr dataItem, int col, QTableWidget* widget);
219 
220  static void updateArrayDataValue(smtk::attribute::GroupItemPtr dataItem, QTableWidgetItem* item);
221  static void addNewTableValues(
223  QTableWidget* table,
224  double* vals,
225  int numVals);
226  static void removeSelectedTableValues(
228  QTableWidget* table);
229 
230  bool updateTableItemCheckState(QTableWidgetItem* labelitem, smtk::attribute::ItemPtr attItem);
231 
232  virtual int getWidthOfAttributeMaxLabel(smtk::attribute::DefinitionPtr def, const QFont& font);
233  virtual int getWidthOfItemsMaxLabel(
234  const QList<smtk::attribute::ItemDefinitionPtr>& itemDefs,
235  const QFont& font);
236  virtual int getWidthOfText(const std::string& text, const QFont& font);
237 
239  qtBaseView* createView(const smtk::view::Information& info);
240 
242  qtItem* createItem(const qtAttributeItemInfo& info);
243 
246  {
247  return m_managers.get<smtk::view::SelectionPtr>();
248  }
249 
251  {
252  m_managers.get<smtk::view::SelectionPtr>() = newSel;
253  }
254 
255  int selectionBit() const { return m_selectionBit; }
256  void setSelectionBit(int val) { m_selectionBit = val; }
257 
258  int hoverBit() const { return m_hoverBit; }
259  void setHoverBit(int val) { m_hoverBit = val; }
260 
261  bool highlightOnHover() const { return m_highlightOnHover; }
262 
263  void setHighlightOnHover(bool val);
264 
265  static qtItem* defaultItemConstructor(const qtAttributeItemInfo& info);
266 
268  const QPixmap& alertPixmap() const { return m_alertPixmap; }
269 
270 #ifdef _WIN32
271 #define LINE_BREAKER_STRING "\n";
272 #else
273 #define LINE_BREAKER_STRING "\r";
274 #endif
275 
276 public Q_SLOTS:
277  void onFileItemCreated(smtk::extension::qtFileItem*);
278  void onModelEntityItemCreated(smtk::extension::qtModelEntityItem*);
279  void onViewUIModified(smtk::extension::qtBaseView*, smtk::attribute::ItemPtr);
280  void setAdvanceLevel(int b);
281  void onOperationFinished();
282 
283 Q_SIGNALS:
284  void fileItemCreated(smtk::extension::qtFileItem* fileItem);
285  void modelEntityItemCreated(smtk::extension::qtModelEntityItem* entItem);
290  void highlightOnHoverChanged(bool);
299  void defaultValueColorChanged();
308  void invalidValueColorChanged();
309  void refreshEntityItems();
310 
311  friend class qtBaseView;
312  friend class qtAssociationWidget;
313 
314 protected:
315  void commonConstructor();
316  virtual void internalInitialize();
317 
318 private:
319  qtBaseView* m_topView;
320  smtk::view::ConfigurationPtr m_smtkView;
321  QWidget* m_parentWidget;
322 
323  QFont advFont;
324  QColor DefaultValueColor;
325  QColor InvalidValueColor;
326  bool AdvancedBold; // true by default
327  bool AdvancedItalic; // false by default
328 
329  std::weak_ptr<smtk::attribute::Resource> m_attResource;
330  smtk::common::TypeContainer m_managers;
331  smtk::operation::OperationPtr m_operation;
332  bool m_useInternalFileBrowser;
333 
334  int m_maxValueLabelLength;
335  int m_minValueLabelLength;
336 
337  // current advance level to show advanced attributes/items
338  int m_currentAdvLevel;
339 
340  // map for <Definition, its longest item label>
341  // The longest label is used as a hint when aligning all item labels
342  QMap<smtk::attribute::DefinitionPtr, std::string> Def2LongLabel;
343  void findDefinitionsLongLabels();
344  void findDefinitionLongLabel(smtk::attribute::DefinitionPtr def, std::string& labelText);
345  void getItemsLongLabel(
346  const QList<smtk::attribute::ItemDefinitionPtr>& itemDefs,
347  std::string& labelText);
348  std::map<std::string, qtItemConstructor> m_itemConstructors;
349 
350  int m_selectionBit;
351 
352  // For Hover-based information
353  bool m_highlightOnHover;
354  int m_hoverBit;
355 
356  std::map<std::string, std::string> m_activeTabInfo;
357  QPixmap m_alertPixmap;
358 
359  const std::string m_activeAdvLevelXmlAttName = "ActiveAdvanceLevel";
360 
361 }; // class
362 
363 //A sublcass of QTextEdit to give initial sizehint
364 class SMTKQTEXT_EXPORT qtTextEdit : public QTextEdit
365 {
366  Q_OBJECT
367 public:
368  qtTextEdit(QWidget* parent);
369  QSize sizeHint() const override;
370 };
371 
372 }; // namespace extension
373 }; // namespace smtk
374 
375 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::extension::qtItem
an abstract UI class for attribute item
Definition: qtItem.h:61
smtk::extension::qtUIManager::maxValueLabelLength
int maxValueLabelLength() const
}@
Definition: qtUIManager.h:172
smtk::attribute::DefinitionPtr
smtk::shared_ptr< smtk::attribute::Definition > DefinitionPtr
Definition: PublicPointerDefs.h:450
smtk::extension::qtUIManager
Container for managers whose content is presented via Qt widgets.
Definition: qtUIManager.h:57
smtk::view::SelectionPtr
smtk::shared_ptr< smtk::view::Selection > SelectionPtr
Definition: PublicPointerDefs.h:634
smtk::extension::qtFileItem
Provides the QT UI for a smtk::attribute::FileSystemItem.
Definition: qtFileItem.h:68
smtk::extension::qtBaseView
A base class for all view types implemented using Qt.
Definition: qtBaseView.h:46
smtk::extension::qtUIManager::advancedItalic
bool advancedItalic()
Definition: qtUIManager.h:167
smtk::extension::qtUIManager::managers
smtk::common::TypeContainer & managers()
Definition: qtUIManager.h:131
smtk::extension::qtUIManager::hoverBit
int hoverBit() const
Definition: qtUIManager.h:258
smtk::extension::qtUIManager::setMinValueLabelLength
void setMinValueLabelLength(int w)
Definition: qtUIManager.h:175
smtk::extension::qtUIManager::setMaxValueLabelLength
void setMaxValueLabelLength(int w)
Definition: qtUIManager.h:173
smtk::extension::qtUIManager::alertPixmap
const QPixmap & alertPixmap() const
Return the pixmap used for alert icons.
Definition: qtUIManager.h:268
smtk::operation::OperationPtr
smtk::shared_ptr< smtk::operation::Operation > OperationPtr
Definition: PublicPointerDefs.h:344
smtk::view::Information
A class for information passed to views during initialization.
Definition: Information.h:32
smtk::extension::qtUIManager::viewManager
smtk::view::ManagerPtr & viewManager()
Definition: qtUIManager.h:123
smtk::extension::qtAssociationWidget
Base class for widgets that deal with attribute associations.
Definition: qtAssociationWidget.h:25
smtk::attribute::GroupItemPtr
smtk::shared_ptr< smtk::attribute::GroupItem > GroupItemPtr
Definition: PublicPointerDefs.h:507
smtk::extension::qtUIManager::advancedFont
const QFont & advancedFont()
Definition: qtUIManager.h:208
smtk::extension::qtUIManager::operation
smtk::operation::OperationPtr operation() const
If this instance was constructed with an operation, return it.
Definition: qtUIManager.h:87
smtk::operation::ManagerPtr
smtk::shared_ptr< smtk::operation::Manager > ManagerPtr
Definition: PublicPointerDefs.h:348
smtk::extension::qtUIManager::setSelectionBit
void setSelectionBit(int val)
Definition: qtUIManager.h:256
smtk::extension::qtUIManager::advanceLevel
int advanceLevel() const
Definition: qtUIManager.h:209
smtk::view::ManagerPtr
smtk::shared_ptr< smtk::view::Manager > ManagerPtr
Definition: PublicPointerDefs.h:626
smtk::extension::qtUIManager::invalidValueColor
QColor invalidValueColor() const
Definition: qtUIManager.h:145
smtk::extension::qtUIManager::selection
const smtk::view::SelectionPtr & selection() const
Methods for dealing with selection process.
Definition: qtUIManager.h:245
smtk::extension::qtUIManager::highlightOnHover
bool highlightOnHover() const
Definition: qtUIManager.h:261
smtk::extension::qtAttributeItemInfo
Class used to generate widgets for Attribute Items.
Definition: qtAttributeItemInfo.h:39
smtk::extension::qtUIManager::managers
const smtk::common::TypeContainer & managers() const
Definition: qtUIManager.h:130
smtk::extension::qtUIManager::setHoverBit
void setHoverBit(int val)
Definition: qtUIManager.h:259
smtk::view::ConfigurationPtr
smtk::shared_ptr< smtk::view::Configuration > ConfigurationPtr
Definition: PublicPointerDefs.h:642
smtk::extension::qtUIManager::topView
qtBaseView * topView()
Definition: qtUIManager.h:189
smtk::extension::qtUIManager::resourceManager
smtk::resource::ManagerPtr & resourceManager()
}@
Definition: qtUIManager.h:103
smtk::view::Configuration::Component
Configure one item in a view, which may contain children.
Definition: Configuration.h:32
smtk::extension::qtUIManager::smtkView
smtk::view::ConfigurationPtr smtkView() const
Definition: qtUIManager.h:97
smtk::extension::qtUIManager::setAdvancedItalic
void setAdvancedItalic(bool i)
Definition: qtUIManager.h:166
smtk::extension::qtUIManager::setSelection
void setSelection(const smtk::view::SelectionPtr &newSel)
Definition: qtUIManager.h:250
smtk::extension::qtUIManager::selectionBit
int selectionBit() const
Definition: qtUIManager.h:255
smtk::extension::qtUIManager::setAdvancedBold
void setAdvancedBold(bool b)
Definition: qtUIManager.h:164
smtk::extension::qtUIManager::setResourceManager
void setResourceManager(const smtk::resource::ManagerPtr &mgr)
Definition: qtUIManager.h:108
smtk::extension::qtUIManager::minValueLabelLength
int minValueLabelLength() const
Definition: qtUIManager.h:174
smtk::extension::qtUIManager::setOperationManager
void setOperationManager(const smtk::operation::ManagerPtr &mgr)
Definition: qtUIManager.h:118
smtk::extension::qtUIManager::defaultValueColor
QColor defaultValueColor() const
Definition: qtUIManager.h:137
smtk::attribute::ItemPtr
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:467
smtk::extension::qtUIManager::advancedBold
bool advancedBold()
Definition: qtUIManager.h:165
smtk::extension::qtTextEdit
Definition: qtUIManager.h:364
smtk::resource::ManagerPtr
smtk::shared_ptr< smtk::resource::Manager > ManagerPtr
Definition: PublicPointerDefs.h:281
smtk::extension::qtUIManager::hasItemConstructor
bool hasItemConstructor(const std::string &vtype) const
Check if view type string has a registered view construction function.
Definition: qtUIManager.h:184
smtk::extension::qtUIManager::setViewManager
void setViewManager(const smtk::view::ManagerPtr &mgr)
Definition: qtUIManager.h:125
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:604
smtk::common::TypeContainer
A container for caching and retrieving instances of types.
Definition: TypeContainer.h:35
smtk::extension::qtUIManager::operationManager
smtk::operation::ManagerPtr & operationManager()
Definition: qtUIManager.h:113