SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
qtAssociation2ColumnWidget.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 
11 #ifndef smtk_extension_qtAssociation2ColumnWidget_h
12 #define smtk_extension_qtAssociation2ColumnWidget_h
13 
14 #include "smtk/extension/qt/qtAssociationWidget.h"
15 #include <QString>
16 
17 #include "smtk/operation/Observer.h"
18 #include "smtk/operation/Operation.h"
19 #include "smtk/resource/Observer.h"
20 
21 #include <set>
22 
24 class QListWidgetItem;
25 class QListWidget;
26 
27 namespace smtk
28 {
29 namespace extension
30 {
31 class qtBaseView;
32 class SMTKQTEXT_EXPORT qtAssociation2ColumnWidget : public qtAssociationWidget
33 {
34  Q_OBJECT
35 
36 public:
37  qtAssociation2ColumnWidget(QWidget* p, qtBaseView* view);
38  ~qtAssociation2ColumnWidget() override;
39  bool hasSelectedItem() override;
40  // when register the instance with qtSelectionManager, also add the memory address.
41  virtual std::string selectionSourceName() { return m_selectionSourceName; }
42  void leaveEvent(QEvent*) override;
43  bool isValid() const override;
44  void setAllAssociatedMode(bool val) { m_allAssociatedMode = val; }
45  bool allAssociatedMode() const { return m_allAssociatedMode; }
46  void setAllAssociationWarning(const std::string& message)
47  {
48  m_allAssociatedWarning = message.c_str();
49  }
50  void setCurrentLabel(const std::string& message);
51  void setAvailableLabel(const std::string& message);
52  void setTitleLabel(const std::string& message);
53 
54 public Q_SLOTS:
55  // Display the association information to a specific attribute
56  void showEntityAssociation(smtk::attribute::AttributePtr theAtt) override;
57  // Display the association information to a specific definition
58  void showEntityAssociation(smtk::attribute::DefinitionPtr theDef) override;
59  // Refresh the association information for the current attribute. If ignoreResource is specified
60  // the corresponding resource will not participate in determining which object can be associated.
61  // The main use case would be updating the widget because a resource is about to be removed from the
62  // system. Since it is still in memory we needed a way to ignore it
63  virtual void refreshAssociations(
64  const smtk::common::UUID& ignoreResource = smtk::common::UUID::null());
65 
66 protected Q_SLOTS:
67  virtual void onRemoveAssigned();
68  virtual void onAddAvailable();
69  virtual void removeObservers();
70  virtual void hoverRow(const QModelIndex& idx);
71  virtual void resetHover();
72  virtual void highlightOnHoverChanged(bool);
73  virtual void onCurrentItemChanged(QListWidgetItem*, QListWidgetItem*);
74 
75 protected:
76  virtual void initWidget();
77  QList<QListWidgetItem*> getSelectedItems(QListWidget* theList) const;
78  virtual void removeItem(QListWidget*, QListWidgetItem*);
79  smtk::attribute::AttributePtr getAttribute(QListWidgetItem* item);
80  smtk::attribute::AttributePtr getSelectedAttribute(QListWidgetItem*);
81 
82  smtk::resource::PersistentObjectPtr object(QListWidgetItem* item);
83  smtk::resource::PersistentObjectPtr selectedObject(QListWidgetItem*);
84  //returns the Item it has added to the widget
85  //ownership of the item is handled by the widget so no need to delete
86  //for now we append model name to currentList
87  virtual QListWidgetItem* addObjectAssociationListItem(
88  QListWidget* theList,
90  bool sort = true,
91  bool appendModelName = false);
92 
93  //returns the Item it has added to the widget
94  //ownership of the item is handled by the widget so no need to delete
95  virtual QListWidgetItem* addAttributeAssociationItem(
96  QListWidget* theList,
98  bool sort = true);
99 
100  // helper function to update available/current list after selection
101  void updateListItemSelectionAfterChange(QList<QListWidgetItem*> selItems, QListWidget* list);
102 
103  // This widget needs to handle changes made to resources as a result of an operation.
104  // This method is used by the observation mechanism to address these changes
105  int handleOperationEvent(
106  const smtk::operation::Operation& op,
108  smtk::operation::Operation::Result result);
109 
110  // This widget needs to handle changes made to resources as a result of resources being removed.
111  // This method is used by the observation mechanism to address this via the resource manager
112  int handleResourceEvent(
113  const smtk::resource::Resource& resource,
115  // Used to determine if an alert icon should be displayed and why
116  void updateAssociationStatus(const smtk::attribute::Attribute* att);
117 
118  // Sets the validity of the widget
119  void setIsValid(bool val);
120 
121 private:
123  std::string m_selectionSourceName;
124  smtk::operation::Observers::Key m_operationObserverKey;
125  smtk::resource::Observers::Key m_resourceObserverKey;
126  bool m_allAssociatedMode;
127  bool m_isValid;
128  QString m_allAssociatedWarning;
129 
130 }; // class
131 }; // namespace extension
132 }; // namespace smtk
133 
134 #endif
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::attribute::DefinitionPtr
smtk::shared_ptr< smtk::attribute::Definition > DefinitionPtr
Definition: PublicPointerDefs.h:450
smtk::common::Observers::Key
Definition: Observers.h:106
smtk::extension::qtBaseView
A base class for all view types implemented using Qt.
Definition: qtBaseView.h:46
smtk::common::UUID
Definition: UUID.h:38
smtk::extension::qtAssociationWidget
Base class for widgets that deal with attribute associations.
Definition: qtAssociationWidget.h:25
smtk::common::UUID::null
static UUID null()
Generate a nil UUID.
Definition: UUID.cxx:78
smtk::resource::EventType
EventType
Enumerate events that the resource manager may encounter.
Definition: Observer.h:32
smtk::extension::qtAssociation2ColumnWidget
Definition: qtAssociation2ColumnWidget.h:32
smtk::operation::Operation
Operation is a base class for all SMTK operations.
Definition: Operation.h:51
qtAssociation2ColumnWidgetInternals
Definition: qtAssociation2ColumnWidget.cxx:69
smtk::attribute::AttributePtr
smtk::shared_ptr< smtk::attribute::Attribute > AttributePtr
Definition: PublicPointerDefs.h:456
smtk::resource::Resource
An abstract base class for SMTK resources.
Definition: Resource.h:59
smtk::attribute::Attribute
Represent a (possibly composite) value according to a definition.
Definition: Attribute.h:49
smtk::resource::PersistentObjectPtr
smtk::shared_ptr< smtk::resource::PersistentObject > PersistentObjectPtr
Definition: PublicPointerDefs.h:285
smtk::operation::EventType
EventType
Enumerate events that an operation may encounter.
Definition: Observer.h:30