Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SkywardHub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
SkywardHub
Commits
30e7ee51
Commit
30e7ee51
authored
8 months ago
by
Alberto Nidasio
Committed by
Alberto Nidasio
8 months ago
Browse files
Options
Downloads
Patches
Plain Diff
[Tabs] Fixed bug when removing tabs (
#15
)
parent
4ec3d908
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!38
[Tabs] Fixed bug when removing tabs (#15)
Pipeline
#9879
passed
8 months ago
Stage: lint
Stage: build
Stage: release
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/Modules/Tabs/TabsModule.cpp
+32
-30
32 additions, 30 deletions
src/shared/Modules/Tabs/TabsModule.cpp
src/shared/Modules/Tabs/TabsModule.h
+0
-1
0 additions, 1 deletion
src/shared/Modules/Tabs/TabsModule.h
with
32 additions
and
31 deletions
src/shared/Modules/Tabs/TabsModule.cpp
+
32
−
30
View file @
30e7ee51
...
...
@@ -43,11 +43,21 @@ XmlObject TabsModule::toXmlObject()
{
XmlObject
obj
=
Module
::
toXmlObject
();
for
(
int
i
=
0
;
i
!=
c
ontent
Modules
.
size
();
i
++
)
for
(
int
i
=
0
;
i
!=
tabC
ontent
s
->
count
();
i
++
)
{
XmlObject
tab
(
"tab"
);
tab
.
addAttribute
(
"name"
,
tabNames
->
item
(
i
)
->
text
());
tab
.
addChild
(
contentModules
.
at
(
i
)
->
toXmlObject
());
if
(
auto
module
=
qobject_cast
<
Module
*>
(
tabContents
->
widget
(
i
)))
{
tab
.
addChild
(
module
->
toXmlObject
());
}
else
{
qCritical
()
<<
"Unable to save tab "
<<
tabNames
->
item
(
i
)
->
text
()
<<
" due to failed when casting widget to Module*"
;
continue
;
// Skip this tab
}
obj
.
addChild
(
tab
);
}
...
...
@@ -58,13 +68,8 @@ void TabsModule::fromXmlObject(const XmlObject& xmlObject)
{
// Discard previous content
tabNames
->
clear
();
for
(
int
i
=
contentModules
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
auto
*
module
=
contentModules
[
i
];
contentModules
.
pop_back
();
tabContents
->
removeWidget
(
tabContents
->
widget
(
i
));
delete
module
;
}
for
(
int
i
=
tabContents
->
count
()
-
1
;
i
>=
0
;
i
--
)
delete
tabContents
->
widget
(
i
);
for
(
int
i
=
0
;
i
<
xmlObject
.
childCount
();
++
i
)
{
...
...
@@ -84,12 +89,14 @@ void TabsModule::fromXmlObject(const XmlObject& xmlObject)
}
else
{
// TODO: what should we do?
qCritical
()
<<
"Failed to instantiate module"
<<
tabNode
.
getAttribute
(
"name"
,
generateUniqueTabName
());
}
}
// If the tabs are left empty, add a single tab with an empty module
if
(
contentModules
.
size
()
==
0
)
if
(
tabNames
->
count
()
==
0
)
addTab
(
generateUniqueTabName
(),
ModulesList
::
getInstance
().
instantiateModule
(
ModuleId
::
EMPTY
));
...
...
@@ -107,7 +114,6 @@ void TabsModule::addTab(const QString& tabName, Module* module)
tabNames
->
addItem
(
listItem
);
tabContents
->
addWidget
(
module
);
contentModules
.
append
(
module
);
// We set the correct tabName after the widget is added
tabNames
->
setCurrentItem
(
listItem
);
...
...
@@ -128,45 +134,39 @@ void TabsModule::replaceTab(Module* oldModule, Module* newModule)
if
(
oldModule
==
newModule
)
return
;
int
index
=
contentModules
.
indexOf
(
oldModule
);
// Check if the old module is a child
// Get the index of the old module
int
index
=
tabContents
->
indexOf
(
oldModule
);
if
(
index
==
-
1
)
return
;
// Can replace only current tab
tabNames
->
setCurrentItem
(
tabNames
->
item
(
index
));
contentModules
.
replace
(
index
,
newModule
);
// Replace the module
tabContents
->
insertWidget
(
index
,
newModule
);
tabContents
->
removeWidget
(
oldModule
);
tabContents
->
setCurrentWidget
(
newModule
);
tabContents
->
removeWidget
(
oldModule
);
delete
oldModule
;
tabContents
->
update
();
connect
(
newModule
,
&
Module
::
replaceMe
,
this
,
&
TabsModule
::
replaceTab
);
connect
(
newModule
,
&
Module
::
closeMe
,
this
,
&
TabsModule
::
closeTab
);
delete
oldModule
;
}
void
TabsModule
::
closeTab
(
Module
*
module
)
{
int
index
=
c
ontent
Modules
.
indexOf
(
module
);
int
index
=
tabC
ontent
s
->
indexOf
(
module
);
// Check if the given module is a child
if
(
index
==
-
1
)
return
;
// If there is only one child, then close the entire tabs module
if
(
c
ontent
Modules
.
count
()
==
1
)
if
(
tabC
ontent
s
->
count
()
==
1
)
{
emit
closeMe
(
this
);
return
;
}
contentModules
.
removeAt
(
index
);
tabContents
->
removeWidget
(
tabContents
->
widget
(
index
));
tabNames
->
takeItem
(
index
);
tabContents
->
removeWidget
(
module
);
delete
tabNames
->
item
(
index
);
tabNames
->
setCurrentItem
(
tabNames
->
item
(
index
==
0
?
0
:
index
-
1
));
}
...
...
@@ -202,8 +202,11 @@ void TabsModule::onMenuNewTabClick()
void
TabsModule
::
onMenuDeleteTabClick
()
{
delete
contentModules
.
at
(
tabNames
->
currentRow
());
tabNames
->
removeItemWidget
(
tabNames
->
currentItem
());
if
(
auto
module
=
qobject_cast
<
Module
*>
(
tabContents
->
currentWidget
()))
closeTab
(
module
);
else
qCritical
()
<<
"Unable to close tab due to failed when casting widget "
"to Module*"
;
}
void
TabsModule
::
onMenuRenameTabClick
()
...
...
@@ -231,7 +234,6 @@ void TabsModule::setupUi()
QBoxLayout
*
outerLayout
=
new
QBoxLayout
(
QBoxLayout
::
TopToBottom
,
this
);
outerLayout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
outerLayout
->
setSpacing
(
0
);
outerLayout
->
addWidget
(
tabNames
);
outerLayout
->
addWidget
(
tabContents
);
}
This diff is collapsed.
Click to expand it.
src/shared/Modules/Tabs/TabsModule.h
+
0
−
1
View file @
30e7ee51
...
...
@@ -53,5 +53,4 @@ private:
QListWidget
*
tabNames
;
QStackedWidget
*
tabContents
;
QList
<
Module
*>
contentModules
;
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment