pActionsNodeModel.sip 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*!
  2. \file pActionsNodeModel.h
  3. \brief This class allow to define a hierarchy of pActionsNode that can be exposed in a pActionsNodeMenuBar.
  4. \author Filipe Azevedo aka Nox P\@sNox <pasnox@gmail.com>
  5. */
  6. /*!
  7. \ingroup Gui
  8. \class pActionsNodeModel
  9. \brief This class allow to define a hierarchy of pActionsNode that can be exposed in a pActionsNodeMenuBar.
  10. That allow to have a menu bar that can be easily queried / handled by third party components like plugins.
  11. */
  12. class pActionsNodeModel : QAbstractItemModel
  13. {
  14. %TypeHeaderCode
  15. #include <gui/actionmanager/pActionsNodeModel.h>
  16. %End
  17. public:
  18. /*! This enum defines teh differents columns of the model. */
  19. enum Column {
  20. Action = 0, /*!< The action column. */
  21. Shortcut, /*!< The shortcut column. */
  22. DefaultShortcut /*!< The default shortcut. */
  23. };
  24. /*!
  25. Create a new pActionsNodeModel having parent \a parent.
  26. */
  27. pActionsNodeModel( QObject* parent = 0 );
  28. /*!
  29. Reimplemented from QAbstractItemModel::columnCount().
  30. */
  31. virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const;
  32. /*!
  33. Reimplemented from QAbstractItemModel::data().
  34. */
  35. virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
  36. /*!
  37. Reimplemented from QAbstractItemModel::index().
  38. */
  39. virtual QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const;
  40. /*!
  41. Reimplemented from QAbstractItemModel::parent().
  42. */
  43. virtual QModelIndex parent( const QModelIndex& index ) const;
  44. /*!
  45. Reimplemented from QAbstractItemModel::rowCount().
  46. */
  47. virtual int rowCount( const QModelIndex& parent = QModelIndex() ) const;
  48. /*!
  49. Reimplemented from QAbstractItemModel::hasChildren().
  50. */
  51. virtual bool hasChildren( const QModelIndex& parent = QModelIndex() ) const;
  52. /*!
  53. Reimplemented from QAbstractItemModel::headerData().
  54. */
  55. virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
  56. /*!
  57. Reimplemented from QAbstractItemModel::setData().
  58. */
  59. virtual bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
  60. /*!
  61. return the root node of the model.
  62. */
  63. pActionsNode rootNode() const;
  64. /*!
  65. Return the pActionsNode for the given \a index.
  66. */
  67. pActionsNode indexToNode( const QModelIndex& index ) const;
  68. /*!
  69. Return the pActionsNode for the given \a path.
  70. */
  71. pActionsNode pathToNode( const QString& path ) const;
  72. /*!
  73. Return the pActionsNode for the given \a action.
  74. */
  75. pActionsNode actionToNode( QAction* action ) const;
  76. /*!
  77. Return the QModelIndex for the given \a node.
  78. */
  79. QModelIndex nodeToIndex( const pActionsNode& node ) const;
  80. /*!
  81. Return the QModelIndex for the given \a path.
  82. */
  83. QModelIndex pathToIndex( const QString& path ) const;
  84. /*!
  85. Return the QModelIndex for the given \a action.
  86. */
  87. QModelIndex actionToIndex( QAction* action ) const;
  88. /*!
  89. Clear all nodes of the root node.
  90. The node's QAction are deleted.
  91. */
  92. void clear();
  93. /*!
  94. Add the \a action to the model at the given \a path.
  95. Return true on success else false.
  96. */
  97. bool addAction( const QString& path, QAction* action );
  98. /*!
  99. Add a new action in the model at the given \a path having text \a text and icon \a icon.
  100. Return the created QAction on success else
  101. . */
  102. QAction* addAction( const QString& path, const QString& text, const QIcon& icon = QIcon() );
  103. /*!
  104. Add a path node at the given \a path.
  105. */
  106. pActionsNode addPath( const QString& path );
  107. /*!
  108. Remove the action at the given \a path and delete the path hierarchy if it
  109. contains no more actions and the \a removeEmptyPath parameter is true.
  110. Return true on success else false.
  111. */
  112. bool removeAction( const QString& path, bool removeEmptyPath = false );
  113. /*!
  114. Remove the action \a action and delete the hierarchy if no more actions exists and the \a removeEmptyPath parameter is true.
  115. Return true on success else false.
  116. */
  117. bool removeAction( QAction* action, bool removeEmptyPath = false );
  118. /*!
  119. Remove the path \a path and delete the hierarchy if it contains no more actions and if the \a removeEmptyPath is true.
  120. Return true on success else false.
  121. */
  122. bool removePath( const QString& path, bool removeEmptyPath = false );
  123. signals:
  124. /*!
  125. This signal is emited when the node \a node is inserted.
  126. */
  127. void nodeInserted( const pActionsNode& node );
  128. /*!
  129. This signal is emited when the node \a node is modified.
  130. */
  131. void nodeChanged( const pActionsNode& node );
  132. /*!
  133. This signal is emited when the node \a node is removed.
  134. */
  135. void nodeRemoved( const pActionsNode& node );
  136. /*!
  137. This signal is emited when the model is cleared.
  138. */
  139. void nodesCleared();
  140. };