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  Q_PROPERTY(QColor tempInvalidValueColor READ invalidValueColor WRITE setTempInvalidValueColor);
70  Q_PROPERTY(QVariantList tempInvalidValueColorRgbF READ tempInvalidValueColorRgbF WRITE
71  setTempInvalidValueColorRgbF);
72 
73 public:
76  const smtk::operation::OperationPtr& operation,
77  const smtk::resource::ManagerPtr& resourceManager,
78  const smtk::view::ManagerPtr& viewManager);
80  const smtk::resource::ManagerPtr& resourceManager,
81  const smtk::view::ManagerPtr& viewManager);
82  ~qtUIManager() override;
83 
84  void initializeUI(QWidget* pWidget, bool useInternalFileBrowser = false);
85  void initializeUI(const smtk::view::Information& v, bool useInternalFileBrowser = false);
86 
88  smtk::view::ConfigurationPtr findOrCreateOperationView() const;
89 
91  smtk::operation::OperationPtr operation() const { return m_operation; }
92 
95  qtBaseView* setSMTKView(const smtk::view::ConfigurationPtr& v);
96  qtBaseView* setSMTKView(
98  QWidget* pWidget,
99  bool useInternalFileBrowser = true);
100  qtBaseView* setSMTKView(const smtk::view::Information& v, bool useInternalFileBrowser = true);
101  smtk::view::ConfigurationPtr smtkView() const { return m_smtkView; }
102  const smtk::view::Configuration::Component& findStyle(
104  const std::string& styleName = "") const;
106 
108  {
109  return m_managers.get<smtk::resource::ManagerPtr>();
110  }
111 
113  {
114  m_managers.get<smtk::resource::ManagerPtr>() = mgr;
115  }
116 
118  {
119  return m_managers.get<smtk::operation::ManagerPtr>();
120  }
121 
123  {
124  m_managers.get<smtk::operation::ManagerPtr>() = mgr;
125  }
126 
128 
130  {
131  m_managers.get<smtk::view::ManagerPtr>() = mgr;
132  }
133 
134  const smtk::common::TypeContainer& managers() const { return m_managers; }
135  smtk::common::TypeContainer& managers() { return m_managers; }
136 
139  void setDefaultValueColor(const QColor& color);
140  void setDefaultValueColorRgbF(const QVariantList& color);
141  QColor defaultValueColor() const { return this->DefaultValueColor; }
142  QVariantList defaultValueColorRgbF() const;
144 
147  void setInvalidValueColor(const QColor& color);
148  void setInvalidValueColorRgbF(const QVariantList& color);
149  QColor invalidValueColor() const { return this->InvalidValueColor; }
150  QVariantList invalidValueColorRgbF() const;
152 
155  void setTempInvalidValueColor(const QColor& color);
156  void setTempInvalidValueColorRgbF(const QVariantList& color);
157  QColor tempInvalidValueColor() const { return this->InvalidValueColor; }
158  QVariantList tempInvalidValueColorRgbF() const;
160 
165  QColor correctedInvalidValueColor() const;
166  QColor correctedNormalValueColor() const;
167  QColor correctedDefaultValueColor() const;
168  QColor correctedTempInvalidValueColor() const;
170 
173  void setAdvanceFontStyleBold(bool val);
174  bool advanceFontStyleBold() const;
175  void setAdvanceFontStyleItalic(bool val);
176  bool advanceFontStyleItalic() const;
177 
178  void setAdvancedBold(bool b) { this->AdvancedBold = b; }
179  bool advancedBold() { return this->AdvancedBold; }
180  void setAdvancedItalic(bool i) { this->AdvancedItalic = i; }
181  bool advancedItalic() { return this->AdvancedItalic; }
183 
186  int maxValueLabelLength() const { return m_maxValueLabelLength; }
187  void setMaxValueLabelLength(int w) { m_maxValueLabelLength = w; }
188  int minValueLabelLength() const { return m_minValueLabelLength; }
189  void setMinValueLabelLength(int w) { m_minValueLabelLength = w; }
191 
193  bool hasViewConstructor(const std::string& vtype) const;
194 
196  void registerItemConstructor(const std::string& vtype, qtItemConstructor f);
198  bool hasItemConstructor(const std::string& vtype) const
199  {
200  return m_itemConstructors.find(vtype) != m_itemConstructors.end();
201  }
202 
203  qtBaseView* topView() { return m_topView; }
204  static QString clipBoardText();
205  static void setClipBoardText(QString& text);
206  std::string currentCategory();
207  bool categoryEnabled();
208  void clearRoot();
209 
213  //
214  // TODO: We may not want to define color in smtk::core. Instead, we may want
215  // to use Qt's convention of naming entities within a color palette
216  // rather than hard-coding colors; these descriptions should also live
217  // in the smtk::extensions::qt library, where they are used.
218  static QColor contrastWithText(const QColor&);
219 
220  bool passAdvancedCheck(int level);
221 
222  const QFont& advancedFont() { return this->advFont; }
223  int advanceLevel() const { return m_currentAdvLevel; }
224  void initAdvanceLevels(QComboBox* combo);
225 
226  void setWidgetColorToInvalid(QWidget* widget);
227  void setWidgetColorToDefault(QWidget* widget);
228  void setWidgetColorToNormal(QWidget* widget);
229  bool getExpressionArrayString(smtk::attribute::GroupItemPtr dataItem, QString& strValues);
230 
231  static void updateArrayTableWidget(smtk::attribute::GroupItemPtr dataItem, QTableWidget* widget);
232  static void updateTableColRows(smtk::attribute::ItemPtr dataItem, int col, QTableWidget* widget);
233 
234  static void updateArrayDataValue(smtk::attribute::GroupItemPtr dataItem, QTableWidgetItem* item);
235  static void addNewTableValues(
237  QTableWidget* table,
238  double* vals,
239  int numVals);
240  static void removeSelectedTableValues(
242  QTableWidget* table);
243 
244  bool updateTableItemCheckState(QTableWidgetItem* labelitem, smtk::attribute::ItemPtr attItem);
245 
246  virtual int getWidthOfAttributeMaxLabel(smtk::attribute::DefinitionPtr def, const QFont& font);
247  virtual int getWidthOfItemsMaxLabel(
248  const QList<smtk::attribute::ItemDefinitionPtr>& itemDefs,
249  const QFont& font);
250  virtual int getWidthOfText(const std::string& text, const QFont& font);
251 
253  qtBaseView* createView(const smtk::view::Information& info);
254 
256  qtItem* createItem(const qtAttributeItemInfo& info);
257 
260  {
261  return m_managers.get<smtk::view::SelectionPtr>();
262  }
263 
265  {
266  m_managers.get<smtk::view::SelectionPtr>() = newSel;
267  }
268 
269  int selectionBit() const { return m_selectionBit; }
270  void setSelectionBit(int val) { m_selectionBit = val; }
271 
272  int hoverBit() const { return m_hoverBit; }
273  void setHoverBit(int val) { m_hoverBit = val; }
274 
275  bool highlightOnHover() const { return m_highlightOnHover; }
276 
277  void setHighlightOnHover(bool val);
278 
279  static qtItem* defaultItemConstructor(const qtAttributeItemInfo& info);
280 
282  const QPixmap& alertPixmap() const { return m_alertPixmap; }
283 
286  void setReadOnly(bool mode);
287  bool isReadOnly() const { return m_readOnly; }
288 
289 #ifdef _WIN32
290 #define LINE_BREAKER_STRING "\n";
291 #else
292 #define LINE_BREAKER_STRING "\r";
293 #endif
294 
295 public Q_SLOTS:
296  void onFileItemCreated(smtk::extension::qtFileItem*);
297  void onModelEntityItemCreated(smtk::extension::qtModelEntityItem*);
298  void onViewUIModified(smtk::extension::qtBaseView*, smtk::attribute::ItemPtr);
299  void setAdvanceLevel(int b);
300  void onOperationFinished();
301 
302 Q_SIGNALS:
303  void fileItemCreated(smtk::extension::qtFileItem* fileItem);
304  void modelEntityItemCreated(smtk::extension::qtModelEntityItem* entItem);
309  void highlightOnHoverChanged(bool);
318  void defaultValueColorChanged();
327  void invalidValueColorChanged();
328  void refreshEntityItems();
329 
330  friend class qtBaseView;
331  friend class qtAssociationWidget;
332 
333 protected:
334  void commonConstructor();
335  virtual void internalInitialize();
336 
337 private:
338  qtBaseView* m_topView;
339  smtk::view::ConfigurationPtr m_smtkView;
340  QWidget* m_parentWidget;
341 
342  QFont advFont;
343  QColor DefaultValueColor;
344  QColor InvalidValueColor;
345  QColor TempInvalidValueColor;
346  bool AdvancedBold; // true by default
347  bool AdvancedItalic; // false by default
348 
349  std::weak_ptr<smtk::attribute::Resource> m_attResource;
350  smtk::common::TypeContainer m_managers;
351  smtk::operation::OperationPtr m_operation;
352  bool m_useInternalFileBrowser;
353 
354  int m_maxValueLabelLength;
355  int m_minValueLabelLength;
356 
357  // current advance level to show advanced attributes/items
358  int m_currentAdvLevel;
359 
360  bool m_readOnly = false;
361 
362  // map for <Definition, its longest item label>
363  // The longest label is used as a hint when aligning all item labels
364  QMap<smtk::attribute::DefinitionPtr, std::string> Def2LongLabel;
365  void findDefinitionsLongLabels();
366  void findDefinitionLongLabel(smtk::attribute::DefinitionPtr def, std::string& labelText);
367  void getItemsLongLabel(
368  const QList<smtk::attribute::ItemDefinitionPtr>& itemDefs,
369  std::string& labelText);
370  std::map<std::string, qtItemConstructor> m_itemConstructors;
371 
372  int m_selectionBit;
373 
374  // For Hover-based information
375  bool m_highlightOnHover;
376  int m_hoverBit;
377 
378  std::map<std::string, std::string> m_activeTabInfo;
379  QPixmap m_alertPixmap;
380 
381  const std::string m_activeAdvLevelXmlAttName = "ActiveAdvanceLevel";
382 
383 }; // class
384 
385 //A sublcass of QTextEdit to give initial sizehint
386 class SMTKQTEXT_EXPORT qtTextEdit : public QTextEdit
387 {
388  Q_OBJECT
389 public:
390  qtTextEdit(QWidget* parent);
391  QSize sizeHint() const override;
392 };
393 
394 }; // namespace extension
395 }; // namespace smtk
396 
397 #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:186
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:181
smtk::extension::qtUIManager::managers
smtk::common::TypeContainer & managers()
Definition: qtUIManager.h:135
smtk::extension::qtUIManager::hoverBit
int hoverBit() const
Definition: qtUIManager.h:272
smtk::extension::qtUIManager::setMinValueLabelLength
void setMinValueLabelLength(int w)
Definition: qtUIManager.h:189
smtk::extension::qtUIManager::setMaxValueLabelLength
void setMaxValueLabelLength(int w)
Definition: qtUIManager.h:187
smtk::extension::qtUIManager::alertPixmap
const QPixmap & alertPixmap() const
Return the pixmap used for alert icons.
Definition: qtUIManager.h:282
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:127
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:222
smtk::extension::qtUIManager::operation
smtk::operation::OperationPtr operation() const
If this instance was constructed with an operation, return it.
Definition: qtUIManager.h:91
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:270
smtk::extension::qtUIManager::advanceLevel
int advanceLevel() const
Definition: qtUIManager.h:223
smtk::view::ManagerPtr
smtk::shared_ptr< smtk::view::Manager > ManagerPtr
Definition: PublicPointerDefs.h:626
smtk::extension::qtUIManager::invalidValueColor
QColor invalidValueColor() const
Definition: qtUIManager.h:149
smtk::extension::qtUIManager::selection
const smtk::view::SelectionPtr & selection() const
Methods for dealing with selection process.
Definition: qtUIManager.h:259
smtk::extension::qtUIManager::highlightOnHover
bool highlightOnHover() const
Definition: qtUIManager.h:275
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:134
smtk::extension::qtUIManager::setHoverBit
void setHoverBit(int val)
Definition: qtUIManager.h:273
smtk::view::ConfigurationPtr
smtk::shared_ptr< smtk::view::Configuration > ConfigurationPtr
Definition: PublicPointerDefs.h:642
smtk::extension::qtUIManager::topView
qtBaseView * topView()
Definition: qtUIManager.h:203
smtk::extension::qtUIManager::resourceManager
smtk::resource::ManagerPtr & resourceManager()
}@
Definition: qtUIManager.h:107
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:101
smtk::extension::qtUIManager::setAdvancedItalic
void setAdvancedItalic(bool i)
Definition: qtUIManager.h:180
smtk::extension::qtUIManager::setSelection
void setSelection(const smtk::view::SelectionPtr &newSel)
Definition: qtUIManager.h:264
smtk::extension::qtUIManager::selectionBit
int selectionBit() const
Definition: qtUIManager.h:269
smtk::extension::qtUIManager::setAdvancedBold
void setAdvancedBold(bool b)
Definition: qtUIManager.h:178
smtk::extension::qtUIManager::setResourceManager
void setResourceManager(const smtk::resource::ManagerPtr &mgr)
Definition: qtUIManager.h:112
smtk::extension::qtUIManager::minValueLabelLength
int minValueLabelLength() const
Definition: qtUIManager.h:188
smtk::extension::qtUIManager::setOperationManager
void setOperationManager(const smtk::operation::ManagerPtr &mgr)
Definition: qtUIManager.h:122
smtk::extension::qtUIManager::defaultValueColor
QColor defaultValueColor() const
Definition: qtUIManager.h:141
smtk::attribute::ItemPtr
smtk::shared_ptr< smtk::attribute::Item > ItemPtr
Definition: PublicPointerDefs.h:467
smtk::extension::qtUIManager::advancedBold
bool advancedBold()
Definition: qtUIManager.h:179
smtk::extension::qtTextEdit
Definition: qtUIManager.h:386
smtk::extension::qtUIManager::tempInvalidValueColor
QColor tempInvalidValueColor() const
Definition: qtUIManager.h:157
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:198
smtk::extension::qtUIManager::setViewManager
void setViewManager(const smtk::view::ManagerPtr &mgr)
Definition: qtUIManager.h:129
smtk::attribute::ResourcePtr
smtk::shared_ptr< smtk::attribute::Resource > ResourcePtr
Definition: PublicPointerDefs.h:604
smtk::extension::qtUIManager::isReadOnly
bool isReadOnly() const
Definition: qtUIManager.h:287
smtk::common::TypeContainer
A container for caching and retrieving instances of types.
Definition: TypeContainer.h:42
smtk::extension::qtUIManager::operationManager
smtk::operation::ManagerPtr & operationManager()
Definition: qtUIManager.h:117