qtResourceBrowser.h 3.49 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 11 12
#ifndef smtk_extension_qtResourceBrowser_h
#define smtk_extension_qtResourceBrowser_h

13 14 15 16 17 18
#include "smtk/extension/qt/Exports.h"

#include "smtk/PublicPointerDefs.h"

#include <QWidget>

19
class QAbstractItemModel;
20 21 22 23 24 25 26 27
class QItemSelection;
class QTreeView;

namespace smtk
{
namespace extension
{

28 29
class qtDescriptivePhraseModel;

30 31
/**\brief A panel that displays SMTK resources available to the application/user.
  *
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
  * This is a Qt widget that displays a tree or list view holding an SMTK
  * descriptive phrase model.
  *
  * Its constructor accepts
  * (1) an smtk::view::PhraseModel that you have configured,
  * (2) the string name registered to a QAbstractItemView subclass constructor,
  * (3) a QAbstactItemModel implementing qtDescriptivePhraseModel model index queries, and
  * (4) a parent QWidget.
  *
  * This QAbstractItemModel class should either be a
  * qtDescriptivePhraseModel or QAbstractProxyModel whose source is a
  * qtDescriptivePhraseModel.
  * Because of that, indices from the QAbstractItemModel will provide properties
  * that can be used by a qtDescriptivePhraseDelegate instance, which this
  * class creates and owns to control how the tree rows are rendered.
47 48 49 50 51 52 53
  */
class SMTKQTEXT_EXPORT qtResourceBrowser : public QWidget
{
  Q_OBJECT
  typedef QWidget Superclass;

public:
54 55 56
  qtResourceBrowser(const smtk::view::PhraseModelPtr& phraseModel = smtk::view::PhraseModelPtr(),
    const std::string& modelViewName = "", QAbstractItemModel* model = nullptr,
    QWidget* parent = nullptr);
57 58 59
  ~qtResourceBrowser() override;

  static QTreeView* createDefaultView(QWidget* parent);
60
  QTreeView* view() const;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

  smtk::view::PhraseModelPtr phraseModel() const;
  void setPhraseModel(const smtk::view::PhraseModelPtr&);

  smtk::view::SubphraseGeneratorPtr phraseGenerator() const;
  void setPhraseGenerator(smtk::view::SubphraseGeneratorPtr spg);

  bool highlightOnHover() const;
  void setHighlightOnHover(bool highlight);

  void leaveEvent(QEvent*) override;

public slots:
  virtual void sendPanelSelectionToSMTK(
    const QItemSelection& selected, const QItemSelection& deselected);
  virtual void sendSMTKSelectionToPanel(const std::string& src, smtk::view::SelectionPtr seln);

  virtual void addSource(smtk::resource::ManagerPtr rsrcMgr, smtk::operation::ManagerPtr operMgr,
    smtk::view::SelectionPtr seln);
  virtual void removeSource(smtk::resource::ManagerPtr rsrcMgr, smtk::operation::ManagerPtr operMgr,
    smtk::view::SelectionPtr seln);

protected slots:
  virtual void hoverRow(const QModelIndex& idx);
  virtual void resetHover();

  /// Called when the user asks to change the color.
  /// This pops up a color editor dialog, which we can make ParaView-specific if needed
  /// and which can be a "singleton" (i.e., re-use the same dialog so that users do not
  /// accidentally pop up one per descriptive phrase and get confused).
  virtual void editObjectColor(const QModelIndex&);

protected:
  virtual void resetHover(smtk::resource::ComponentSet& add, smtk::resource::ComponentSet& del);

  class Internal;
  Internal* m_p;
};
}
}
101
#endif // smtk_extension_qtResourceBrowser_h