1 | /* $Id: QITableView.h 71027 2018-02-15 14:33:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QITableView class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___QITableView_h___
|
---|
19 | #define ___QITableView_h___
|
---|
20 |
|
---|
21 | /* Qt includes: */
|
---|
22 | #include <QTableView>
|
---|
23 |
|
---|
24 | /* Forward declarations: */
|
---|
25 | class QITableViewCell;
|
---|
26 | class QITableViewRow;
|
---|
27 | class QITableView;
|
---|
28 |
|
---|
29 |
|
---|
30 | /** OObject subclass used as cell for the QITableView. */
|
---|
31 | class QITableViewCell : public QObject
|
---|
32 | {
|
---|
33 | Q_OBJECT;
|
---|
34 |
|
---|
35 | public:
|
---|
36 |
|
---|
37 | /** Constructs table-view cell for passed @a pParent. */
|
---|
38 | QITableViewCell(QITableViewRow *pParent)
|
---|
39 | : m_pRow(pParent)
|
---|
40 | {}
|
---|
41 |
|
---|
42 | /** Defines the parent @a pRow reference. */
|
---|
43 | void setRow(QITableViewRow *pRow) { m_pRow = pRow; }
|
---|
44 | /** Returns the parent row reference. */
|
---|
45 | QITableViewRow *row() const { return m_pRow; }
|
---|
46 |
|
---|
47 | /** Returns the cell text. */
|
---|
48 | virtual QString text() const = 0;
|
---|
49 |
|
---|
50 | private:
|
---|
51 |
|
---|
52 | /** Holds the parent row reference. */
|
---|
53 | QITableViewRow *m_pRow;
|
---|
54 | };
|
---|
55 |
|
---|
56 |
|
---|
57 | /** OObject subclass used as row for the QITableView. */
|
---|
58 | class QITableViewRow : public QObject
|
---|
59 | {
|
---|
60 | Q_OBJECT;
|
---|
61 |
|
---|
62 | public:
|
---|
63 |
|
---|
64 | /** Constructs table-view row for passed @a pParent. */
|
---|
65 | QITableViewRow(QITableView *pParent)
|
---|
66 | : m_pTable(pParent)
|
---|
67 | {}
|
---|
68 |
|
---|
69 | /** Defines the parent @a pTable reference. */
|
---|
70 | void setTable(QITableView *pTable) { m_pTable = pTable; }
|
---|
71 | /** Returns the parent table reference. */
|
---|
72 | QITableView *table() const { return m_pTable; }
|
---|
73 |
|
---|
74 | /** Returns the number of children. */
|
---|
75 | virtual int childCount() const = 0;
|
---|
76 | /** Returns the child item with @a iIndex. */
|
---|
77 | virtual QITableViewCell *childItem(int iIndex) const = 0;
|
---|
78 |
|
---|
79 | private:
|
---|
80 |
|
---|
81 | /** Holds the parent table reference. */
|
---|
82 | QITableView *m_pTable;
|
---|
83 | };
|
---|
84 |
|
---|
85 |
|
---|
86 | /** QTableView subclass extending standard functionality. */
|
---|
87 | class QITableView : public QTableView
|
---|
88 | {
|
---|
89 | Q_OBJECT;
|
---|
90 |
|
---|
91 | signals:
|
---|
92 |
|
---|
93 | /** Notifies listeners about index changed from @a previous to @a current. */
|
---|
94 | void sigCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
---|
95 |
|
---|
96 | public:
|
---|
97 |
|
---|
98 | /** Constructs table-view passing @a pParent to the base-class. */
|
---|
99 | QITableView(QWidget *pParent = 0);
|
---|
100 | /** Destructs table-view. */
|
---|
101 | virtual ~QITableView() /* override */;
|
---|
102 |
|
---|
103 | /** Returns the number of children. */
|
---|
104 | virtual int childCount() const { return 0; }
|
---|
105 | /** Returns the child item with @a iIndex. */
|
---|
106 | virtual QITableViewRow *childItem(int /* iIndex */) const { return 0; }
|
---|
107 |
|
---|
108 | /** Makes sure current editor data committed. */
|
---|
109 | void makeSureEditorDataCommitted();
|
---|
110 |
|
---|
111 | protected slots:
|
---|
112 |
|
---|
113 | /** Stores the created @a pEditor for passed @a index in the map. */
|
---|
114 | virtual void sltEditorCreated(QWidget *pEditor, const QModelIndex &index);
|
---|
115 | /** Clears the destoyed @a pEditor from the map. */
|
---|
116 | virtual void sltEditorDestroyed(QObject *pEditor);
|
---|
117 |
|
---|
118 | protected:
|
---|
119 |
|
---|
120 | /** Handles index change from @a previous to @a current. */
|
---|
121 | virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) /* override */;
|
---|
122 |
|
---|
123 | private:
|
---|
124 |
|
---|
125 | /** Prepares all. */
|
---|
126 | void prepare();
|
---|
127 | /** Cleanups all. */
|
---|
128 | void cleanup();
|
---|
129 |
|
---|
130 | /** Holds the map of editors stored for passed indexes. */
|
---|
131 | QMap<QModelIndex, QObject*> m_editors;
|
---|
132 | };
|
---|
133 |
|
---|
134 | #endif /* !___QITableView_h___ */
|
---|
135 |
|
---|