Speed up exit time

Instantiating a single QSettings and using it for each ui element
can significantly shorten the time required to save the various
states at exit. The speed up can be better appreciated on *nix,
where the settings are saved on disk, rather than on Windows where
they are held in memory (in the registry).
This commit is contained in:
Enrico Forestieri 2017-10-18 22:11:56 +02:00
parent 74dbfc1b1b
commit 054b7c68a4
16 changed files with 32 additions and 31 deletions

View File

@ -275,9 +275,8 @@ QString Dialog::sessionKey() const
}
void Dialog::saveSession() const
void Dialog::saveSession(QSettings & settings) const
{
QSettings settings;
settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
}

View File

@ -20,6 +20,7 @@
#include <QString>
class QSettings;
class QWidget;
namespace lyx {
@ -72,7 +73,7 @@ public:
* This default implementation saves the geometry state.
* Reimplement to save more settings.
**/
virtual void saveSession() const;
virtual void saveSession(QSettings & settings) const;
/// Restore session settings.
/**

View File

@ -455,10 +455,9 @@ void GuiCharacter::dispatchParams()
}
void GuiCharacter::saveSession() const
void GuiCharacter::saveSession(QSettings & settings) const
{
Dialog::saveSession();
QSettings settings;
Dialog::saveSession(settings);
settings.setValue(sessionKey() + "/toggleall", toggleallCB->isChecked());
settings.setValue(sessionKey() + "/autoapply", autoapplyCB->isChecked());
}

View File

@ -74,7 +74,7 @@ private:
void dispatchParams();
bool isBufferDependent() const { return true; }
FuncCode getLfun() const { return LFUN_TEXTSTYLE_UPDATE; }
void saveSession() const;
void saveSession(QSettings & settings) const;
void restoreSession();
//@}

View File

@ -816,10 +816,9 @@ BiblioInfo const & GuiCitation::bibInfo() const
}
void GuiCitation::saveSession() const
void GuiCitation::saveSession(QSettings & settings) const
{
Dialog::saveSession();
QSettings settings;
Dialog::saveSession(settings);
settings.setValue(
sessionKey() + "/regex", regexp_->isChecked());
settings.setValue(

View File

@ -76,7 +76,7 @@ private:
void clearParams();
void dispatchParams();
bool isBufferDependent() const { return true; }
void saveSession() const;
void saveSession(QSettings & settings) const;
void restoreSession();
/** Disconnect from the inset when the Apply button is pressed.
* Allows easy insertion of multiple citations.

View File

@ -384,10 +384,9 @@ bool GuiParagraph::hasLabelwidth() const
}
void GuiParagraph::saveSession() const
void GuiParagraph::saveSession(QSettings & settings) const
{
Dialog::saveSession();
QSettings settings;
Dialog::saveSession(settings);
settings.setValue(sessionKey() + "/autoapply", synchronizedViewCB->isChecked());
}

View File

@ -39,7 +39,7 @@ public:
void enableView(bool enable);
bool isBufferDependent() const { return true; }
virtual FuncCode getLfun() const { return LFUN_PARAGRAPH_PARAMS_APPLY; }
void saveSession() const;
void saveSession(QSettings & settings) const;
void restoreSession();
//@}

View File

@ -224,10 +224,9 @@ void GuiProgressView::appendText(QString const & text)
}
void GuiProgressView::saveSession() const
void GuiProgressView::saveSession(QSettings & settings) const
{
Dialog::saveSession();
QSettings settings;
Dialog::saveSession(settings);
settings.setValue(
sessionKey() + "/autoclear", widget_->autoClearCB->isChecked());
settings.setValue(

View File

@ -61,7 +61,7 @@ public:
void updateView() {}
bool wantInitialFocus() const { return false; }
void restoreSession();
void saveSession() const;
void saveSession(QSettings & settings) const;
///@}
private Q_SLOTS:

View File

@ -353,9 +353,8 @@ QString GuiToolbar::sessionKey() const
}
void GuiToolbar::saveSession() const
void GuiToolbar::saveSession(QSettings & settings) const
{
QSettings settings;
settings.setValue(sessionKey() + "/visibility", visibility_);
}

View File

@ -20,6 +20,8 @@
#include <QToolBar>
#include <QToolButton>
class QSettings;
namespace lyx {
class DocumentClass;
@ -84,7 +86,7 @@ public:
**/
QString sessionKey() const;
/// Save session settings.
void saveSession() const;
void saveSession(QSettings & settings) const;
/// Restore session settings.
void restoreSession();

View File

@ -726,14 +726,16 @@ void GuiView::saveLayout() const
void GuiView::saveUISettings() const
{
QSettings settings;
// Save the toolbar private states
ToolbarMap::iterator end = d.toolbars_.end();
for (ToolbarMap::iterator it = d.toolbars_.begin(); it != end; ++it)
it->second->saveSession();
it->second->saveSession(settings);
// Now take care of all other dialogs
map<string, DialogPtr>::const_iterator it = d.dialogs_.begin();
for (; it!= d.dialogs_.end(); ++it)
it->second->saveSession();
it->second->saveSession(settings);
}

View File

@ -371,9 +371,9 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event)
QWidget::resizeEvent(event);
}
void ViewSourceWidget::saveSession(QString const & session_key) const
void ViewSourceWidget::saveSession(QSettings & settings, QString const & session_key) const
{
QSettings settings;
settings.setValue(session_key + "/output", toqstr(view_format_));
settings.setValue(session_key + "/contents", contentsCO->currentIndex());
settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked());
@ -457,10 +457,10 @@ void GuiViewSource::updateTitle()
}
void GuiViewSource::saveSession() const
void GuiViewSource::saveSession(QSettings & settings) const
{
Dialog::saveSession();
widget_->saveSession(sessionKey());
Dialog::saveSession(settings);
widget_->saveSession(settings, sessionKey());
}

View File

@ -43,7 +43,7 @@ public:
/// returns true if the string has changed
bool setText(QString const & qstr = QString());
///
void saveSession(QString const & session_key) const;
void saveSession(QSettings & settings, QString const & session_key) const;
///
void restoreSession(QString const & session_key);
@ -116,7 +116,7 @@ public:
bool canApplyToReadOnly() const { return true; }
void updateView();
void enableView(bool enable);
void saveSession() const;
void saveSession(QSettings & settings) const;
void restoreSession();
bool wantInitialFocus() const { return false; }
///@}

View File

@ -26,6 +26,8 @@ What's new
- Cache information on exportable formats (bug 9980).
- Shorten the time required to save the session state on exit.
* DOCUMENTATION AND LOCALIZATION