BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AccordionWidget.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/AccordionWidget/AccordionWidget.h
6 //! @brief Defines AccordionWidget class
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 // This file is part of qAccordion. An Accordion widget for Qt
16 // Copyright (C) 2015 Christian Rapp <0x2a at posteo dot org>
17 //
18 // This program is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program. If not, see <http://www.gnu.org/licenses/>.
30 
31 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_ACCORDIONWIDGET_H
32 #define BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_ACCORDIONWIDGET_H
33 
35 #include <QGridLayout>
36 #include <QHBoxLayout>
37 #include <QPainter>
38 #include <QSpacerItem>
39 #include <QString>
40 #include <QStyleOption>
41 #include <QVBoxLayout>
42 #include <QWidget>
43 #include <algorithm>
44 #include <iterator>
45 #include <memory>
46 #include <vector>
47 
48 class ContentPane;
49 
50 /**
51  * @brief QAccordion base class
52  *
53  * @details
54  * This class is the basis of the qAccordion widget. If you want to add a
55  * accordion widget to your gui then you have to create an object of this class.
56  *
57  * Managing content panes is simpel:
58  * * You can either add (addContentPane()) or insert (insertContentPane()) new ContentPanes.
59  * * Use removeContentPane() to remove existing ContentPanes.
60  * * moveContentPane() allows you to change the order of the ContentPanes.
61  * * To change a ContentPane in place use swapContentPane()
62  *
63  * @note
64  * Many of the mentioned functions are overloaded, provided for convenience.
65  *
66  * @details
67  * The signal numberOfContentPanesChanged() is emitted whenever the number of
68  * content panes changed.
69  *
70  * In case of an error you may get a more detailed error description with
71  * getError().
72  *
73  * @warning
74  * Currently Headers have to be unique
75  *
76  */
77 class AccordionWidget : public QWidget {
78  Q_OBJECT
79 public:
80  /**
81  * @brief QAccordion constructor
82  * @param parent Optionally provide a parent widget
83  */
84  explicit AccordionWidget(QWidget* parent = 0);
85 
86  /**
87  * @brief Returns the number of content panes
88  * @return int
89  */
91 
92  /**
93  * @brief Add a new content Pane
94  * @param header Header of the content pane
95  * @return Content pane index
96  *
97  * @details
98  * Use this method to add a new content pane with the Header header.
99  * The method will return the index of the new content pane, or <b>-1</b> if
100  * the pane was not added because header already exists.
101  */
102  int addContentPane(QString header);
103  /**
104  * @brief Add a new content Pane
105  * @param header Header of the content pane
106  * @param contentFrame The content of the pane
107  * @return Content pane index
108  *
109  * @details
110  * This is an overloaded method of addContentPane(QString), that
111  * allows you to provide your own content frame.
112  * @warning
113  * Headers have to be unique
114  */
115  int addContentPane(QString header, QFrame* contentFrame);
116  /**
117  * @brief Add content pane
118  * @param cpane New content pane to add
119  * @return Content pane index
120  *
121  * @details
122  * This is an overloaded method of addContentPane(QString), that
123  * allows you to provide your own content pane.
124  */
125  int addContentPane(ContentPane* cpane);
126  /**
127  * @brief Insert content pane
128  * @param index Index of the content pane
129  * @param header Header of the content pane
130  * @return bool True if insert was successfull
131  *
132  * @details
133  * You can use this method to insert a new content pane at given index with
134  * header defining the Header. An empty content pane will be created that
135  * you can get with getContentPane().
136  *
137  * Returns true if the insert was successfull.
138  */
139  bool insertContentPane(uint index, QString header);
140  /**
141  * @brief Insert content pane
142  * @param index Index of the content pane
143  * @param header Header of the content pane
144  * @param contentFrame Content frame of the content pane
145  * @return bool True if insert was successfull
146  *
147  * @details
148  * This is an overloaded method of insertContentPane(uint, QString).
149  * Use this method when you already created a content frame that you want to
150  * insert.
151  * @warning
152  * Headers have to be unique
153  */
154  bool insertContentPane(uint index, QString header, QFrame* contentFrame);
155  /**
156  * @brief Insert content pane
157  * @param index Index of the content pane
158  * @param cpane Content Pane to insert
159  * @return bool True if insert was successfull
160  *
161  * @details
162  * This is an overloaded method of insertContentPane(uint, QString).
163  * Use this method when you already created a content pane that you want to
164  * insert.
165  */
166  bool insertContentPane(uint index, ContentPane* cpane);
167 
168  /**
169  * @brief Swap the content pane
170  * @param index Index of the content pane to swap
171  * @param cpane New content pane
172  * @return bool True if swap was successfull
173  *
174  * @details
175  * With this method you can replace an existing content pane at index with
176  * a new one cpane.
177  *
178  * Returns true if the swap was successfull.
179  *
180  * The old content pane will be __deleted__.
181  */
182  bool swapContentPane(uint index, ContentPane* cpane);
183 
184  /**
185  * @brief Remove a content pane
186  * @param deleteObject Delete the object and free memory
187  * @param index Index of the content pane
188  * @return bool
189  *
190  * @details
191  * Remove a content pane at index. If deleteObject is true the
192  * object will be deleted. Otherwise it is up to the user to
193  * free the allocated memory.
194  *
195  * Returns true if the pane was removed and false otherwise.
196  */
197  bool removeContentPane(bool deleteObject, uint index);
198  /**
199  * @brief Remove a content pane
200  * @param deleteObject Delete the object and free memory
201  * @param header Header of the content pane
202  * @return bool
203  *
204  * @details
205  * This is an overloaded method of removeContentPane(bool, uint).
206  */
207  bool removeContentPane(bool deleteObject, QString header);
208  /**
209  * @brief Remove a content pane
210  * @param deleteObject Delete the object and free memory
211  * @param contentframe Content frame of the content pane
212  * @return bool
213  *
214  * @details
215  * This is an overloaded method of removeContentPane(bool, uint).
216  */
217  bool removeContentPane(bool deleteObject, QFrame* contentframe);
218  /**
219  * @brief Remove a content pane
220  * @param deleteObject Delete the object and free memory
221  * @param contentPane The content pane to remove
222  * @return bool
223  *
224  * @details
225  * This is an overloaded method of removeContentPane(bool, uint).
226  */
227  bool removeContentPane(bool deleteObject, ContentPane* contentPane);
228 
229  /**
230  * @brief Move content pane
231  * @param currentIndex The current index of the content pane.
232  * @param newIndex The new index of the current pane
233  * @return bool
234  *
235  * @details
236  * Moves a content from currentIndex to newIndex. Returns true if the
237  * content pane was moved, false otherwise.
238  */
239  bool moveContentPane(uint currentIndex, uint newIndex);
240 
241  /**
242  * @brief Get content pane
243  * @param index Index of the content pane
244  * @return QFrame* or nullptr
245  *
246  * @details
247  * Get a content pane (QFrame*) with index. This method will return a
248  * __nullptr__ if the content pane does not exist.
249  */
250  ContentPane* getContentPane(uint index);
251 
252  /**
253  * @brief Get the index of a content pane
254  * @param header Header of the Content Pane
255  * @return Index of the content pane
256  *
257  * @details
258  * Get the index of a ContentPane with header. This method will return
259  * <b>-1</b> if a ContentPane with this header does not exist.
260  */
261  int getContentPaneIndex(QString header);
262  /**
263  * @brief Get the index of a content pane
264  * @param contentFrame Content Frame
265  * @return Index of the content pane
266  *
267  * @details
268  * This is an overloaded function of getContentPaneIndex(QString)
269  */
270  int getContentPaneIndex(QFrame* contentFrame);
271  /**
272  * @brief Get the index of a content pane
273  * @param contentPane ContentPane*
274  * @return Index of the content pane
275  *
276  * @details
277  * This is an overloaded function of getContentPaneIndex(QString)
278  */
279  int getContentPaneIndex(ContentPane* contentPane);
280 
281  /**
282  * @brief Get the index of the active ContentPane
283  * @return Vector with indexes of all active ContentPanes
284  *
285  * @details
286  * This method will fill a vector with the index of all active ContentPanes.
287  * The vector will be empty if no ContentPane is active
288  */
289  void getActiveContentPaneIndex(std::vector<int>& indexVector);
290 
291  /**
292  * @brief Allow multiple ContentPane to be open
293  * @param status
294  *
295  * @details
296  * This option allows you to open several ContentPane at the same time.
297  * @note
298  * Default value for this option is false.
299  */
300  void setMultiActive(bool status);
301  /**
302  * @brief Check status of multiActive
303  * @return bool
304  *
305  * @sa
306  * setMultiActive()
307  */
308  bool getMultiActive();
309 
310  /**
311  * @brief If collapsible is true you can close all ContentPanes
312  * @param status
313  *
314  * @details
315  * With the collapsible option you can control if one content pane has to be
316  * open and can't be closed.
317  */
318  void setCollapsible(bool status);
319  /**
320  * @brief Get collapsible status
321  * @return bool
322  * @sa
323  * setCollapsible()
324  */
325  bool getCollapsible();
326 
327  /**
328  * @brief Get error string
329  * @return Error string
330  *
331  * @details
332  * Call this method after a function call failed for a detailed error
333  * description.
334  */
335  QString getError();
336 
337 signals:
338  /**
339  * @brief Signals the new number of content panes
340  * @param number Number of content panes
341  *
342  * @details
343  * Signal will be emitted if the number of content panes changes
344  */
345  void numberOfContentPanesChanged(int number);
346 
347 public slots:
348 
349 private:
350  std::vector<ContentPane*> contentPanes;
351 
352  QSpacerItem* spacer;
353 
354  QString errorString;
355 
358 
359  int internalAddContentPane(QString header, QFrame* cframe = nullptr,
360  ContentPane* cpane = nullptr);
361  bool internalInsertContentPane(uint index, QString header, QFrame* contentFrame = nullptr,
362  ContentPane* cpane = nullptr);
363  bool internalRemoveContentPane(bool deleteOject, int index = -1, QString name = "",
364  QFrame* contentFrame = nullptr, ContentPane* cpane = nullptr);
365  int findContentPaneIndex(QString name = "", QFrame* cframe = nullptr,
366  ContentPane* cpane = nullptr);
367 
368  bool checkIndexError(uint index, bool sizeIndexAllowed, const QString& errMessage);
369  void handleClickedSignal(ContentPane* cpane);
370 
371 private slots:
372  void numberOfPanesChanged(int number);
373 
374 protected:
375  /**
376  * @brief paintEvent Reimplement paintEvent to use stylesheets in derived Widgets
377  * @param event
378  */
379  void paintEvent(ATTR_UNUSED QPaintEvent* event);
380 };
381 
382 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_ACCORDIONWIDGET_ACCORDIONWIDGET_H
Defines AccordionWidget class.
#define ATTR_UNUSED
QAccordion base class.
bool getCollapsible()
Get collapsible status.
ContentPane * getContentPane(uint index)
Get content pane.
bool moveContentPane(uint currentIndex, uint newIndex)
Move content pane.
bool removeContentPane(bool deleteObject, uint index)
Remove a content pane.
void paintEvent(ATTR_UNUSED QPaintEvent *event)
paintEvent Reimplement paintEvent to use stylesheets in derived Widgets
bool checkIndexError(uint index, bool sizeIndexAllowed, const QString &errMessage)
int addContentPane(QString header)
Add a new content Pane.
void handleClickedSignal(ContentPane *cpane)
bool insertContentPane(uint index, QString header)
Insert content pane.
void numberOfPanesChanged(int number)
void setCollapsible(bool status)
If collapsible is true you can close all ContentPanes.
void numberOfContentPanesChanged(int number)
Signals the new number of content panes.
int findContentPaneIndex(QString name="", QFrame *cframe=nullptr, ContentPane *cpane=nullptr)
std::vector< ContentPane * > contentPanes
bool internalRemoveContentPane(bool deleteOject, int index=-1, QString name="", QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)
QString getError()
Get error string.
AccordionWidget(QWidget *parent=0)
QAccordion constructor.
QSpacerItem * spacer
bool swapContentPane(uint index, ContentPane *cpane)
Swap the content pane.
void getActiveContentPaneIndex(std::vector< int > &indexVector)
Get the index of the active ContentPane.
bool getMultiActive()
Check status of multiActive.
int getContentPaneIndex(QString header)
Get the index of a content pane.
bool internalInsertContentPane(uint index, QString header, QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)
void setMultiActive(bool status)
Allow multiple ContentPane to be open.
int internalAddContentPane(QString header, QFrame *cframe=nullptr, ContentPane *cpane=nullptr)
int numberOfContentPanes()
Returns the number of content panes.
Content Pane class.
Definition: ContentPane.h:75
QString const & name(EShape k)
Definition: particles.cpp:21