BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
AccordionWidget Class Reference

QAccordion base class. More...

Inheritance diagram for AccordionWidget:
[legend]
Collaboration diagram for AccordionWidget:
[legend]

Signals

void numberOfContentPanesChanged (int number)
 Signals the new number of content panes. More...
 

Public Member Functions

 AccordionWidget (QWidget *parent=0)
 QAccordion constructor. More...
 
int addContentPane (ContentPane *cpane)
 Add content pane. More...
 
int addContentPane (QString header)
 Add a new content Pane. More...
 
int addContentPane (QString header, QFrame *contentFrame)
 Add a new content Pane. More...
 
void getActiveContentPaneIndex (std::vector< int > &indexVector)
 Get the index of the active ContentPane. More...
 
bool getCollapsible ()
 Get collapsible status. More...
 
ContentPanegetContentPane (uint index)
 Get content pane. More...
 
int getContentPaneIndex (ContentPane *contentPane)
 Get the index of a content pane. More...
 
int getContentPaneIndex (QFrame *contentFrame)
 Get the index of a content pane. More...
 
int getContentPaneIndex (QString header)
 Get the index of a content pane. More...
 
QString getError ()
 Get error string. More...
 
bool getMultiActive ()
 Check status of multiActive. More...
 
bool insertContentPane (uint index, ContentPane *cpane)
 Insert content pane. More...
 
bool insertContentPane (uint index, QString header)
 Insert content pane. More...
 
bool insertContentPane (uint index, QString header, QFrame *contentFrame)
 Insert content pane. More...
 
bool moveContentPane (uint currentIndex, uint newIndex)
 Move content pane. More...
 
int numberOfContentPanes ()
 Returns the number of content panes. More...
 
bool removeContentPane (bool deleteObject, ContentPane *contentPane)
 Remove a content pane. More...
 
bool removeContentPane (bool deleteObject, QFrame *contentframe)
 Remove a content pane. More...
 
bool removeContentPane (bool deleteObject, QString header)
 Remove a content pane. More...
 
bool removeContentPane (bool deleteObject, uint index)
 Remove a content pane. More...
 
void setCollapsible (bool status)
 If collapsible is true you can close all ContentPanes. More...
 
void setMultiActive (bool status)
 Allow multiple ContentPane to be open. More...
 
bool swapContentPane (uint index, ContentPane *cpane)
 Swap the content pane. More...
 

Protected Member Functions

void paintEvent (ATTR_UNUSED QPaintEvent *event)
 paintEvent Reimplement paintEvent to use stylesheets in derived Widgets More...
 

Private Slots

void numberOfPanesChanged (int number)
 

Private Member Functions

bool checkIndexError (uint index, bool sizeIndexAllowed, const QString &errMessage)
 
int findContentPaneIndex (QString name="", QFrame *cframe=nullptr, ContentPane *cpane=nullptr)
 
void handleClickedSignal (ContentPane *cpane)
 
int internalAddContentPane (QString header, QFrame *cframe=nullptr, ContentPane *cpane=nullptr)
 
bool internalInsertContentPane (uint index, QString header, QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)
 
bool internalRemoveContentPane (bool deleteOject, int index=-1, QString name="", QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)
 

Private Attributes

bool collapsible
 
std::vector< ContentPane * > contentPanes
 
QString errorString
 
bool multiActive
 
QSpacerItem * spacer
 

Detailed Description

QAccordion base class.

This class is the basis of the qAccordion widget. If you want to add a accordion widget to your gui then you have to create an object of this class.

Managing content panes is simpel:

Note
Many of the mentioned functions are overloaded, provided for convenience.

The signal numberOfContentPanesChanged() is emitted whenever the number of content panes changed.

In case of an error you may get a more detailed error description with getError().

Warning
Currently Headers have to be unique

Definition at line 77 of file AccordionWidget.h.

Constructor & Destructor Documentation

◆ AccordionWidget()

AccordionWidget::AccordionWidget ( QWidget *  parent = 0)
explicit

QAccordion constructor.

Parameters
parentOptionally provide a parent widget

Definition at line 35 of file AccordionWidget.cpp.

35  : QWidget(parent)
36 {
37  // make sure our resource file gets initialized
38  Q_INIT_RESOURCE(accordionwidgeticons);
39 
40  this->multiActive = true;
41  this->collapsible = true;
42 
43  // set our basic layout
44  this->setLayout(new QVBoxLayout());
45 
46  // add a stretch to the end so all content panes are at the top
47  dynamic_cast<QVBoxLayout*>(this->layout())->addStretch();
48  this->layout()->setSpacing(1);
49  this->layout()->setContentsMargins(QMargins());
50  // TODO: Do we need to keep a pointer to the spacer?
51  this->spacer = dynamic_cast<QSpacerItem*>(this->layout()->itemAt(0));
52 
53  // seome things we want to do if the number of panes change
54  QObject::connect(this, &AccordionWidget::numberOfContentPanesChanged, this,
56 }
void numberOfPanesChanged(int number)
void numberOfContentPanesChanged(int number)
Signals the new number of content panes.
QSpacerItem * spacer

References collapsible, multiActive, numberOfContentPanesChanged(), numberOfPanesChanged(), and spacer.

Here is the call graph for this function:

Member Function Documentation

◆ addContentPane() [1/3]

int AccordionWidget::addContentPane ( ContentPane cpane)

Add content pane.

Parameters
cpaneNew content pane to add
Returns
Content pane index

This is an overloaded method of addContentPane(QString), that allows you to provide your own content pane.

Definition at line 73 of file AccordionWidget.cpp.

74 {
75  return this->internalAddContentPane("", nullptr, cpane);
76 }
int internalAddContentPane(QString header, QFrame *cframe=nullptr, ContentPane *cpane=nullptr)

References internalAddContentPane().

Here is the call graph for this function:

◆ addContentPane() [2/3]

int AccordionWidget::addContentPane ( QString  header)

Add a new content Pane.

Parameters
headerHeader of the content pane
Returns
Content pane index

Use this method to add a new content pane with the Header header. The method will return the index of the new content pane, or -1 if the pane was not added because header already exists.

Definition at line 63 of file AccordionWidget.cpp.

64 {
65  return this->internalAddContentPane(std::move(header));
66 }

References internalAddContentPane().

Referenced by MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), MaskEditorPropertyPanel::setup_PlotProperties(), and TestView::test_AccordionWidget().

Here is the call graph for this function:

◆ addContentPane() [3/3]

int AccordionWidget::addContentPane ( QString  header,
QFrame *  contentFrame 
)

Add a new content Pane.

Parameters
headerHeader of the content pane
contentFrameThe content of the pane
Returns
Content pane index

This is an overloaded method of addContentPane(QString), that allows you to provide your own content frame.

Warning
Headers have to be unique

Definition at line 68 of file AccordionWidget.cpp.

69 {
70  return this->internalAddContentPane(std::move(header), contentFrame);
71 }

References internalAddContentPane().

Here is the call graph for this function:

◆ checkIndexError()

bool AccordionWidget::checkIndexError ( uint  index,
bool  sizeIndexAllowed,
const QString &  errMessage 
)
private

Definition at line 356 of file AccordionWidget.cpp.

357 {
358  // sizeIndexAllowed is only used by inserting. If there is one pane you will
359  // be able to insert a new one before and after.
360  // FIXME: Actually there seem to be some bugs hidden here. User may now for
361  // example delete index 0 even if there isn't any content pane. I think we
362  // excluded checking 0 because of inserting.
363  // Update, I removed the 0 exclusion in the second if statement. Really a
364  // fix??
365  if (sizeIndexAllowed) {
366  if (index != 0 && static_cast<int>(index) > numberOfContentPanes()) {
367  qDebug() << Q_FUNC_INFO << errMessage;
368  this->errorString = errMessage;
369  return true;
370  }
371  } else {
372  if (static_cast<int>(index) >= numberOfContentPanes()) {
373  qDebug() << Q_FUNC_INFO << errMessage;
374  this->errorString = errMessage;
375  return true;
376  }
377  }
378  return false;
379 }
int numberOfContentPanes()
Returns the number of content panes.

References errorString, and numberOfContentPanes().

Referenced by internalInsertContentPane(), internalRemoveContentPane(), moveContentPane(), and swapContentPane().

Here is the call graph for this function:

◆ findContentPaneIndex()

int AccordionWidget::findContentPaneIndex ( QString  name = "",
QFrame *  cframe = nullptr,
ContentPane cpane = nullptr 
)
private

Definition at line 323 of file AccordionWidget.cpp.

324 {
325  // simple method that finds the index of a content by Header, content frame
326  // or content pane.
327  int index = -1;
328  if (name != "") {
329  auto result =
330  std::find_if(this->contentPanes.begin(), this->contentPanes.end(),
331  [&name](ContentPane* pane) { return pane->getHeader() == name; });
332  if (result != std::end(this->contentPanes)) {
333  // get the index by subtracting begin iterator from result
334  // iterator
335  // TODO: Is this cast really necessary?
336  index = static_cast<int>(result - this->contentPanes.begin());
337  }
338  }
339  if (cframe != nullptr) {
340  auto result = std::find_if(
341  this->contentPanes.begin(), this->contentPanes.end(),
342  [cframe](ContentPane* cpane) { return cpane->getContentFrame() == cframe; });
343  if (result != std::end(this->contentPanes)) {
344  index = static_cast<int>(result - this->contentPanes.begin());
345  }
346  }
347  if (cpane != nullptr) {
348  auto result = std::find(this->contentPanes.begin(), this->contentPanes.end(), cpane);
349  if (result != std::end(this->contentPanes)) {
350  index = static_cast<int>(result - this->contentPanes.begin());
351  }
352  }
353  return index;
354 }
std::vector< ContentPane * > contentPanes
Content Pane class.
Definition: ContentPane.h:75
QString const & name(EShape k)
Definition: particles.cpp:21

References contentPanes, and RealSpace::Particles::name().

Referenced by getContentPaneIndex(), internalAddContentPane(), internalInsertContentPane(), internalRemoveContentPane(), and swapContentPane().

Here is the call graph for this function:

◆ getActiveContentPaneIndex()

void AccordionWidget::getActiveContentPaneIndex ( std::vector< int > &  indexVector)

Get the index of the active ContentPane.

Returns
Vector with indexes of all active ContentPanes

This method will fill a vector with the index of all active ContentPanes. The vector will be empty if no ContentPane is active

Definition at line 192 of file AccordionWidget.cpp.

193 {
194  // first of all make sure it is empty
195  indexVector.clear();
196  std::for_each(this->contentPanes.begin(), this->contentPanes.end(),
197  [&indexVector, this](ContentPane* pane) {
198  if (pane->getActive()) {
199  indexVector.push_back(this->findContentPaneIndex("", nullptr, pane));
200  }
201  });
202 }

References contentPanes.

Referenced by handleClickedSignal().

◆ getCollapsible()

bool AccordionWidget::getCollapsible ( )

Get collapsible status.

Returns
bool
See also
setCollapsible()

Definition at line 219 of file AccordionWidget.cpp.

220 {
221  return this->collapsible;
222 }

References collapsible.

◆ getContentPane()

ContentPane * AccordionWidget::getContentPane ( uint  index)

Get content pane.

Parameters
indexIndex of the content pane
Returns
QFrame* or nullptr

Get a content pane (QFrame*) with index. This method will return a nullptr if the content pane does not exist.

Definition at line 166 of file AccordionWidget.cpp.

167 {
168  try {
169  return this->contentPanes.at(index);
170  } catch (const std::out_of_range& ex) {
171  qDebug() << Q_FUNC_INFO << "Can not return Content Pane: " << ex.what();
172  this->errorString = "Can not return Content Pane: " + QString(ex.what());
173  return nullptr;
174  }
175 }

References contentPanes, and errorString.

Referenced by MaskEditorPropertyPanel::MaskEditorPropertyPanel(), MaskEditorPropertyPanel::setup_MaskProperties(), MaskEditorPropertyPanel::setup_MaskStack(), MaskEditorPropertyPanel::setup_PlotProperties(), and TestView::test_AccordionWidget().

◆ getContentPaneIndex() [1/3]

int AccordionWidget::getContentPaneIndex ( ContentPane contentPane)

Get the index of a content pane.

Parameters
contentPaneContentPane*
Returns
Index of the content pane

This is an overloaded function of getContentPaneIndex(QString)

Definition at line 187 of file AccordionWidget.cpp.

188 {
189  return this->findContentPaneIndex("", nullptr, contentPane);
190 }
int findContentPaneIndex(QString name="", QFrame *cframe=nullptr, ContentPane *cpane=nullptr)

References findContentPaneIndex().

Here is the call graph for this function:

◆ getContentPaneIndex() [2/3]

int AccordionWidget::getContentPaneIndex ( QFrame *  contentFrame)

Get the index of a content pane.

Parameters
contentFrameContent Frame
Returns
Index of the content pane

This is an overloaded function of getContentPaneIndex(QString)

Definition at line 182 of file AccordionWidget.cpp.

183 {
184  return this->findContentPaneIndex("", contentFrame);
185 }

References findContentPaneIndex().

Here is the call graph for this function:

◆ getContentPaneIndex() [3/3]

int AccordionWidget::getContentPaneIndex ( QString  header)

Get the index of a content pane.

Parameters
headerHeader of the Content Pane
Returns
Index of the content pane

Get the index of a ContentPane with header. This method will return -1 if a ContentPane with this header does not exist.

Definition at line 177 of file AccordionWidget.cpp.

178 {
179  return this->findContentPaneIndex(header);
180 }

References findContentPaneIndex().

Here is the call graph for this function:

◆ getError()

QString AccordionWidget::getError ( )

Get error string.

Returns
Error string

Call this method after a function call failed for a detailed error description.

Definition at line 224 of file AccordionWidget.cpp.

225 {
226  return this->errorString;
227 }

References errorString.

◆ getMultiActive()

bool AccordionWidget::getMultiActive ( )

Check status of multiActive.

Returns
bool
See also
setMultiActive()

Definition at line 209 of file AccordionWidget.cpp.

210 {
211  return this->multiActive;
212 }

References multiActive.

Referenced by handleClickedSignal().

◆ handleClickedSignal()

void AccordionWidget::handleClickedSignal ( ContentPane cpane)
private

Definition at line 381 of file AccordionWidget.cpp.

382 {
383  // if the clicked content pane is open we simply close it and return
384  if (cpane->getActive()) {
385  // if collapsible and multiActive are false we are not allowed to close
386  // this pane
387  if (!this->collapsible && !this->multiActive) {
388  return;
389  }
390  // when multiActive is true we have to check if there is any other open
391  // cpane. if so we can close this one
392  std::vector<int> activePanes;
393  if (!this->collapsible) {
394  this->getActiveContentPaneIndex(activePanes);
395  if (activePanes.size() == 1)
396  return; // only one active --> good bye :)
397  }
398  cpane->closeContentPane();
399  return;
400  }
401  // if it is not open we will open it and search our vector for other
402  // panes that are already open.
403  // TODO: Is it really necessary to search for more than one open cpane?
404  if (!cpane->getActive()) {
405  // check if multiActive is allowed
406  if (!this->getMultiActive()) {
407  std::for_each(this->contentPanes.begin(), this->contentPanes.end(),
408  [](ContentPane* pane) {
409  if (pane->getActive())
410  pane->closeContentPane();
411  });
412  }
413  cpane->openContentPane();
414  }
415 }
void getActiveContentPaneIndex(std::vector< int > &indexVector)
Get the index of the active ContentPane.
bool getMultiActive()
Check status of multiActive.
void closeContentPane()
Close the content pane.
void openContentPane()
Open the content pane.
bool getActive()
Check if this Content pane is active.
Definition: ContentPane.cpp:48

References ContentPane::closeContentPane(), collapsible, contentPanes, ContentPane::getActive(), getActiveContentPaneIndex(), getMultiActive(), multiActive, and ContentPane::openContentPane().

Referenced by internalAddContentPane(), and internalInsertContentPane().

Here is the call graph for this function:

◆ insertContentPane() [1/3]

bool AccordionWidget::insertContentPane ( uint  index,
ContentPane cpane 
)

Insert content pane.

Parameters
indexIndex of the content pane
cpaneContent Pane to insert
Returns
bool True if insert was successfull

This is an overloaded method of insertContentPane(uint, QString). Use this method when you already created a content pane that you want to insert.

Definition at line 88 of file AccordionWidget.cpp.

89 {
90  return this->internalInsertContentPane(index, "", nullptr, cpane);
91 }
bool internalInsertContentPane(uint index, QString header, QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)

References internalInsertContentPane().

Here is the call graph for this function:

◆ insertContentPane() [2/3]

bool AccordionWidget::insertContentPane ( uint  index,
QString  header 
)

Insert content pane.

Parameters
indexIndex of the content pane
headerHeader of the content pane
Returns
bool True if insert was successfull

You can use this method to insert a new content pane at given index with header defining the Header. An empty content pane will be created that you can get with getContentPane().

Returns true if the insert was successfull.

Definition at line 78 of file AccordionWidget.cpp.

79 {
80  return this->internalInsertContentPane(index, header);
81 }

References internalInsertContentPane().

Here is the call graph for this function:

◆ insertContentPane() [3/3]

bool AccordionWidget::insertContentPane ( uint  index,
QString  header,
QFrame *  contentFrame 
)

Insert content pane.

Parameters
indexIndex of the content pane
headerHeader of the content pane
contentFrameContent frame of the content pane
Returns
bool True if insert was successfull

This is an overloaded method of insertContentPane(uint, QString). Use this method when you already created a content frame that you want to insert.

Warning
Headers have to be unique

Definition at line 83 of file AccordionWidget.cpp.

84 {
85  return this->internalInsertContentPane(index, header, contentFrame);
86 }

References internalInsertContentPane().

Here is the call graph for this function:

◆ internalAddContentPane()

int AccordionWidget::internalAddContentPane ( QString  header,
QFrame *  cframe = nullptr,
ContentPane cpane = nullptr 
)
private

Definition at line 229 of file AccordionWidget.cpp.

230 {
231  if (this->findContentPaneIndex(header, cframe, cpane) != -1) {
232  this->errorString = "Can not add content pane as it already exists";
233  return -1;
234  }
235 
236  if (cpane == nullptr) {
237  if (cframe != nullptr) {
238  cpane = new ContentPane(std::move(header), cframe);
239  } else {
240  cpane = new ContentPane(std::move(header));
241  }
242  }
243  dynamic_cast<QVBoxLayout*>(this->layout())->insertWidget(this->layout()->count() - 1, cpane);
244  this->contentPanes.push_back(cpane);
245 
246  // manage the clicked signal in a lambda expression
247  QObject::connect(cpane, &ContentPane::clicked,
248  [this, cpane]() { this->handleClickedSignal(cpane); });
249 
251 
252  return numberOfContentPanes() - 1;
253 }
void handleClickedSignal(ContentPane *cpane)
void clicked()
Clicked signal is emitted when the header is clicked.

References ContentPane::clicked(), contentPanes, errorString, findContentPaneIndex(), handleClickedSignal(), numberOfContentPanes(), and numberOfContentPanesChanged().

Referenced by addContentPane().

Here is the call graph for this function:

◆ internalInsertContentPane()

bool AccordionWidget::internalInsertContentPane ( uint  index,
QString  header,
QFrame *  contentFrame = nullptr,
ContentPane cpane = nullptr 
)
private

Definition at line 255 of file AccordionWidget.cpp.

257 {
258  if (this->checkIndexError(index, true,
259  "Can not insert Content Pane at index " + QString::number(index)
260  + ". Index out of range")) {
261  return false;
262  }
263 
264  if (this->findContentPaneIndex(header, contentFrame, cpane) != -1) {
265  return false;
266  }
267 
268  if (cpane == nullptr) {
269  if (contentFrame != nullptr) {
270  cpane = new ContentPane(std::move(header), contentFrame);
271  } else {
272  cpane = new ContentPane(std::move(header));
273  }
274  }
275 
276  dynamic_cast<QVBoxLayout*>(this->layout())->insertWidget(index, cpane);
277 
278  this->contentPanes.insert(this->contentPanes.begin() + index, cpane);
279 
280  // manage the clicked signal in a lambda expression
281  QObject::connect(cpane, &ContentPane::clicked,
282  [this, cpane]() { this->handleClickedSignal(cpane); });
283 
285 
286  return true;
287 }
bool checkIndexError(uint index, bool sizeIndexAllowed, const QString &errMessage)

References checkIndexError(), ContentPane::clicked(), contentPanes, findContentPaneIndex(), handleClickedSignal(), numberOfContentPanes(), and numberOfContentPanesChanged().

Referenced by insertContentPane().

Here is the call graph for this function:

◆ internalRemoveContentPane()

bool AccordionWidget::internalRemoveContentPane ( bool  deleteOject,
int  index = -1,
QString  name = "",
QFrame *  contentFrame = nullptr,
ContentPane cpane = nullptr 
)
private

Definition at line 289 of file AccordionWidget.cpp.

291 {
292  if (index != -1
293  && this->checkIndexError(index, false,
294  "Can not remove content pane at index " + QString::number(index)
295  + ". Index out of range")) {
296  return false;
297  }
298 
299  if (index == -1) {
300  index = this->findContentPaneIndex(std::move(name), contentFrame, cpane);
301  if (index == -1) {
302  this->errorString = "Can not remove content pane as it is not part "
303  "of the accordion widget";
304  return false;
305  }
306  }
307 
308  dynamic_cast<QVBoxLayout*>(this->layout())->removeWidget(this->contentPanes.at(index));
309 
310  // only delete the object if user wants to.
311  if (deleteOject) {
312  delete this->contentPanes.at(index);
313  this->contentPanes.at(index) = nullptr;
314  }
315 
316  this->contentPanes.erase(this->contentPanes.begin() + index);
317 
319 
320  return true;
321 }

References checkIndexError(), contentPanes, errorString, findContentPaneIndex(), RealSpace::Particles::name(), numberOfContentPanes(), and numberOfContentPanesChanged().

Referenced by removeContentPane().

Here is the call graph for this function:

◆ moveContentPane()

bool AccordionWidget::moveContentPane ( uint  currentIndex,
uint  newIndex 
)

Move content pane.

Parameters
currentIndexThe current index of the content pane.
newIndexThe new index of the current pane
Returns
bool

Moves a content from currentIndex to newIndex. Returns true if the content pane was moved, false otherwise.

Definition at line 140 of file AccordionWidget.cpp.

141 {
142  if (this->checkIndexError(currentIndex, false,
143  "Can not move from " + QString::number(currentIndex)
144  + ". Index out of range.")
145  || this->checkIndexError(newIndex, false,
146  "Can not move to " + QString::number(newIndex)
147  + ". Index out of range.")) {
148  return false;
149  }
150 
151  QVBoxLayout* layout = dynamic_cast<QVBoxLayout*>(this->layout());
152  // get the pane we want to move
153  ContentPane* movePane = this->contentPanes.at(currentIndex);
154 
155  // remove the widget from the layout and insert it at the new position
156  layout->removeWidget(movePane);
157  layout->insertWidget(newIndex, movePane);
158 
159  // keep our vector synchronized
160  this->contentPanes.erase(this->contentPanes.begin() + currentIndex);
161  this->contentPanes.insert(this->contentPanes.begin() + newIndex, movePane);
162 
163  return true;
164 }

References checkIndexError(), and contentPanes.

Here is the call graph for this function:

◆ numberOfContentPanes()

int AccordionWidget::numberOfContentPanes ( )

Returns the number of content panes.

Returns
int

Definition at line 58 of file AccordionWidget.cpp.

59 {
60  return static_cast<int>(contentPanes.size());
61 }

References contentPanes.

Referenced by checkIndexError(), internalAddContentPane(), internalInsertContentPane(), and internalRemoveContentPane().

◆ numberOfContentPanesChanged

void AccordionWidget::numberOfContentPanesChanged ( int  number)
signal

Signals the new number of content panes.

Parameters
numberNumber of content panes

Signal will be emitted if the number of content panes changes

Referenced by AccordionWidget(), internalAddContentPane(), internalInsertContentPane(), and internalRemoveContentPane().

◆ numberOfPanesChanged

void AccordionWidget::numberOfPanesChanged ( int  number)
privateslot

Definition at line 417 of file AccordionWidget.cpp.

418 {
419  // automatically open contentpane if we have only one and collapsible is
420  // false
421  if (number == 1 && this->collapsible == false) {
422  this->contentPanes.at(0)->openContentPane();
423  }
424 }

References collapsible, and contentPanes.

Referenced by AccordionWidget().

◆ paintEvent()

void AccordionWidget::paintEvent ( ATTR_UNUSED QPaintEvent *  event)
protected

paintEvent Reimplement paintEvent to use stylesheets in derived Widgets

Parameters
event

Definition at line 426 of file AccordionWidget.cpp.

427 {
428  QStyleOption o;
429  o.initFrom(this);
430  QPainter p(this);
431  style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
432 }

◆ removeContentPane() [1/4]

bool AccordionWidget::removeContentPane ( bool  deleteObject,
ContentPane contentPane 
)

Remove a content pane.

Parameters
deleteObjectDelete the object and free memory
contentPaneThe content pane to remove
Returns
bool

This is an overloaded method of removeContentPane(bool, uint).

Definition at line 135 of file AccordionWidget.cpp.

136 {
137  return this->internalRemoveContentPane(deleteObject, -1, "", nullptr, contentPane);
138 }
bool internalRemoveContentPane(bool deleteOject, int index=-1, QString name="", QFrame *contentFrame=nullptr, ContentPane *cpane=nullptr)

References internalRemoveContentPane().

Here is the call graph for this function:

◆ removeContentPane() [2/4]

bool AccordionWidget::removeContentPane ( bool  deleteObject,
QFrame *  contentframe 
)

Remove a content pane.

Parameters
deleteObjectDelete the object and free memory
contentframeContent frame of the content pane
Returns
bool

This is an overloaded method of removeContentPane(bool, uint).

Definition at line 130 of file AccordionWidget.cpp.

131 {
132  return this->internalRemoveContentPane(deleteObject, -1, "", contentframe);
133 }

References internalRemoveContentPane().

Here is the call graph for this function:

◆ removeContentPane() [3/4]

bool AccordionWidget::removeContentPane ( bool  deleteObject,
QString  header 
)

Remove a content pane.

Parameters
deleteObjectDelete the object and free memory
headerHeader of the content pane
Returns
bool

This is an overloaded method of removeContentPane(bool, uint).

Definition at line 125 of file AccordionWidget.cpp.

126 {
127  return this->internalRemoveContentPane(deleteObject, -1, header);
128 }

References internalRemoveContentPane().

Here is the call graph for this function:

◆ removeContentPane() [4/4]

bool AccordionWidget::removeContentPane ( bool  deleteObject,
uint  index 
)

Remove a content pane.

Parameters
deleteObjectDelete the object and free memory
indexIndex of the content pane
Returns
bool

Remove a content pane at index. If deleteObject is true the object will be deleted. Otherwise it is up to the user to free the allocated memory.

Returns true if the pane was removed and false otherwise.

Definition at line 120 of file AccordionWidget.cpp.

121 {
122  return this->internalRemoveContentPane(deleteObject, index);
123 }

References internalRemoveContentPane().

Here is the call graph for this function:

◆ setCollapsible()

void AccordionWidget::setCollapsible ( bool  status)

If collapsible is true you can close all ContentPanes.

Parameters
status

With the collapsible option you can control if one content pane has to be open and can't be closed.

Definition at line 214 of file AccordionWidget.cpp.

215 {
216  this->collapsible = status;
217 }

References collapsible.

◆ setMultiActive()

void AccordionWidget::setMultiActive ( bool  status)

Allow multiple ContentPane to be open.

Parameters
status

This option allows you to open several ContentPane at the same time.

Note
Default value for this option is false.

Definition at line 204 of file AccordionWidget.cpp.

205 {
206  this->multiActive = status;
207 }

References multiActive.

Referenced by TestView::test_AccordionWidget().

◆ swapContentPane()

bool AccordionWidget::swapContentPane ( uint  index,
ContentPane cpane 
)

Swap the content pane.

Parameters
indexIndex of the content pane to swap
cpaneNew content pane
Returns
bool True if swap was successfull

With this method you can replace an existing content pane at index with a new one cpane.

Returns true if the swap was successfull.

The old content pane will be deleted.

Definition at line 93 of file AccordionWidget.cpp.

94 {
95  if (this->checkIndexError(index, false,
96  "Can not swap content pane at index " + QString::number(index)
97  + ". Index out of range.")) {
98  return false;
99  }
100 
101  if (this->findContentPaneIndex("", nullptr, cpane) != -1) {
102  this->errorString = "Can not swap content pane as new pane is already "
103  "managed by accordion widget";
104  return false;
105  }
106 
107  // remove the old content pane from the accordion layout
108  dynamic_cast<QVBoxLayout*>(this->layout())->removeWidget(this->contentPanes.at(index));
109  delete this->contentPanes.at(index);
110 
111  // add the new content pane to the appropriate vector
112  this->contentPanes.at(index) = cpane;
113 
114  // add the new content pane to the layout
115  dynamic_cast<QVBoxLayout*>(this->layout())->insertWidget(index, this->contentPanes.at(index));
116 
117  return true;
118 }

References checkIndexError(), contentPanes, errorString, and findContentPaneIndex().

Here is the call graph for this function:

Member Data Documentation

◆ collapsible

bool AccordionWidget::collapsible
private

◆ contentPanes

◆ errorString

QString AccordionWidget::errorString
private

◆ multiActive

bool AccordionWidget::multiActive
private

◆ spacer

QSpacerItem* AccordionWidget::spacer
private

Definition at line 352 of file AccordionWidget.h.

Referenced by AccordionWidget().


The documentation for this class was generated from the following files: