Skip to content
Snippets Groups Projects
Commit a75794c2 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[m.i1029] Restore view on opening project (Closes #1029)

Merging branch 'm.i1029'  into 'main'.

See merge request !2748
parents 4136bdea 8c29fbb5
No related branches found
No related tags found
1 merge request!2748Restore view on opening project
Pipeline #169253 failed
...@@ -51,6 +51,7 @@ const QString ActiveView("ActiveView"); ...@@ -51,6 +51,7 @@ const QString ActiveView("ActiveView");
ProjectDocument::ProjectDocument() ProjectDocument::ProjectDocument()
: m_project_name("Untitled") : m_project_name("Untitled")
, m_modified(false) , m_modified(false)
, m_last_view_active(0)
, m_instruments(std::make_unique<InstrumentsSet>()) , m_instruments(std::make_unique<InstrumentsSet>())
, m_samples(std::make_unique<SamplesSet>()) , m_samples(std::make_unique<SamplesSet>())
, m_datafiles(std::make_unique<DatafilesSet>()) , m_datafiles(std::make_unique<DatafilesSet>())
...@@ -171,6 +172,7 @@ void ProjectDocument::writeTo(QXmlStreamWriter* w) const ...@@ -171,6 +172,7 @@ void ProjectDocument::writeTo(QXmlStreamWriter* w) const
XML::writeTaggedElement(w, Tag::SamplesSet, *m_samples); XML::writeTaggedElement(w, Tag::SamplesSet, *m_samples);
XML::writeTaggedElement(w, Tag::RealModel, *m_datafiles); XML::writeTaggedElement(w, Tag::RealModel, *m_datafiles);
XML::writeTaggedElement(w, Tag::JobsSet, *m_jobs); XML::writeTaggedElement(w, Tag::JobsSet, *m_jobs);
XML::writeTaggedValue(w, Tag::ActiveView, m_last_view_active);
} }
void ProjectDocument::writeProject(QIODevice* device) void ProjectDocument::writeProject(QIODevice* device)
...@@ -208,6 +210,8 @@ void ProjectDocument::readFrom(QXmlStreamReader* r) ...@@ -208,6 +210,8 @@ void ProjectDocument::readFrom(QXmlStreamReader* r)
XML::readTaggedElement(r, tag, *m_datafiles); XML::readTaggedElement(r, tag, *m_datafiles);
else if (tag == Tag::JobsSet) else if (tag == Tag::JobsSet)
XML::readTaggedElement(r, tag, *m_jobs); XML::readTaggedElement(r, tag, *m_jobs);
else if (tag == Tag::ActiveView)
m_last_view_active = XML::readTaggedInt(r, tag);
else else
r->skipCurrentElement(); r->skipCurrentElement();
} }
......
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
void loadProjectFileWithData(const QString& projectPullPath); void loadProjectFileWithData(const QString& projectPullPath);
void setModified(); void setModified();
bool isModified() const { return m_modified; }
QString projectDir() const { return m_project_dir; } QString projectDir() const { return m_project_dir; }
QString projectName() const { return m_project_name; } QString projectName() const { return m_project_name; }
...@@ -58,7 +59,8 @@ public: ...@@ -58,7 +59,8 @@ public:
QString projectFullPath() const; QString projectFullPath() const;
bool hasValidNameAndPath() const; bool hasValidNameAndPath() const;
bool isModified() const { return m_modified; } uint viewId() const { return m_last_view_active; }
void setViewId(uint id) { m_last_view_active = id; }
const InstrumentsSet* instruments() const { return m_instruments.get(); }; const InstrumentsSet* instruments() const { return m_instruments.get(); };
const SamplesSet* samples() const { return m_samples.get(); }; const SamplesSet* samples() const { return m_samples.get(); };
...@@ -89,6 +91,7 @@ private: ...@@ -89,6 +91,7 @@ private:
QString m_project_dir; QString m_project_dir;
QString m_project_name; QString m_project_name;
bool m_modified; bool m_modified;
uint m_last_view_active;
std::unique_ptr<InstrumentsSet> m_instruments; std::unique_ptr<InstrumentsSet> m_instruments;
std::unique_ptr<SamplesSet> m_samples; std::unique_ptr<SamplesSet> m_samples;
std::unique_ptr<DatafilesSet> m_datafiles; std::unique_ptr<DatafilesSet> m_datafiles;
......
...@@ -106,12 +106,28 @@ QWidget* CentralWidget::currentView() const ...@@ -106,12 +106,28 @@ QWidget* CentralWidget::currentView() const
void CentralWidget::raiseView(int viewId) void CentralWidget::raiseView(int viewId)
{ {
ASSERT(checkViewId(viewId));
if (m_views_stack->currentIndex() != viewId) { if (m_views_stack->currentIndex() != viewId) {
m_views_stack->setCurrentIndex(viewId); m_views_stack->setCurrentIndex(viewId);
gDoc->setViewId(viewId);
emit currentViewChanged(); emit currentViewChanged();
} }
} }
void CentralWidget::restoreView(int viewId)
{
ASSERT(checkViewId(viewId));
m_views_stack->setCurrentIndex(viewId);
m_view_selection_buttons->button(viewId)->setChecked(true);
}
bool CentralWidget::checkViewId(int viewId) const
{
return viewId >= 0 && viewId < m_views_stack->count();
}
void CentralWidget::updateViews(bool open) void CentralWidget::updateViews(bool open)
{ {
if (!open) if (!open)
......
...@@ -38,11 +38,15 @@ public: ...@@ -38,11 +38,15 @@ public:
void updateViews(bool open); void updateViews(bool open);
void raiseView(int viewId);
void restoreView(int viewId);
signals: signals:
void currentViewChanged(); void currentViewChanged();
private: private:
enum ViewId { Datafile, Instrument, Sample, Simulation, Job }; enum ViewId { Datafile, Instrument, Sample, Simulation, Job };
bool checkViewId(int viewId) const;
void addButton(ViewId id, const QIcon& icon, const QString& title, const QString& tooltip); void addButton(ViewId id, const QIcon& icon, const QString& title, const QString& tooltip);
QToolButton* createViewSelectionButton() const; QToolButton* createViewSelectionButton() const;
...@@ -50,8 +54,6 @@ private: ...@@ -50,8 +54,6 @@ private:
//! Recalculate the size of the view selection buttons to show complete button text //! Recalculate the size of the view selection buttons to show complete button text
void updateViewSelectionButtonsGeometry() const; void updateViewSelectionButtonsGeometry() const;
void raiseView(int viewId);
QProgressBar* m_progress_bar; QProgressBar* m_progress_bar;
QButtonGroup* m_view_selection_buttons; QButtonGroup* m_view_selection_buttons;
QStackedLayout* m_views_stack; QStackedLayout* m_views_stack;
......
...@@ -116,6 +116,8 @@ void MainWindow::onDocumentOpenedOrClosed(bool open) ...@@ -116,6 +116,8 @@ void MainWindow::onDocumentOpenedOrClosed(bool open)
{ {
updateTitle(); updateTitle();
m_central_widget->updateViews(open); m_central_widget->updateViews(open);
if (open)
m_central_widget->restoreView(gDoc->viewId());
} }
void MainWindow::onDocumentModified() void MainWindow::onDocumentModified()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment