~ubuntu-branches/ubuntu/vivid/regina-normal/vivid-proposed

« back to all changes in this revision

Viewing changes to kdeui/src/part/packettreeview.h

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2011-09-10 07:17:25 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: package-import@ubuntu.com-20110910071725-97n90tywdq60w2cr
Tags: 4.90-1
* New upstream release!
* The user interface has been ported from KDE3 to KDE4 (closes: #556318).
  Re-enabled the GUI as a result.
* The build system has been ported from autotools to cmake.
* The new upstream release builds fine on amd64 (closes: #624882).
* Moved the users' handbook into regina-normal-doc.
* Upgraded several suggests/recommends.  Upgraded regina-normal-mpi to
  depend on mpi-default-bin, and regina-normal to depend on both graphviz
  and regina-normal-doc (which the GUI expends to be present).  Upgraded
  regina-normal to recommend gap.
* Bumped standards-version to 3.9.2.0 (no changes required).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *  Regina - A Normal Surface Theory Calculator                           *
5
5
 *  KDE User Interface                                                    *
6
6
 *                                                                        *
7
 
 *  Copyright (c) 1999-2009, Ben Burton                                   *
 
7
 *  Copyright (c) 1999-2011, Ben Burton                                   *
8
8
 *  For further details contact Ben Burton (bab@debian.org).              *
9
9
 *                                                                        *
10
10
 *  This program is free software; you can redistribute it and/or         *
35
35
 
36
36
#include "packet/npacketlistener.h"
37
37
 
38
 
#include <klistview.h>
 
38
#include <QtGui/QTreeWidget>
 
39
#include <QtGui/QTreeWidgetItem>
 
40
 
39
41
 
40
42
class PacketTreeView;
41
43
class ReginaPart;
47
49
/**
48
50
 * A single item in a Regina packet tree.
49
51
 */
50
 
class PacketTreeItem : public KListViewItem, public regina::NPacketListener {
 
52
class PacketTreeItem : public QTreeWidgetItem, public regina::NPacketListener {
51
53
    private:
52
54
        /**
53
55
         * The underlying packet, or 0 if the underlying packet has
67
69
         */
68
70
        bool isEditable;
69
71
 
 
72
        /**
 
73
         * Since the KDE4 port, moving packets around the tree seems to
 
74
         * result in branches being closed when they were once open.
 
75
         * Manage this manually, sigh.
 
76
         */
 
77
        bool shouldBeExpanded_;
 
78
 
70
79
    public:
71
80
        /**
72
81
         * Constructors and destructors.
 
82
         *
 
83
         * \warning The constructors should \a only be used by internal
 
84
         * PacketTreeView routines!  When creating a new packet tree
 
85
         * item, use one of the PacketTreeView::createAndSelect() routines
 
86
         * instead.
 
87
         *
 
88
         * \todo Make these constructors private, and add PacketTreeView
 
89
         * as a friend class.
73
90
         */
74
91
        PacketTreeItem(PacketTreeView* parent, regina::NPacket* realPacket);
75
92
        PacketTreeItem(PacketTreeItem* parent, regina::NPacket* realPacket);
76
 
        PacketTreeItem(PacketTreeView* parent, QListViewItem* after,
77
 
                regina::NPacket* realPacket);
78
 
        PacketTreeItem(PacketTreeItem* parent, QListViewItem* after,
 
93
        PacketTreeItem(PacketTreeItem* parent, QTreeWidgetItem* after,
79
94
                regina::NPacket* realPacket);
80
95
 
81
96
        /**
137
152
            bool inParentDestructor);
138
153
        void childrenWereReordered(regina::NPacket* packet);
139
154
 
 
155
        /**
 
156
         * Manual management of expansion state.
 
157
         */
 
158
        bool shouldBeExpanded() const;
 
159
        void markShouldBeExpanded(bool state);
 
160
        void ensureExpanded();
 
161
 
140
162
    private:
141
163
        /**
142
164
         * Initialises the appearance of this item.
149
171
 *
150
172
 * This tree must be filled only with items of type PacketTreeItem.
151
173
 */
152
 
class PacketTreeView : public KListView {
 
174
class PacketTreeView : public QTreeWidget {
153
175
    Q_OBJECT
154
176
 
155
177
    private:
156
178
        ReginaPart* part;
157
179
            /**< The KPart responsible for this packet tree. */
158
180
 
 
181
        regina::NPacket* toSelect;
 
182
            /**< If non-zero, this is a packet that will be added to the
 
183
                 tree shortly, and which will be automatically selected
 
184
                 as soon as it appears. */
 
185
 
159
186
    public:
160
187
        /**
161
188
         * Creates an empty tree.  This tree must be initialised using
162
189
         * fill().
163
190
         */
164
 
        PacketTreeView(ReginaPart* newPart, QWidget* parent = 0,
165
 
            const char* name = 0);
 
191
        PacketTreeView(ReginaPart* newPart, QWidget* parent = 0);
166
192
 
167
193
        /**
168
194
         * Returns the currently selected packet, or 0 if no packet is
171
197
        regina::NPacket* selectedPacket();
172
198
 
173
199
        /**
 
200
         * Selects the given packet in the tree, or clears the selection
 
201
         * if 0 is passed.  If the given packet cannot be found in the
 
202
         * tree, the selection will be cleared (and nothing will break).
 
203
         *
 
204
         * If \a allowDefer is \c true and the given packet cannot be
 
205
         * found in the tree then it will be assumed that the packet will be
 
206
         * added shortly, and once the corresponding tree item does appear
 
207
         * it will be selected immediately.
 
208
         */
 
209
        void selectPacket(regina::NPacket* p, bool allowDefer = false);
 
210
 
 
211
        /**
174
212
         * Fills this tree with items corresponding to the given
175
213
         * packet tree.  Any existing items in this tree will be removed.
176
214
         */
187
225
         */
188
226
        ReginaPart* getPart();
189
227
 
 
228
        /**
 
229
         * Create a new packet item in this tree.  These routines handle
 
230
         * matters such as automatic packet selection correctly, and
 
231
         * should be used instead of the PacketTreeItem* constructors.
 
232
         */
 
233
        PacketTreeItem* createAndSelect(regina::NPacket* packet);
 
234
        PacketTreeItem* createAndSelect(PacketTreeItem* parent,
 
235
            regina::NPacket* packet);
 
236
        PacketTreeItem* createAndSelect(PacketTreeItem* parent,
 
237
            QTreeWidgetItem* after, regina::NPacket* packet);
 
238
 
190
239
    public slots:
191
240
        /**
192
241
         * View or edit the packet corresponding to the given list item.
193
242
         */
194
 
        void packetView(QListViewItem* packet);
 
243
        void packetView(QTreeWidgetItem* packet);
195
244
 
196
245
        /**
197
246
         * Updates this tree to match the given packet tree.  The final
208
257
        /**
209
258
         * Allow GUI updates from within a non-GUI thread.
210
259
         */
211
 
        void customEvent(QCustomEvent* evt);
 
260
        void customEvent(QEvent* evt);
 
261
 
 
262
    private slots:
 
263
        /**
 
264
         * Manual management of expansion states.
 
265
         */
 
266
        void handleItemExpanded(QTreeWidgetItem* item);
 
267
        void handleItemCollapsed(QTreeWidgetItem* item);
212
268
};
213
269
 
214
270
inline regina::NPacket* PacketTreeItem::getPacket() {
219
275
    return tree->getPart();
220
276
}
221
277
 
 
278
inline bool PacketTreeItem::shouldBeExpanded() const {
 
279
    return shouldBeExpanded_;
 
280
}
 
281
 
 
282
inline void PacketTreeItem::markShouldBeExpanded(bool state) {
 
283
    shouldBeExpanded_ = state;
 
284
}
 
285
 
222
286
inline regina::NPacket* PacketTreeView::selectedPacket() {
223
 
    QListViewItem* item = selectedItem();
 
287
    if (selectedItems().isEmpty())
 
288
        return 0;
 
289
    QTreeWidgetItem* item = selectedItems().first();
224
290
    return (item ? dynamic_cast<PacketTreeItem*>(item)->getPacket() : 0);
225
291
}
226
292