1 /*
2   propertywidget.h
3 
4   This file is part of GammaRay, the Qt application inspection and
5   manipulation tool.
6 
7   Copyright (C) 2010-2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8   Author: Volker Krause <volker.krause@kdab.com>
9 
10   Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11   accordance with GammaRay Commercial License Agreement provided with the Software.
12 
13   Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 
15   This program is free software; you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation, either version 2 of the License, or
18   (at your option) any later version.
19 
20   This program is distributed in the hope that it will be useful,
21   but WITHOUT ANY WARRANTY; without even the implied warranty of
22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   GNU General Public License for more details.
24 
25   You should have received a copy of the GNU General Public License
26   along with this program.  If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #ifndef GAMMARAY_PROPERTYWIDGET_H
30 #define GAMMARAY_PROPERTYWIDGET_H
31 
32 #include <QTabWidget>
33 #include <QPointer>
34 #include <QHash>
35 
36 #include "gammaray_ui_export.h"
37 #include "propertywidgettab.h"
38 
39 QT_BEGIN_NAMESPACE
40 class QAbstractItemModel;
41 class QAbstractItemView;
42 class QModelIndex;
43 class QTimer;
44 QT_END_NAMESPACE
45 
46 namespace GammaRay {
47 class Ui_PropertyWidget;
48 class PropertyControllerInterface;
49 
50 /** @brief Client-side counter-part GammaRay::PropertyController. */
51 class GAMMARAY_UI_EXPORT PropertyWidget : public QTabWidget
52 {
53     Q_OBJECT
54 public:
55     explicit PropertyWidget(QWidget *parent = nullptr);
56     virtual ~PropertyWidget();
57 
58     QString objectBaseName() const;
59     void setObjectBaseName(const QString &baseName);
60 
61     /** Register a new tab widget factory.
62      * @tparam T A widget type providing the tab UI
63      * @param name The internal object name of this extension.
64      * @param label The user-visible tab label of this extension.
65      * @param priority This is used to keep tabs in a stable order, tabs are ordered
66      *   left to right with increasing priority.
67      */
68     template<typename T> static void registerTab(const QString &name, const QString &label,
69                                                  int priority = 1000)
70     {
71         registerTab(new PropertyWidgetTabFactory<T>(name, label, priority));
72     }
73 
74     //! \internal
75     static void cleanupTabs();
76 signals:
77     void tabsUpdated();
78 
79 private:
80     static void registerTab(PropertyWidgetTabFactoryBase *factory);
81     void createWidgets();
82     bool extensionAvailable(PropertyWidgetTabFactoryBase *factory) const;
83     bool factoryInUse(PropertyWidgetTabFactoryBase *factory) const;
84 
85 private slots:
86     void updateShownTabs();
87     void slotCurrentTabChanged();
88 
89 private:
90     QString m_objectBaseName;
91 
92     QTimer *m_tabsUpdatedTimer;
93     QWidget *m_lastManuallySelectedWidget;
94 
95     struct PageInfo {
96         PropertyWidgetTabFactoryBase *factory;
97         QWidget *widget;
98     };
99     QVector<PageInfo> m_pages;
100 
101     PropertyControllerInterface *m_controller;
102 
103     static QVector<PropertyWidgetTabFactoryBase *> s_tabFactories;
104     static QVector<PropertyWidget *> s_propertyWidgets;
105 };
106 }
107 
108 #endif // GAMMARAY_PROPERTYWIDGET_H
109