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) GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
: QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0), : 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()); setIconSize(owner.iconSize());
connect(&owner, SIGNAL(iconSizeChanged(QSize)), this, 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() void GuiToolbar::fill()
{ {
if (filled_) if (filled_)

View File

@ -69,6 +69,10 @@ class GuiToolbar : public QToolBar
public: public:
/// ///
GuiToolbar(ToolbarInfo const &, GuiView &); 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); void setVisibility(int visibility);
@ -86,6 +90,9 @@ public:
/// Restore session settings. /// Restore session settings.
void restoreSession(); void restoreSession();
///
bool isRestored() const;
/// Refresh the contents of the bar. /// Refresh the contents of the bar.
void update(bool in_math, bool in_table, bool review, void update(bool in_math, bool in_table, bool review,
bool in_mathmacrotemplate, bool in_ipa); bool in_mathmacrotemplate, bool in_ipa);
@ -123,6 +130,8 @@ private:
ToolbarInfo const & tbinfo_; ToolbarInfo const & tbinfo_;
/// ///
bool filled_; bool filled_;
///
bool restored_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -674,6 +674,16 @@ bool GuiView::restoreLayout()
if (!restoreState(settings.value("layout").toByteArray(), 0)) if (!restoreState(settings.value("layout").toByteArray(), 0))
initToolbars(); 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(); updateDialogs();
return true; return true;
} }
@ -716,42 +726,47 @@ void GuiView::initToolbars()
// extracts the toolbars from the backend // extracts the toolbars from the backend
Toolbars::Infos::iterator cit = guiApp->toolbars().begin(); Toolbars::Infos::iterator cit = guiApp->toolbars().begin();
Toolbars::Infos::iterator end = guiApp->toolbars().end(); Toolbars::Infos::iterator end = guiApp->toolbars().end();
for (; cit != end; ++cit) { for (; cit != end; ++cit)
GuiToolbar * tb = toolbar(cit->name); initToolbar(cit->name);
if (!tb) }
continue;
int const visibility = guiApp->toolbars().defaultVisibility(cit->name);
bool newline = !(visibility & Toolbars::SAMEROW);
tb->setVisible(false);
tb->setVisibility(visibility);
if (visibility & Toolbars::TOP) {
if (newline)
addToolBarBreak(Qt::TopToolBarArea);
addToolBar(Qt::TopToolBarArea, tb);
}
if (visibility & Toolbars::BOTTOM) { void GuiView::initToolbar(string const & name)
if (newline) {
addToolBarBreak(Qt::BottomToolBarArea); GuiToolbar * tb = toolbar(name);
addToolBar(Qt::BottomToolBarArea, tb); if (!tb)
} return;
int const visibility = guiApp->toolbars().defaultVisibility(name);
bool newline = !(visibility & Toolbars::SAMEROW);
tb->setVisible(false);
tb->setVisibility(visibility);
if (visibility & Toolbars::LEFT) { if (visibility & Toolbars::TOP) {
if (newline) if (newline)
addToolBarBreak(Qt::LeftToolBarArea); addToolBarBreak(Qt::TopToolBarArea);
addToolBar(Qt::LeftToolBarArea, tb); addToolBar(Qt::TopToolBarArea, tb);
}
if (visibility & Toolbars::RIGHT) {
if (newline)
addToolBarBreak(Qt::RightToolBarArea);
addToolBar(Qt::RightToolBarArea, tb);
}
if (visibility & Toolbars::ON)
tb->setVisible(true);
} }
if (visibility & Toolbars::BOTTOM) {
if (newline)
addToolBarBreak(Qt::BottomToolBarArea);
addToolBar(Qt::BottomToolBarArea, tb);
}
if (visibility & Toolbars::LEFT) {
if (newline)
addToolBarBreak(Qt::LeftToolBarArea);
addToolBar(Qt::LeftToolBarArea, tb);
}
if (visibility & Toolbars::RIGHT) {
if (newline)
addToolBarBreak(Qt::RightToolBarArea);
addToolBar(Qt::RightToolBarArea, tb);
}
if (visibility & Toolbars::ON)
tb->setVisible(true);
} }

View File

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