Newer
Older
Gigg, Martyn Anthony
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#ifndef MANTIDQT_CUSTOMDIALOGS_CREATESAMPLESHAPEDIALOG_H_
#define MANTIDQT_CUSTOMDIALOGS_CREATESAMPLESHAPEDIALOG_H_
//---------------------------
// Includes
//--------------------------
#include "MantidQtCustomDialogs/ui_CreateSampleShapeDialog.h"
#include "MantidQtAPI/AlgorithmDialog.h"
#include <QTreeWidget>
#include <QItemDelegate>
#include <QPoint>
#include <QHash>
#include <QMap>
#include <QVector>
//-----------------------------------
// Qt Forward declarations
//---------------------------------
namespace MantidQt
{
namespace CustomDialogs
{
class BinaryTreeWidget;
class BinaryTreeWidgetItem;
class ShapeDetails;
/**
This class gives specialised dialog for the sample shape definition
algorithm
@author Martyn Gigg, Tessella Support Services plc
@date 13/03/2009
Copyright © 2009 STFC Rutherford Appleton Laboratories
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class CreateSampleShapeDialog : public MantidQt::API::AlgorithmDialog
{
Q_OBJECT
public:
/// Default constructor
CreateSampleShapeDialog(QWidget *parent = 0);
/// Destructor
~CreateSampleShapeDialog();
public slots:
///Context menu request
void handleTreeContextMenuRequest(const QPoint & pos);
///Add a new child shape
void addChildShape(QAction *shape);
// Setup the details box based currently selected item
void setupDetailsBox();
private:
/// Initialize the layout
virtual void initLayout();
/// Get the input out of the dialog
virtual void parseInput();
/**@name Details setup functions */
//@{
/// Setup the box for a sphere
ShapeDetails* setupSphereDetails() const;
/// Setup the box for a cylinder
ShapeDetails* setupCylinderDetails() const;
//@}
private:
/// The form generated with Qt Designer
Ui::CreateSampleShapeDialog m_uiForm;
/// A pointer to the model for the shape tree
BinaryTreeWidget *m_shapeTree;
/// A map of shape names to function pointers
typedef ShapeDetails* (CreateSampleShapeDialog::*MemFuncGetter)() const;
QHash<QString, MemFuncGetter> m_setup_functions;
///A map of QTreeWidgetItem objects to their details objects
QMap<BinaryTreeWidgetItem*, ShapeDetails*> m_details_map;
};
/**
* A custom item to use in the BinaryTree widget
*/
class BinaryTreeWidgetItem : public QTreeWidgetItem
{
public:
/// Default Constructor
BinaryTreeWidgetItem(int type = QTreeWidgetItem::UserType);
/// Constructor taking a string list and an optional type
BinaryTreeWidgetItem(const QStringList & strings, int type = QTreeWidgetItem::UserType);
/// Add a child item
bool addChildItem(BinaryTreeWidgetItem *child);
/// A pointer to the left child
BinaryTreeWidgetItem* leftChild() const;
/// A pointer to the right child
BinaryTreeWidgetItem* rightChild() const;
private:
/// The index of the left child (0 or 1)
int m_left_index;
/// The index of the right child (0 or 1)
int m_right_index;
};
/**
* A widget to implement a binary tree display.
*/
class BinaryTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
/// Default constructor
BinaryTreeWidget(QWidget *parent = 0);
/// Check that we have a full binary tree
bool isFullTree() const;
//Return the root of the binary tree
BinaryTreeWidgetItem* root() const;
/// Recurse through the tree in a pre-order
void traverseByPreorder(BinaryTreeWidgetItem* node);
};
/**
* A custom delegate class used for item editing
*/
class ComboBoxDelegate : public QItemDelegate
{
Q_OBJECT
public:
/// Default constructor
ComboBoxDelegate(QWidget *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
/// A custom data role
static int g_idata_role;
};
}
}
#endif //MANTIDQT_CUSTOMDIALOGS_CREATESAMPLESHAPE_H_