1 | /* $Id: QITableView.h 76532 2018-12-30 06:08:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QITableView class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2018 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 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QTableView>
|
---|
26 |
|
---|
27 | /* GUI includes: */
|
---|
28 | #include "UILibraryDefs.h"
|
---|
29 |
|
---|
30 | /* Forward declarations: */
|
---|
31 | class QITableViewCell;
|
---|
32 | class QITableViewRow;
|
---|
33 | class QITableView;
|
---|
34 |
|
---|
35 |
|
---|
36 | /** OObject subclass used as cell for the QITableView. */
|
---|
37 | class SHARED_LIBRARY_STUFF QITableViewCell : public QObject
|
---|
38 | {
|
---|
39 | Q_OBJECT;
|
---|
40 |
|
---|
41 | public:
|
---|
42 |
|
---|
43 | /** Constructs table-view cell for passed @a pParent. */
|
---|
44 | QITableViewCell(QITableViewRow *pParent)
|
---|
45 | : m_pRow(pParent)
|
---|
46 | {}
|
---|
47 |
|
---|
48 | /** Defines the parent @a pRow reference. */
|
---|
49 | void setRow(QITableViewRow *pRow) { m_pRow = pRow; }
|
---|
50 | /** Returns the parent row reference. */
|
---|
51 | QITableViewRow *row() const { return m_pRow; }
|
---|
52 |
|
---|
53 | /** Returns the cell text. */
|
---|
54 | virtual QString text() const = 0;
|
---|
55 |
|
---|
56 | private:
|
---|
57 |
|
---|
58 | /** Holds the parent row reference. */
|
---|
59 | QITableViewRow *m_pRow;
|
---|
60 | };
|
---|
61 |
|
---|
62 |
|
---|
63 | /** OObject subclass used as row for the QITableView. */
|
---|
64 | class SHARED_LIBRARY_STUFF QITableViewRow : public QObject
|
---|
65 | {
|
---|
66 | Q_OBJECT;
|
---|
67 |
|
---|
68 | public:
|
---|
69 |
|
---|
70 | /** Constructs table-view row for passed @a pParent. */
|
---|
71 | QITableViewRow(QITableView *pParent)
|
---|
72 | : m_pTable(pParent)
|
---|
73 | {}
|
---|
74 |
|
---|
75 | /** Defines the parent @a pTable reference. */
|
---|
76 | void setTable(QITableView *pTable) { m_pTable = pTable; }
|
---|
77 | /** Returns the parent table reference. */
|
---|
78 | QITableView *table() const { return m_pTable; }
|
---|
79 |
|
---|
80 | /** Returns the number of children. */
|
---|
81 | virtual int childCount() const = 0;
|
---|
82 | /** Returns the child item with @a iIndex. */
|
---|
83 | virtual QITableViewCell *childItem(int iIndex) const = 0;
|
---|
84 |
|
---|
85 | private:
|
---|
86 |
|
---|
87 | /** Holds the parent table reference. */
|
---|
88 | QITableView *m_pTable;
|
---|
89 | };
|
---|
90 |
|
---|
91 |
|
---|
92 | /** QTableView subclass extending standard functionality. */
|
---|
93 | class SHARED_LIBRARY_STUFF QITableView : public QTableView
|
---|
94 | {
|
---|
95 | Q_OBJECT;
|
---|
96 |
|
---|
97 | signals:
|
---|
98 |
|
---|
99 | /** Notifies listeners about index changed from @a previous to @a current. */
|
---|
100 | void sigCurrentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
---|
101 |
|
---|
102 | public:
|
---|
103 |
|
---|
104 | /** Constructs table-view passing @a pParent to the base-class. */
|
---|
105 | QITableView(QWidget *pParent = 0);
|
---|
106 | /** Destructs table-view. */
|
---|
107 | virtual ~QITableView() /* override */;
|
---|
108 |
|
---|
109 | /** Returns the number of children. */
|
---|
110 | virtual int childCount() const { return 0; }
|
---|
111 | /** Returns the child item with @a iIndex. */
|
---|
112 | virtual QITableViewRow *childItem(int /* iIndex */) const { return 0; }
|
---|
113 |
|
---|
114 | /** Makes sure current editor data committed. */
|
---|
115 | void makeSureEditorDataCommitted();
|
---|
116 |
|
---|
117 | protected slots:
|
---|
118 |
|
---|
119 | /** Stores the created @a pEditor for passed @a index in the map. */
|
---|
120 | virtual void sltEditorCreated(QWidget *pEditor, const QModelIndex &index);
|
---|
121 | /** Clears the destoyed @a pEditor from the map. */
|
---|
122 | virtual void sltEditorDestroyed(QObject *pEditor);
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | /** Handles index change from @a previous to @a current. */
|
---|
127 | virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) /* override */;
|
---|
128 |
|
---|
129 | private:
|
---|
130 |
|
---|
131 | /** Prepares all. */
|
---|
132 | void prepare();
|
---|
133 | /** Cleanups all. */
|
---|
134 | void cleanup();
|
---|
135 |
|
---|
136 | /** Holds the map of editors stored for passed indexes. */
|
---|
137 | QMap<QModelIndex, QObject*> m_editors;
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 | #endif /* !___QITableView_h___ */
|
---|