Fix zombie toolbars (bug 8520)

If there is a new toolbar, it will not be restored by Qt and we need to
initialize it ourselves. However, it is not so easy to find out which
toolbars are restored by Qt and which are not. For this, the setVisible
function of GuiToolbar is 'misused'. If the visibility is set, the toolbar
must have been restored by Qt and we should leave it alone.
This commit is contained in:
Vincent van Ravesteijn 2013-05-19 22:04:29 +02:00
parent 97405fa623
commit c8d685c665
4 changed files with 76 additions and 33 deletions

View File

@ -53,7 +53,8 @@ namespace frontend {
GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
: QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false)
owner_(owner), command_buffer_(0), tbinfo_(tbinfo), filled_(false),
restored_(false)
{
setIconSize(owner.iconSize());
connect(&owner, SIGNAL(iconSizeChanged(QSize)), this,
@ -68,6 +69,22 @@ GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
}
void GuiToolbar::setVisible(bool visible)
{
// This is a hack to find out which toolbars have been restored by
// MainWindow::restoreState and which toolbars should be initialized
// by us (i.e., new toolbars)
restored_ = true;
QToolBar::setVisible(visible);
}
bool GuiToolbar::isRestored() const
{
return restored_;
}
void GuiToolbar::fill()
{
if (filled_)

View File

@ -70,6 +70,10 @@ public:
///
GuiToolbar(ToolbarInfo const &, GuiView &);
/// Reimplemented from QToolbar to detect whether the
/// toolbar is restored with MainWindow::restoreState().
void setVisible(bool visible);
///
void setVisibility(int visibility);
@ -86,6 +90,9 @@ public:
/// Restore session settings.
void restoreSession();
///
bool isRestored() const;
/// Refresh the contents of the bar.
void update(bool in_math, bool in_table, bool review,
bool in_mathmacrotemplate, bool in_ipa);
@ -123,6 +130,8 @@ private:
ToolbarInfo const & tbinfo_;
///
bool filled_;
///
bool restored_;
};
} // namespace frontend

View File

@ -674,6 +674,16 @@ bool GuiView::restoreLayout()
if (!restoreState(settings.value("layout").toByteArray(), 0))
initToolbars();
// init the toolbars that have not been restored
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::iterator end = guiApp->toolbars().end();
for (; cit != end; ++cit) {
GuiToolbar * tb = toolbar(cit->name);
if (tb && !tb->isRestored())
initToolbar(cit->name);
}
updateDialogs();
return true;
}
@ -716,11 +726,17 @@ void GuiView::initToolbars()
// extracts the toolbars from the backend
Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::iterator end = guiApp->toolbars().end();
for (; cit != end; ++cit) {
GuiToolbar * tb = toolbar(cit->name);
for (; cit != end; ++cit)
initToolbar(cit->name);
}
void GuiView::initToolbar(string const & name)
{
GuiToolbar * tb = toolbar(name);
if (!tb)
continue;
int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
return;
int const visibility = guiApp->toolbars().defaultVisibility(name);
bool newline = !(visibility & Toolbars::SAMEROW);
tb->setVisible(false);
tb->setVisibility(visibility);
@ -751,7 +767,6 @@ void GuiView::initToolbars()
if (visibility & Toolbars::ON)
tb->setVisible(true);
}
}

View File

@ -344,6 +344,8 @@ private:
///
void initToolbars();
///
void initToolbar(std::string const & name);
///
bool lfunUiToggle(std::string const & ui_component);
///
void toggleFullScreen();