qtBaseView.h 5.44 KB
Newer Older
1 2 3 4 5 6 7 8 9
//=========================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//=========================================================================
10
// .NAME qtBaseView - a base class for all view types
11 12
// .SECTION Description

Bob Obara's avatar
Bob Obara committed
13 14
#ifndef __smtk_extension_qtBaseView_h
#define __smtk_extension_qtBaseView_h
15

16 17 18 19
#include <QtCore/QList>
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtWidgets/QLayout>
20

21
#include "smtk/PublicPointerDefs.h"
22
#include "smtk/extension/qt/Exports.h"
23
#include "smtk/extension/qt/qtViewInfoDialog.h"
24

25
class qtBaseViewInternals;
26
class QScrollArea;
27

28
namespace smtk
29
{
30 31 32 33
namespace extension
{
class qtUIManager;
class qtItem;
34
class qtViewInfoDialog;
35 36 37 38 39

// This struct is used to initialize qtView-based classes
class SMTKQTEXT_EXPORT ViewInfo
{
public:
40
  ViewInfo(smtk::view::ViewPtr view, QWidget* parent, qtUIManager* uiman)
41 42 43 44 45 46
    : m_view(view)
    , m_parent(parent)
    , m_UIManager(uiman)
  {
  }

47
  ViewInfo(smtk::view::ViewPtr view, QWidget* parent, qtUIManager* uiman,
48 49 50 51 52 53 54 55 56 57 58
    const std::map<std::string, QLayout*>& layoutDict)
    : m_view(view)
    , m_parent(parent)
    , m_UIManager(uiman)
    , m_layoutDict(layoutDict)
  {
  }

  ViewInfo() {}
  virtual ~ViewInfo() {}

59
  smtk::view::ViewPtr m_view;                   // View Definition
60 61 62 63 64 65 66 67 68 69 70
  QWidget* m_parent;                            // Parent Widget of the View
  qtUIManager* m_UIManager;                     // UI Manager
  std::map<std::string, QLayout*> m_layoutDict; // Widget Layout Dictionary
};

class SMTKQTEXT_EXPORT qtBaseView : public QObject
{
  Q_OBJECT

public:
  qtBaseView(const ViewInfo& info);
71
  ~qtBaseView() override;
72

73
  smtk::view::ViewPtr getObject() const { return m_viewInfo.m_view; }
74
  QWidget* widget() const { return this->Widget; }
75 76
  QWidget* parentWidget() const { return m_viewInfo.m_parent; }
  qtUIManager* uiManager() const { return m_viewInfo.m_UIManager; }
77 78 79 80 81 82 83 84 85 86

  // Description:
  // Determines if an item should be displayed
  virtual bool displayItem(smtk::attribute::ItemPtr);
  virtual void getDefinitions(
    smtk::attribute::DefinitionPtr attDef, QList<smtk::attribute::DefinitionPtr>& defs);
  int fixedLabelWidth() { return m_fixedLabelWidth; }

  bool setFixedLabelWidth(int w);
  bool advanceLevelVisible() { return m_advOverlayVisible; }
87
  bool useSelectionManager() const { return m_useSelectionManager; }
88

89 90 91
  virtual int advanceLevel();
  virtual bool categoryEnabled();
  virtual std::string currentCategory();
92 93 94 95 96
  // When category filtering is requested to be either on by default or is requested to be
  // on permanently, we need to have a mechanism to force the views to display info based on
  // the initial category.  This method will check to see if this is the case and call the
  // onShowCategory method
  void setInitialCategory();
97

98
  bool isTopLevel() const { return m_isTopLevel; }
99

100 101 102 103
  //Returns true if the view does not contain any information to display - the default
  // behavior is to return false
  virtual bool isEmpty() const;

104 105
signals:
  void modified(smtk::attribute::ItemPtr);
106
  void aboutToDestroy();
107 108 109

public slots:
  virtual void updateUI()
110
  {
111 112 113 114 115 116
    this->updateAttributeData();
    this->updateModelAssociation();
    this->showAdvanceLevelOverlay(m_advOverlayVisible);
  }
  virtual void updateModelAssociation() { ; }
  virtual void valueChanged(smtk::attribute::ItemPtr);
117 118 119 120 121 122
  /// Invoke the Signal dummy operation to indicate an attribute has been created.
  virtual void attributeCreated(const smtk::attribute::AttributePtr&);
  /// Invoke the Signal dummy operation to indicate an attribute has been changed (renamed).
  virtual void attributeChanged(const smtk::attribute::AttributePtr&);
  /// Invoke the Signal dummy operation to indicate an attribute has been removed.
  virtual void attributeRemoved(const smtk::attribute::AttributePtr&);
123 124 125 126 127
  virtual void childrenResized() { ; }
  virtual void showAdvanceLevelOverlay(bool val) { m_advOverlayVisible = val; }
  virtual void showAdvanceLevel(int i);
  virtual void updateViewUI(int /* currentTab */) {}
  virtual void enableShowBy(int /* enable */);
128 129
  virtual void onInfo(); /* for displaying View Information */

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  virtual void onShowCategory() {}

  virtual void requestModelEntityAssociation() { ; }

protected slots:
  virtual void updateAttributeData() { ; }
  virtual void onAdvanceLevelChanged(int levelIdx);

protected:
  // Description:
  // Creates the UI related to the view and properly assigns it
  // to the parent widget.
  virtual void buildUI();
  // Description:
  // Creates the main QT Widget that is associated with a View.  Typically this
  // is the only method a derived View needs to override.
  virtual void createWidget() {}

  // Description:
  // Adds properties associated with respects to a top level view
  virtual void makeTopLevel();

152 153 154 155
  // Description:
  // Set the information to be displayed in the ViewInfoDialog
  virtual void setInfoToBeDisplayed();

156 157 158 159
  QWidget* Widget;
  QScrollArea* m_ScrollArea;
  bool m_isTopLevel;
  bool m_topLevelInitialized;
160
  bool m_useSelectionManager;
161
  ViewInfo m_viewInfo;
162
  QPointer<qtViewInfoDialog> m_infoDialog;
163 164 165 166 167 168 169 170

private:
  bool m_advOverlayVisible;
  int m_fixedLabelWidth;
  qtBaseViewInternals* Internals;

}; // class
}; // namespace attribute
171
}; // namespace smtk
172 173

#endif