Kross

actioncollectionview.h
1 /***************************************************************************
2  * actioncollectionview.h
3  * This file is part of the KDE project
4  * copyright (c) 2005-2006 Cyrille Berger <[email protected]>
5  * copyright (C) 2006-2007 Sebastian Sauer <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  * You should have received a copy of the GNU Library General Public License
16  * along with this program; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  ***************************************************************************/
20 
21 #ifndef KROSS_VIEW_H
22 #define KROSS_VIEW_H
23 
24 #include <kross/ui/krossui_export.h>
25 
26 #include <QObject>
27 #include <QWidget>
28 #include <QModelIndex>
29 #include <QItemSelection>
30 #include <QTreeView>
31 
32 class KLineEdit;
33 class QComboBox;
34 class QPushButton;
35 class QItemSelection;
36 class KActionCollection;
37 class KUrlRequester;
38 
39 namespace Kross
40 {
41 
42 class Action;
43 class ActionCollection;
44 
45 /**
46 * The ActionCollectionEditor class implements a general editor
47 * for \a Action and \a ActionCollection instances.
48 *
49 * Example that shows how to display the editor with an \a Action ;
50 * \code
51 * KDialog d(this);
52 * Action* a = new Action();
53 * new ActionCollectionEditor(a, d.mainWidget());
54 * d.exec();
55 * \endcode
56 *
57 * Example that shows how to display the editor with an \a ActionCollection ;
58 * \code
59 * KDialog d(this);
60 * ActionCollection* c = new ActionCollection();
61 * new ActionCollectionEditor(c, d.mainWidget());
62 * d.exec();
63 * \endcode
64 */
65 class KROSSUI_EXPORT ActionCollectionEditor : public QWidget
66 {
67 public:
68 
69  /**
70  * Constructor.
71  * \param action The \a Action instance this editor should
72  * operate on.
73  * \param parent The optional parent widget this widget is child of.
74  */
75  explicit ActionCollectionEditor(Action *action, QWidget *parent = nullptr);
76 
77  /**
78  * Constructor.
79  * \param collection The \a ActionCollection instance this
80  * editor should operate on.
81  * \param parent The optional parent widget this widget is child of.
82  */
83  explicit ActionCollectionEditor(ActionCollection *collection, QWidget *parent = nullptr);
84 
85  /**
86  * Destructor.
87  */
88  ~ActionCollectionEditor() override;
89 
90  /**
91  * \return the \a Action instance this editor operates on or
92  * NULL if this editor does not operate on a \a Action instance.
93  */
94  Action *action() const;
95 
96  /**
97  * \return the \a ActionCollection instance this editor operates on or
98  * NULL if this editor does not operate on a \a ActionCollection instance.
99  */
100  ActionCollection *collection() const;
101 
102  /**
103  * \return true if the values within the editor fields are valid.
104  */
105  virtual bool isValid();
106 
107  /**
108  * This method got called if the changes done in the editor
109  * should be saved aka committed to the \a Action or
110  * \a ActionCollection instance.
111  */
112  virtual void commit();
113 
114  /**
115  * Following getters are providing access to the edit-widgets once the
116  * \a initGui() was called by the constructors. Some widgets like e.g.
117  * the \a fileEdit() may return NULL if they are not used / displayed
118  * (what is for the fileEdit the case if this \a ActionCollectionEditor
119  * instance has no \a Action ).
120  */
121  QLineEdit *nameEdit() const;
122  QLineEdit *textEdit() const;
123  QLineEdit *commentEdit() const;
124  QLineEdit *iconEdit() const;
125  QComboBox *interpreterEdit() const;
126  KUrlRequester *fileEdit() const;
127 
128 protected:
129 
130  /**
131  * Initialize the GUI. Called by the both constructors and does
132  * create e.g. the \a nameEdit() and the \a textEdit() widgets.
133  */
134  virtual void initGui();
135 
136 private:
137  /// \internal d-pointer class.
138  class Private;
139  /// \internal d-pointer instance.
140  Private *const d;
141 };
142 
143 /**
144 * The ActionCollectionView class shows a QTreeView where the content of a
145 * \a ActionCollection is displayed and optional actions to run, stop,
146 * add, edit and remove scripts are provided.
147 *
148 * Example how to create, fill and use an instance of a ActionCollectionView;
149 * \code
150 * // We like to show the widget in a dialog.
151 * KDialog d(this);
152 * // Create the view.
153 * ActionCollectionView* v = new ActionCollectionView( d.mainWidget() );
154 * // Create the model.
155 * ActionCollectionModel::Mode mode( ActionCollectionModel::Icons | ActionCollectionModel::ToolTips | ActionCollectionModel::UserCheckable );
156 * ActionCollectionModel* m = new ActionCollectionModel(view, Manager::self().actionCollection(), mode);
157 * // Set the model the view should use.
158 * v->setModel(m);
159 * // Show the dialog.
160 * d.exec();
161 * \endcode
162 */
163 class KROSSUI_EXPORT ActionCollectionView : public QTreeView
164 {
165  Q_OBJECT
166 public:
167 
168  /**
169  * Constructor.
170  * \param parent The optional parent widget this widget is child of.
171  */
172  explicit ActionCollectionView(QWidget *parent = nullptr);
173 
174  /**
175  * Destructor.
176  */
177  ~ActionCollectionView() override;
178 
179  /**
180  * Set the model this view should use to \p model . Use an instance of
181  * \a ActionCollectionModel or \a ActionCollectionProxyModel as model.
182  */
183  void setModel(QAbstractItemModel *model) override;
184 
185  /**
186  * \return true if the collection was modified.
187  */
188  bool isModified() const;
189 
190  /**
191  * Set the internal modified state of the collection to \p modified .
192  */
193  void setModified(bool modified);
194 
195  /**
196  * \return the KActionCollection which is filled with KAction
197  * instances this view provides. Per default there are the
198  * actions "run" to run a script, "stop" to stop execution, "edit"
199  * to edit the selected item, "add" to add a new item or resource,
200  * "remove" to remove the selected item and "manager" to call and
201  * show the modal Script Manager dialog.
202  */
203  KActionCollection *actionCollection() const;
204 
205  /**
206  * \return the QPushButton instance which has the actionname \p actionname
207  * or NULL if there is not such button.
208  */
209  QPushButton *button(const QString &actionname) const;
210 
211  /**
212  * Create and return a new QPushButton instance for the given actionname.
213  * \param parentWidget The parent widget.
214  * \param actionname The name of the action. Each button points to an action
215  * from within the \a actionCollection() and triggers that action if the
216  * button got clicked.
217  * \return The new QPushButton instance or NULL if e.g. there exist no
218  * such action with \p actionname .
219  */
220  QPushButton *createButton(QWidget *parentWidget, const QString &actionname);
221 
222 public Q_SLOTS:
223 
224  /**
225  * Called if the "run" action was triggered and the selected script
226  * should be executed.
227  */
228  virtual void slotRun();
229 
230  /**
231  * Called if the "stop" action was triggered and the selected script
232  * stops execution if running.
233  */
234  virtual void slotStop();
235 
236  /**
237  * Called if the "edit" action was triggered and the select item should
238  * be edited via the scripts manager editor dialog.
239  */
240  virtual void slotEdit();
241 
242  /**
243  * Called if the "add" action was triggered and a new item should be added.
244  */
245  virtual void slotAdd();
246 
247  /**
248  * Called if the "remove" action was triggered and the selected item
249  * should be removed.
250  */
251  virtual void slotRemove();
252 
253 Q_SIGNALS:
254 
255  /**
256  * This signal is emitted if the enabled/disabled state of an action
257  * changed. This happens for example if the slotSelectionChanged() above
258  * got called cause another item was selected.
259  * \param actionname The name of the action that changed. You are able
260  * to use \a actionCollection() to receive the to the name matching
261  * \a KAction instance. You are able to use e.g. a QSignalMapper here to
262  * map such changes direct to your e.g. \a QPushButton instances used
263  * to display some of the actions provided with \a actionCollection() .
264  */
265  void enabledChanged(const QString &actionname);
266 
267 protected Q_SLOTS:
268 
269  /**
270  * This slot got called if the data changed.
271  */
272  virtual void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
273 
274  /**
275  * This slot got called if the enable/disable state of an action changed.
276  */
277  virtual void slotEnabledChanged(const QString &actionname);
278 
279  /**
280  * This slot got called if the selected item changed.
281  */
282  virtual void slotSelectionChanged();
283 
284 protected:
285 
286  /**
287  * This method provides us access to the QItemSelection. Compared to
288  * the selectionModel()->selection() method this method does also
289  * map the selection to the source-model for the case e.g. the
290  * \a ActionCollectionProxyModel proxy-model was used rather then
291  * a \a ActionCollectionModel direct.
292  */
293  QItemSelection itemSelection() const;
294 
295 private:
296  /// \internal d-pointer class.
297  class Private;
298  /// \internal d-pointer instance.
299  Private *const d;
300 };
301 
302 }
303 
304 #endif
The ActionCollectionView class shows a QTreeView where the content of a ActionCollection is displayed...
The ActionCollectionEditor class implements a general editor for Action and ActionCollection instance...
The Action class is an abstract container to deal with scripts like a single standalone script file.
Definition: action.h:112
The ActionCollection class manages collections of Action instances.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 04:03:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.