Newer
Older
Gigg, Martyn Anthony
committed
#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
//---------------------------------
Gigg, Martyn Anthony
committed
class QCloseEvent;
Gigg, Martyn Anthony
committed
namespace MantidQt
{
namespace CustomDialogs
{
class BinaryTreeWidget;
class BinaryTreeWidgetItem;
class ShapeDetails;
Gigg, Martyn Anthony
committed
class BaseInstantiator;
class Operation;
Gigg, Martyn Anthony
committed
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
/**
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);
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Destructor
~CreateSampleShapeDialog();
Gigg, Martyn Anthony
committed
private slots:
/// Context menu request
Gigg, Martyn Anthony
committed
void handleTreeContextMenuRequest(const QPoint & pos);
Gigg, Martyn Anthony
committed
/// Add a new shape
void addShape(QAction *shape);
/// Add operation node based on menu action
void addOperation(QAction *shape);
/// Connects to the delete slot
void handleDeleteRequest();
/// Remove an item from the tree (recursive)
void removeItem(BinaryTreeWidgetItem* item);
/// Setup the details box based currently selected item
Gigg, Martyn Anthony
committed
void setupDetailsBox();
Gigg, Martyn Anthony
committed
/// Change item data
void changeTreeData(BinaryTreeWidgetItem* item, int data);
Gigg, Martyn Anthony
committed
private:
/// Initialize the layout
virtual void initLayout();
/// Get the input out of the dialog
virtual void parseInput();
Gigg, Martyn Anthony
committed
/// Find the parent
BinaryTreeWidgetItem* getSelectedItem();
/// Create a details widget based upon the shape name given
ShapeDetails* createDetailsWidget(const QString & shapename) const;
Gigg, Martyn Anthony
committed
private:
/// The form generated with Qt Designer
Ui::CreateSampleShapeDialog m_uiForm;
/// A pointer to the model for the shape tree
BinaryTreeWidget *m_shapeTree;
Gigg, Martyn Anthony
committed
/// A map of shape names to instantiator objects
QHash<QString, BaseInstantiator*> m_setup_map;
Gigg, Martyn Anthony
committed
///A map of QTreeWidgetItem objects to their details objects
QMap<BinaryTreeWidgetItem*, ShapeDetails*> m_details_map;
Gigg, Martyn Anthony
committed
///A map of QTreeWidgetItem objects to their operation objects
QMap<BinaryTreeWidgetItem*, Operation*> m_ops_map;
Gigg, Martyn Anthony
committed
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
};
/**
* 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;
Gigg, Martyn Anthony
committed
/// Recurse through the tree in a post-order
void traverseInPostOrder(BinaryTreeWidgetItem* node, QList<BinaryTreeWidgetItem*> & expression);
/// Called when the data in the model is changed
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight );
signals:
/// Emitted when data has changed
void treeDataChange(BinaryTreeWidgetItem* item, int data);
Gigg, Martyn Anthony
committed
};
/**
* A custom delegate class used for item editing
*/
class ComboBoxDelegate : public QItemDelegate
{
Q_OBJECT
public:
/// Default constructor
ComboBoxDelegate(QWidget *parent = 0);
Gigg, Martyn Anthony
committed
/// Create an editor for the item
Gigg, Martyn Anthony
committed
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
Gigg, Martyn Anthony
committed
///Set the data for the editor when it has been created
Gigg, Martyn Anthony
committed
void setEditorData(QWidget *editor, const QModelIndex &index) const;
Gigg, Martyn Anthony
committed
///Set the data for the model when editing has finished
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
/// Ensure that the editor has the correct geometry when it is created
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
Gigg, Martyn Anthony
committed
};
}
}
#endif //MANTIDQT_CUSTOMDIALOGS_CREATESAMPLESHAPE_H_