1 /***************************************************************************
2                           rkobjectlistview  -  description
3                              -------------------
4     begin                : Wed Sep 1 2004
5     copyright            : (C) 2004-2015 by Thomas Friedrichsmeier
6     email                : thomas.friedrichsmeier@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #ifndef RKOBJECTLISTVIEW_H
18 #define RKOBJECTLISTVIEW_H
19 
20 #include <QTreeView>
21 #include <QSortFilterProxyModel>
22 
23 #include "../settings/rksettings.h"
24 #include "../core/robject.h"
25 
26 class QMenu;
27 class RKListViewItem;
28 class RKObjectListViewSettings;
29 class QTimer;
30 class QCheckBox;
31 class QComboBox;
32 class QPushButton;
33 class RKDynamicSearchLine;
34 
35 /**
36 This class provides the common functionality for the tree views in the RObjectBrowser and RKVarselector(s). The caps it (will) provide are: keeping the list up to date and emitting change-signals when appropriate, filtering for certain types of objects, sorting, mapping items to objects. Maybe some GUI-stuff like popup-menus should also be added to this class?
37 
38 @author Thomas Friedrichsmeier
39 */
40 class RKObjectListView : public QTreeView {
41 	Q_OBJECT
42 public:
43 	explicit RKObjectListView (bool toolwindow, QWidget *parent);
44 	~RKObjectListView ();
45 
46 /** This function returns a pointer to the context menu of the RKObjectListView. It is provided so you can add your own items.
47 @returns a pointer to the context menu
48 @see aboutToShowContextMenu */
contextMenu()49 	QMenu *contextMenu () { return menu; };
50 /** This function returns the RObject the context menu has last been invoked on (or 0 if not invoked on an RObject). You can use this in slots called
51 from your custom menu items, to figure out, which object you should operate on. */
menuObject()52 	RObject *menuObject () const { return menu_object; };
53 
getSettings()54 	RKObjectListViewSettings *getSettings () { return settings; };
55 
56 /** Scrolls so that the item representing object becomes visible, and makes it current */
57 	void setObjectCurrent (RObject *object, bool only_if_none_current=false);
58 	void setRootObject (RObject *root);
59 
60 	RObject::ObjectList selectedObjects () const;
61 
62 	RObject* objectAtIndex (const QModelIndex& index) const;
63 /** Takes care initializing the RKObjectListView */
64 	void initialize ();
65 signals:
66 	void selectionChanged ();
67 /** This signal is emitted just before the context-menu is shown. If you connect to this signal, you can make some adjustments to the context-menu.
68 If you set *suppress to true, showing the context menu will be suppressed. */
69 	void aboutToShowContextMenu (RObject *object, bool *suppress);
70 public slots:
71 	void updateComplete ();
72 	void updateStarted ();
73 	void selectionChanged (const QItemSelection & selected, const QItemSelection & deselected) override;
74 	void settingsChanged ();
75 	void itemClicked (const QModelIndex& index);
76 protected:
77 	void contextMenuEvent (QContextMenuEvent* event) override;
78 private:
79 	QMenu *menu;
80 	RObject *menu_object;
81 	RObject *root_object;
82 friend class RKObjectListViewRootDelegate;
83 	QAbstractItemDelegate *rkdelegate;
84 	RKObjectListViewSettings *settings;
85 };
86 
87 /** Does filtering for an RKObjectListView. Should probably be renamed to RKObjectListViewFilter */
88 class RKObjectListViewSettings : public QSortFilterProxyModel {
89 	Q_OBJECT
90 public:
91 /** ctor. copies the default settings from RKSettingsModuleObjectBrowser */
92 	explicit RKObjectListViewSettings (bool toolwindow, QObject* parent=0);
93 	~RKObjectListViewSettings ();
94 
95 /** enum of @em persistent settings. There are more settings than these, but those will not be stored */
96 	enum PersistentSettings {
97 		ShowObjectsHidden,
98 		ShowFieldsType,
99 		ShowFieldsClass,
100 		ShowFieldsLabel,
101 		SettingsCount
102 	};
103 
104 	void addSettingsToMenu (QMenu* menu, QAction* before);
105 
106 	QWidget* filterWidget (QWidget *parent);
107 signals:
108 	void settingsChanged ();
109 public slots:
110 	void filterSettingsChanged ();
111 	void updateSelfNow ();
112 	void resetFilters ();
113 protected:
114 	bool filterAcceptsRow (int source_row, const QModelIndex& source_parent) const override;
115 	bool acceptRow (int source_row, const QModelIndex& source_parent) const;
116 	bool filterAcceptsColumn (int source_column, const QModelIndex& source_parent) const override;
117 	bool lessThan (const QModelIndex& left, const QModelIndex& right) const override;
118 private:
119 	QAction* persistent_settings_actions[SettingsCount];
120 	bool persistent_settings[SettingsCount];
121 
122 	void updateSelf ();
123 
124 	QWidget *filter_widget;
125 	RKDynamicSearchLine *sline;
126 	QWidget *filter_widget_expansion;
127 	QCheckBox* filter_on_name_box;
128 	QCheckBox* filter_on_label_box;
129 	QCheckBox* filter_on_class_box;
130 	bool filter_on_name;
131 	bool filter_on_label;
132 	bool filter_on_class;
133 	QComboBox* depth_box;
134 	int depth_limit;
135 	QComboBox* type_box;
136 	bool hide_functions;
137 	bool hide_non_functions;
138 	QPushButton* reset_filters_button;
139 	bool in_reset_filters;
140 
141 	bool is_tool_window;
142 
143 	QTimer *update_timer;
144 };
145 
146 #endif
147