SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
qtInputsItem.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 // .NAME qtInputsItem - UI components for attribute ValueItem
11 // .SECTION Description
12 // .SECTION See Also
13 // qtItem
14 
15 #ifndef smtk_extension_qtInputsItem_h
16 #define smtk_extension_qtInputsItem_h
17 
18 #include "smtk/extension/qt/Exports.h"
19 #include "smtk/extension/qt/qtItem.h"
20 #include <QDoubleValidator>
21 
23 class QBoxLayout;
24 class QFrame;
25 class QLayout;
26 class QLineEdit;
27 class QPoint;
28 
29 namespace smtk
30 {
31 namespace extension
32 {
33 class qtUIManager;
34 
35 class SMTKQTEXT_EXPORT qtInputsItem : public qtItem
36 {
37  Q_OBJECT
38 
39  friend class qtDiscreteValueEditor;
40 
41 public:
42  static qtItem* createItemWidget(const qtAttributeItemInfo& info);
43  qtInputsItem(const qtAttributeItemInfo& info);
44  ~qtInputsItem() override;
45  void setLabelVisible(bool) override;
46  void unsetValue(int elementIndex);
47  bool setDiscreteValue(int elementIndex, int discreteValIndex);
50  void forceUpdate();
51  bool isFixedWidth() const override;
52  bool eventFilter(QObject* filterObj, QEvent* ev) override;
53 
54  QWidget* lastEditor() const override;
55  void updateTabOrder(QWidget* precedingEditor) override;
56 
57 public Q_SLOTS:
58  void setOutputOptional(int);
59  void onExpressionReferenceChanged();
60  void onTextEditChanged();
61  void onLineEditChanged();
62  void onLineEditFinished();
63  void onInputValueChanged(QObject*);
64  void doubleValueChanged(double newVal);
65  void intValueChanged(int newVal);
66  void updateItemData() override;
67  // void setUseSelectionManager(bool mode) override;
68  void showContextMenu(const QPoint& pt, int elementIdx);
69 
70 protected Q_SLOTS:
71  virtual void onAddNewValue();
72  virtual void onRemoveValue();
73  void displayExpressionWidget(bool checkstate);
74  virtual void onChildItemModified();
75 
76 protected:
77  void createWidget() override;
78  virtual void loadInputValues();
79  virtual void updateUI();
80  virtual void addInputEditor(int i);
81  virtual void updateExtensibleState();
82  virtual void clearChildWidgets();
83  QWidget* createDoubleWidget(
84  int elementIdx,
86  QWidget* pWidget,
87  QString& tooltip);
88  QWidget* createIntWidget(
89  int elementIdx,
91  QWidget* pWidget,
92  QString& tooltip);
93  virtual QWidget* createInputWidget(int elementIdx, QLayout* childLayout);
94  virtual QWidget* createEditBox(int elementIdx, QWidget* pWidget);
95  virtual QFrame* createExpressionRefFrame();
96  virtual QFrame* createLabelFrame(
97  const smtk::attribute::ValueItem* vitem,
98  const smtk::attribute::ValueItemDefinition* vitemDef);
99  // Methods for updating widgets based on changes made to the underlying attribute item
100  void updateDoubleItemData(QWidget* iwidget, const smtk::attribute::DoubleItemPtr& ditem);
101  void updateIntItemData(QWidget* iwidget, const smtk::attribute::IntItemPtr& iitem);
102  void updateStringItemData(QWidget* iwidget, const smtk::attribute::StringItemPtr& sitem);
103 
104  // Updates the item's expression reference widget. Takes the |elementIdx|th
105  // value of |inputItem|. If |showMessageBox| == true, errors are presented
106  // in a modal QMessageBox.
107  void updateExpressionRefWidgetForEvaluation(
109  bool showMessageBox);
110  void hideExpressionResultWidgets();
111  // Shows widgets for displaying results of expression evaluation. |text| is
112  // shown in a QLineEdit whose tooltip is set to |tooltip|. If |success| is
113  // true but |tooltip| is nonempty, the line edit will have a dark yellow
114  // background.
115  void showExpressionResultWidgets(bool success, const QString& text, const QString& tooltip);
116 
118  Qt::Orientation getOrientation(const qtAttributeItemInfo& info);
119 
120 private:
121  qtInputsItemInternals* m_internals;
122 }; // class
123 
124 //A sublcass of QDoubleValidator to fixup input outside of range
125 class SMTKQTEXT_EXPORT qtDoubleValidator : public QDoubleValidator
126 {
127  Q_OBJECT
128 public:
129  qtDoubleValidator(qtInputsItem* item, int elementIndex, QLineEdit* lineEdit, QObject* parent);
130  void fixup(QString& input) const override;
131 
132 private:
133  qtInputsItem* m_item;
134  int m_elementIndex;
135  QLineEdit* m_lineWidget;
136 };
137 
138 //A sublcass of QIntValidator to fixup input outside of range
139 class SMTKQTEXT_EXPORT qtIntValidator : public QIntValidator
140 {
141  Q_OBJECT
142 public:
143  qtIntValidator(qtInputsItem* item, int elementIndex, QLineEdit* lineEdit, QObject* parent);
144  void fixup(QString& input) const override;
145 
146 private:
147  qtInputsItem* m_item;
148  int m_elementIndex;
149  QLineEdit* m_lineWidget;
150 };
151 
152 }; // namespace extension
153 }; // namespace smtk
154 
155 #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::qtIntValidator
Definition: qtInputsItem.h:139
smtk::attribute::ValueItemPtr
smtk::shared_ptr< smtk::attribute::ValueItem > ValueItemPtr
Definition: PublicPointerDefs.h:487
smtk::attribute::StringItemPtr
smtk::shared_ptr< smtk::attribute::StringItem > StringItemPtr
Definition: PublicPointerDefs.h:523
smtk::attribute::IntItemPtr
smtk::shared_ptr< smtk::attribute::IntItem > IntItemPtr
Definition: PublicPointerDefs.h:519
smtk::extension::qtInputsItem
Definition: qtInputsItem.h:35
smtk::extension::qtAttributeItemInfo
Class used to generate widgets for Attribute Items.
Definition: qtAttributeItemInfo.h:39
smtk::extension::qtDoubleValidator
Definition: qtInputsItem.h:125
smtk::extension::qtDiscreteValueEditor
Definition: qtDiscreteValueEditor.h:29
smtk::attribute::ValueItemDefinition
Definition: ValueItemDefinition.h:41
smtk::attribute::ValueItem
A concrete base class for items that store a vector of plain-old-data (POD) as values.
Definition: ValueItem.h:37
smtk::attribute::DoubleItemPtr
smtk::shared_ptr< smtk::attribute::DoubleItem > DoubleItemPtr
Definition: PublicPointerDefs.h:502
qtInputsItemInternals
Definition: qtInputsItem.cxx:214