Skip to content

Commit c5f80b9

Browse files
authored
Hide the empty tab in the parameters window (#7499)
Fixes #7494
1 parent 4c24d57 commit c5f80b9

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

OMEdit/OMEditLIB/Element/ElementProperties.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ ParametersScrollArea::ParametersScrollArea()
627627
setFrameShape(QFrame::NoFrame);
628628
setBackgroundRole(QPalette::Base);
629629
setWidgetResizable(true);
630+
mGroupBoxesList.clear();
630631
mpVerticalLayout = new QVBoxLayout;
631632
mpVerticalLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
632633
mpWidget->setLayout(mpVerticalLayout);
@@ -662,8 +663,7 @@ QSize ParametersScrollArea::minimumSizeHint() const
662663
*/
663664
void ParametersScrollArea::addGroupBox(GroupBox *pGroupBox)
664665
{
665-
if (!getGroupBox(pGroupBox->title()))
666-
{
666+
if (!getGroupBox(pGroupBox->title())) {
667667
pGroupBox->hide(); /* create a hidden groupbox, we show it when it contains the parameters. */
668668
mGroupBoxesList.append(pGroupBox);
669669
mpVerticalLayout->addWidget(pGroupBox);
@@ -674,12 +674,12 @@ void ParametersScrollArea::addGroupBox(GroupBox *pGroupBox)
674674
Returns the GroupBox by reading the list of GroupBoxes.
675675
\return the GroupBox
676676
*/
677-
GroupBox* ParametersScrollArea::getGroupBox(QString title)
677+
GroupBox* ParametersScrollArea::getGroupBox(const QString &title)
678678
{
679-
foreach (GroupBox *pGroupBox, mGroupBoxesList)
680-
{
681-
if (pGroupBox->title().compare(title) == 0)
679+
foreach (GroupBox *pGroupBox, mGroupBoxesList) {
680+
if (pGroupBox->title().compare(title) == 0) {
682681
return pGroupBox;
682+
}
683683
}
684684
return 0;
685685
}
@@ -786,8 +786,7 @@ void ElementParameters::setUpDialog()
786786
fetchComponentModifiers();
787787
fetchExtendsModifiers();
788788
foreach (Parameter *pParameter, mParametersList) {
789-
ParametersScrollArea *pParametersScrollArea;
790-
pParametersScrollArea = qobject_cast<ParametersScrollArea*>(mpParametersTabWidget->widget(mTabsMap.value(pParameter->getTab())));
789+
ParametersScrollArea *pParametersScrollArea = qobject_cast<ParametersScrollArea*>(mpParametersTabWidget->widget(mTabsMap.value(pParameter->getTab())));
791790
if (pParametersScrollArea) {
792791
if (!pParameter->getGroupBox().isEmpty()) {
793792
GroupBox *pGroupBox = pParametersScrollArea->getGroupBox(pParameter->getGroupBox());
@@ -839,6 +838,26 @@ void ElementParameters::setUpDialog()
839838
pModifiersTabLayout->addWidget(mpModifiersTextBox);
840839
pModifiersTab->setLayout(pModifiersTabLayout);
841840
mpParametersTabWidget->addTab(pModifiersTab, "Modifiers");
841+
// Issue #7494. Hide any empty tab.
842+
for (int i = 0; i < mpParametersTabWidget->count(); ++i) {
843+
ParametersScrollArea *pParametersScrollArea = qobject_cast<ParametersScrollArea*>(mpParametersTabWidget->widget(i));
844+
if (pParametersScrollArea) {
845+
bool tabIsEmpty = true;
846+
// The tab is empty if its groupbox layout is empty.
847+
for (int j = 0; j < pParametersScrollArea->groupBoxesSize(); ++j) {
848+
GroupBox *pGroupBox = pParametersScrollArea->getGroupBox(j);
849+
if (pGroupBox && !pGroupBox->getGridLayout()->isEmpty()) {
850+
tabIsEmpty = false;
851+
break;
852+
}
853+
}
854+
// If the tab is empty then remove it and move one step back.
855+
if (tabIsEmpty) {
856+
mpParametersTabWidget->removeTab(i);
857+
--i;
858+
}
859+
}
860+
}
842861
// Create the buttons
843862
mpOkButton = new QPushButton(Helper::ok);
844863
mpOkButton->setAutoDefault(true);

OMEdit/OMEditLIB/Element/ElementProperties.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ class ParametersScrollArea : public QScrollArea
144144
public:
145145
ParametersScrollArea();
146146
virtual QSize minimumSizeHint() const override;
147+
int groupBoxesSize() {return mGroupBoxesList.size();}
147148
void addGroupBox(GroupBox *pGroupBox);
148-
GroupBox *getGroupBox(QString title);
149+
GroupBox *getGroupBox(const QString &title);
150+
GroupBox *getGroupBox(int index) {return mGroupBoxesList.at(index);}
149151
QVBoxLayout* getLayout();
150152
private:
151153
QWidget *mpWidget;
@@ -186,8 +188,7 @@ class ElementParameters : public QDialog
186188
void createTabsGroupBoxesAndParametersHelper(LibraryTreeItem *pLibraryTreeItem, bool useInsert = false);
187189
void fetchComponentModifiers();
188190
void fetchExtendsModifiers();
189-
Parameter* findParameter(LibraryTreeItem *pLibraryTreeItem, const QString &parameter,
190-
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
191+
Parameter* findParameter(LibraryTreeItem *pLibraryTreeItem, const QString &parameter, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
191192
Parameter* findParameter(const QString &parameter, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
192193
public slots:
193194
void commentLinkClicked(QString link);

0 commit comments

Comments
 (0)