From: Guillaume Munch Date: Fri, 31 Jul 2015 00:05:54 +0000 (+0100) Subject: Better session management for the source panel. X-Git-Tag: 2.2.0alpha1~327 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=120c99ae60fb6d429148ca653183557db4e1e421;p=features.git Better session management for the source panel. We now remember the previous GUI values across sessions. --- diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index 50cfa31257..aa1b30dc62 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -56,13 +57,15 @@ ViewSourceWidget::ViewSourceWidget() connect(autoUpdateCB, SIGNAL(toggled(bool)), updatePB, SLOT(setDisabled(bool))); connect(autoUpdateCB, SIGNAL(toggled(bool)), - this, SLOT(updateViewNow())); + this, SLOT(contentsChanged())); connect(masterPerspectiveCB, SIGNAL(toggled(bool)), - this, SLOT(updateViewNow())); + this, SLOT(contentsChanged())); connect(updatePB, SIGNAL(clicked()), this, SLOT(updateViewNow())); connect(outputFormatCO, SIGNAL(activated(int)), - this, SLOT(setViewFormat())); + this, SLOT(setViewFormat(int))); + connect(outputFormatCO, SIGNAL(activated(int)), + this, SLOT(contentsChanged())); // setting the update timer update_timer_->setSingleShot(true); @@ -149,11 +152,10 @@ void ViewSourceWidget::contentsChanged() } -void ViewSourceWidget::setViewFormat() +void ViewSourceWidget::setViewFormat(int const index) { - view_format_ = outputFormatCO->itemData( - outputFormatCO->currentIndex()).toString(); - updateViewNow(); + outputFormatCO->setCurrentIndex(index); + view_format_ = outputFormatCO->itemData(index).toString(); } @@ -244,7 +246,7 @@ void ViewSourceWidget::updateDefaultFormat() if (qformat == view_format_) index = outputFormatCO->count() -1; } - outputFormatCO->setCurrentIndex(index); + setViewFormat(index); outputFormatCO->blockSignals(false); } @@ -262,6 +264,35 @@ void ViewSourceWidget::resizeEvent (QResizeEvent * event) QWidget::resizeEvent(event); } +void ViewSourceWidget::saveSession(QString const & session_key) const +{ + QSettings settings; + settings.setValue(session_key + "/output", view_format_); + settings.setValue(session_key + "/contents", contentsCO->currentIndex()); + settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked()); + settings.setValue(session_key + "/masterview", + masterPerspectiveCB->isChecked()); +} + + +void ViewSourceWidget::restoreSession(QString const & session_key) +{ + QSettings settings; + view_format_ = settings.value(session_key + "/output", 0).toString(); + contentsCO->setCurrentIndex(settings + .value(session_key + "/contents", 0) + .toInt()); + masterPerspectiveCB->setChecked(settings + .value(session_key + "/masterview", false) + .toBool()); + bool const checked = settings + .value(session_key + "/autoupdate", true) + .toBool(); + autoUpdateCB->setChecked(checked); + if (checked) + updateView(); +} + GuiViewSource::GuiViewSource(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags) @@ -294,7 +325,7 @@ void GuiViewSource::enableView(bool enable) widget_->updateDefaultFormat(); if (!enable) // In the opposite case, updateView() will be called anyway. - widget_->updateView(); + widget_->contentsChanged(); } @@ -323,26 +354,14 @@ QString GuiViewSource::title() const void GuiViewSource::saveSession() const { Dialog::saveSession(); - QSettings settings; - // see below - // settings.setValue( - // sessionKey() + "/output", widget_->contentsCO->currentIndex()); - settings.setValue( - sessionKey() + "/autoupdate", widget_->autoUpdateCB->isChecked()); + widget_->saveSession(sessionKey()); } void GuiViewSource::restoreSession() { DockView::restoreSession(); - // FIXME: Full source updating is too slow to be done at startup. - //widget_->outputCO-setCurrentIndex( - // settings.value(sessionKey() + "/output", false).toInt()); - widget_->contentsCO->setCurrentIndex(0); - QSettings settings; - widget_->autoUpdateCB->setChecked( - settings.value(sessionKey() + "/autoupdate", true).toBool()); - widget_->updateView(); + widget_->restoreSession(sessionKey()); } diff --git a/src/frontends/qt4/GuiViewSource.h b/src/frontends/qt4/GuiViewSource.h index d9425ac090..ee664a275c 100644 --- a/src/frontends/qt4/GuiViewSource.h +++ b/src/frontends/qt4/GuiViewSource.h @@ -38,6 +38,10 @@ public: ViewSourceWidget(); /// void setBufferView(BufferView const * bv); + /// + void saveSession(QString const & session_key) const; + /// + void restoreSession(QString const & session_key); protected: /// @@ -49,8 +53,8 @@ public Q_SLOTS: /// schedule an update now void updateViewNow(); /// - void setViewFormat(); - /// + void setViewFormat(int const index); + // void updateDefaultFormat(); /// void contentsChanged();