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

« back to all changes in this revision

Viewing changes to qtui/src/choosers/facechooser.h

  • Committer: Package Import Robot
  • Author(s): Ben Burton
  • Date: 2013-11-02 11:44:32 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20131102114432-acgci6b1pb2hjl8q
Tags: 4.95-1
* New upstream release.
* The python module is now installed in a standard location beneath
  /usr/lib/python2.7/dist-packages.
* Switched python packaging from python-support to dh_python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/**************************************************************************
3
 
 *                                                                        *
4
 
 *  Regina - A Normal Surface Theory Calculator                           *
5
 
 *  Qt User Interface                                                     *
6
 
 *                                                                        *
7
 
 *  Copyright (c) 1999-2013, Ben Burton                                   *
8
 
 *  For further details contact Ben Burton (bab@debian.org).              *
9
 
 *                                                                        *
10
 
 *  This program is free software; you can redistribute it and/or         *
11
 
 *  modify it under the terms of the GNU General Public License as        *
12
 
 *  published by the Free Software Foundation; either version 2 of the    *
13
 
 *  License, or (at your option) any later version.                       *
14
 
 *                                                                        *
15
 
 *  As an exception, when this program is distributed through (i) the     *
16
 
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
17
 
 *  (iii) Google Play by Google Inc., then that store may impose any      *
18
 
 *  digital rights management, device limits and/or redistribution        *
19
 
 *  restrictions that are required by its terms of service.               *
20
 
 *                                                                        *
21
 
 *  This program is distributed in the hope that it will be useful, but   *
22
 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
23
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
24
 
 *  General Public License for more details.                              *
25
 
 *                                                                        *
26
 
 *  You should have received a copy of the GNU General Public             *
27
 
 *  License along with this program; if not, write to the Free            *
28
 
 *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,       *
29
 
 *  MA 02110-1301, USA.                                                   *
30
 
 *                                                                        *
31
 
 **************************************************************************/
32
 
 
33
 
/* end stub */
34
 
 
35
 
/*! \file facechooser.h
36
 
 *  \brief Provides a widget for selecting a single face
37
 
 *  of a 3-manifold triangulation.
38
 
 */
39
 
 
40
 
#ifndef __FACECHOOSER_H
41
 
#define __FACECHOOSER_H
42
 
 
43
 
#include "packet/npacketlistener.h"
44
 
 
45
 
#include <QDialog>
46
 
#include <QComboBox>
47
 
#include <vector>
48
 
 
49
 
namespace regina {
50
 
    class NFace;
51
 
    class NTriangulation;
52
 
};
53
 
 
54
 
/**
55
 
 * A filter function, used to determine whether a given face
56
 
 * should appear in the list.
57
 
 */
58
 
typedef bool (*FaceFilterFunc)(regina::NFace*);
59
 
 
60
 
/**
61
 
 * A widget through which a single face of some triangulation
62
 
 * can be selected.  An optional filter may be applied to restrict the
63
 
 * available selections.
64
 
 *
65
 
 * The contents of this chooser will be updated in real time if the
66
 
 * triangulation is externally modified.
67
 
 *
68
 
 * These chooser classes would be *much* better using templates, but my
69
 
 * understanding is that templates don't play well with Q_OBJECT and moc.
70
 
 */
71
 
class FaceChooser : public QComboBox, public regina::NPacketListener {
72
 
    Q_OBJECT
73
 
 
74
 
    private:
75
 
        regina::NTriangulation* tri_;
76
 
            /**< The triangulation whose faces we are
77
 
                 choosing from. */
78
 
        FaceFilterFunc filter_;
79
 
            /**< A filter to restrict the available selections, or
80
 
                 0 if no filter is necessary. */
81
 
        std::vector<regina::NFace*> options_;
82
 
            /**< A list of the available options to choose from. */
83
 
 
84
 
    public:
85
 
        /**
86
 
         * Constructors that fills the chooser with available selections.
87
 
         *
88
 
         * If \a autoUpdate is \c true (the default), then this chooser
89
 
         * will be updated when the triangulation changes.
90
 
         *
91
 
         * If \a autoUpdate is \c false, then contents of this chooser will
92
 
         * only be updated when refresh() is manually called.  Be careful
93
 
         * when using this setting, since if the triangulation changes
94
 
         * but the chooser is \e not refreshed, then selected() may end
95
 
         * up returning an invalid pointer.
96
 
         */
97
 
        FaceChooser(regina::NTriangulation* tri,
98
 
                FaceFilterFunc filter, QWidget* parent,
99
 
                bool autoUpdate = true);
100
 
 
101
 
        /**
102
 
         * Returns the currently selected face.
103
 
         *
104
 
         * If there are no available faces to choose from,
105
 
         * this routine will return 0.
106
 
         */
107
 
        regina::NFace* selected();
108
 
 
109
 
        /**
110
 
         * Changes the selection to the given face.
111
 
         *
112
 
         * If the given face is not one of the options in this
113
 
         * chooser, or if the given pointer is 0, then the first entry
114
 
         * in the chooser will be selected.
115
 
         *
116
 
         * The activated() signal will \e not be emitted.
117
 
         */
118
 
        void select(regina::NFace* option);
119
 
 
120
 
        /**
121
 
         * Forces a manual refresh of the contents of this chooser.
122
 
         * Returns \c true if and only if the chooser is non-empty
123
 
         * (i.e., at least one option is present) after the refresh.
124
 
         */
125
 
        bool refresh();
126
 
 
127
 
        /**
128
 
         * NPacketListener overrides.
129
 
         */
130
 
        void packetToBeChanged(regina::NPacket*);
131
 
        void packetWasChanged(regina::NPacket*);
132
 
        void packetToBeDestroyed(regina::NPacket*);
133
 
 
134
 
    private:
135
 
        /**
136
 
         * The text to be displayed for a given option.
137
 
         */
138
 
        QString description(regina::NFace* option);
139
 
 
140
 
        /**
141
 
         * Fills the chooser with the set of allowable options.
142
 
         */
143
 
        void fill();
144
 
};
145
 
 
146
 
/**
147
 
 * A dialog used to select a single face of a given triangulation.
148
 
 */
149
 
class FaceDialog : public QDialog {
150
 
    Q_OBJECT
151
 
 
152
 
    private:
153
 
        /**
154
 
         * Internal components:
155
 
         */
156
 
        FaceChooser* chooser;
157
 
 
158
 
    public:
159
 
        /**
160
 
         * Constructor and destructor.
161
 
         */
162
 
        FaceDialog(QWidget* parent,
163
 
            regina::NTriangulation* tri,
164
 
            FaceFilterFunc filter,
165
 
            const QString& title,
166
 
            const QString& message,
167
 
            const QString& whatsThis);
168
 
 
169
 
        static regina::NFace* choose(QWidget* parent,
170
 
            regina::NTriangulation* tri,
171
 
            FaceFilterFunc filter,
172
 
            const QString& title,
173
 
            const QString& message,
174
 
            const QString& whatsThis);
175
 
};
176
 
 
177
 
inline bool FaceChooser::refresh() {
178
 
    clear();
179
 
    options_.clear();
180
 
    fill();
181
 
    return (count() > 0);
182
 
}
183
 
 
184
 
inline void FaceChooser::packetToBeChanged(regina::NPacket*) {
185
 
    clear();
186
 
    options_.clear();
187
 
}
188
 
 
189
 
inline void FaceChooser::packetWasChanged(regina::NPacket*) {
190
 
    fill();
191
 
}
192
 
 
193
 
inline void FaceChooser::packetToBeDestroyed(regina::NPacket*) {
194
 
    clear();
195
 
    options_.clear();
196
 
}
197
 
 
198
 
#endif