2
/**************************************************************************
4
* Regina - A Normal Surface Theory Calculator *
7
* Copyright (c) 1999-2013, Ben Burton *
8
* For further details contact Ben Burton (bab@debian.org). *
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. *
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. *
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. *
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. *
31
**************************************************************************/
35
/*! \file facechooser.h
36
* \brief Provides a widget for selecting a single face
37
* of a 3-manifold triangulation.
40
#ifndef __FACECHOOSER_H
41
#define __FACECHOOSER_H
43
#include "packet/npacketlistener.h"
55
* A filter function, used to determine whether a given face
56
* should appear in the list.
58
typedef bool (*FaceFilterFunc)(regina::NFace*);
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.
65
* The contents of this chooser will be updated in real time if the
66
* triangulation is externally modified.
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.
71
class FaceChooser : public QComboBox, public regina::NPacketListener {
75
regina::NTriangulation* tri_;
76
/**< The triangulation whose faces we are
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. */
86
* Constructors that fills the chooser with available selections.
88
* If \a autoUpdate is \c true (the default), then this chooser
89
* will be updated when the triangulation changes.
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.
97
FaceChooser(regina::NTriangulation* tri,
98
FaceFilterFunc filter, QWidget* parent,
99
bool autoUpdate = true);
102
* Returns the currently selected face.
104
* If there are no available faces to choose from,
105
* this routine will return 0.
107
regina::NFace* selected();
110
* Changes the selection to the given face.
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.
116
* The activated() signal will \e not be emitted.
118
void select(regina::NFace* option);
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.
128
* NPacketListener overrides.
130
void packetToBeChanged(regina::NPacket*);
131
void packetWasChanged(regina::NPacket*);
132
void packetToBeDestroyed(regina::NPacket*);
136
* The text to be displayed for a given option.
138
QString description(regina::NFace* option);
141
* Fills the chooser with the set of allowable options.
147
* A dialog used to select a single face of a given triangulation.
149
class FaceDialog : public QDialog {
154
* Internal components:
156
FaceChooser* chooser;
160
* Constructor and destructor.
162
FaceDialog(QWidget* parent,
163
regina::NTriangulation* tri,
164
FaceFilterFunc filter,
165
const QString& title,
166
const QString& message,
167
const QString& whatsThis);
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);
177
inline bool FaceChooser::refresh() {
181
return (count() > 0);
184
inline void FaceChooser::packetToBeChanged(regina::NPacket*) {
189
inline void FaceChooser::packetWasChanged(regina::NPacket*) {
193
inline void FaceChooser::packetToBeDestroyed(regina::NPacket*) {