Skip to content

Commit

Permalink
export settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainthery committed Apr 4, 2017
1 parent ba1a301 commit c20958c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
35 changes: 21 additions & 14 deletions schnapps/core/schnapps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ SCHNApps::SCHNApps(const QString& app_path, const QString& settings_path, SCHNAp

SCHNApps::~SCHNApps()
{
// make a copy of overwrite settings
QFile old(settings_path_);
QString copy_name = settings_path_.left(settings_path_.length()-5) + ".back.json";
old.copy(copy_name);

settings_->to_file(settings_path_);

// first safely unload every plugins (this has to be done before the views get deleted)
Expand Down Expand Up @@ -498,23 +503,12 @@ void SCHNApps::set_selected_view(const QString& name)

void SCHNApps::cycle_selected_view()
{
//auto it = views_.find(selected_view_->get_name());
//if ((it == views_.end()) && (!views_.empty()))
// set_selected_view(views_.begin()->second.get());
//else
//{
// it++;
// if (it == views_.end())
// set_selected_view(views_.begin()->second.get());
// else
// set_selected_view(it->second.get());
//}
auto it = views_.find(selected_view_->get_name());
it++;
if (it == views_.end())
set_selected_view(views_.begin()->second.get());
else
set_selected_view(it->second.get());
it = views_.begin();

set_selected_view(it->second.get());
}

View* SCHNApps::split_view(const QString& name, Qt::Orientation orientation)
Expand Down Expand Up @@ -647,4 +641,17 @@ void SCHNApps::set_window_size(int w, int h)
window_->resize(w, h);
}


/*********************************************************
* EXPORT SETTINGS
*********************************************************/

void SCHNApps::export_settings()
{
QString filename = QFileDialog::getSaveFileName(nullptr, "Export", settings_path_, "Settings Files (*.json)");
if (! filename.isEmpty())
settings_->to_file(filename);

}

} // namespace schnapps
4 changes: 4 additions & 0 deletions schnapps/core/schnapps.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ public slots:
void schnapps_window_closing();
SCHNAppsWindow* get_window() { return window_; }


public slots:
void export_settings();

signals:

void camera_added(Camera*);
Expand Down
8 changes: 7 additions & 1 deletion schnapps/core/schnapps.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<x>0</x>
<y>0</y>
<width>1106</width>
<height>25</height>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -33,6 +33,7 @@
<addaction name="action_TogglePluginDock"/>
<addaction name="separator"/>
<addaction name="action_Settings"/>
<addaction name="action_Export_settings"/>
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
Expand Down Expand Up @@ -76,6 +77,11 @@
<string>Settings</string>
</property>
</action>
<action name="action_Export_settings">
<property name="text">
<string>Export settings</string>
</property>
</action>
</widget>
<resources/>
<connections>
Expand Down
2 changes: 2 additions & 0 deletions schnapps/core/schnapps_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ SCHNAppsWindow::SCHNAppsWindow(const QString& app_path, const QString& settings_
connect(action_Settings, SIGNAL(triggered()), settings_widget_.get(), SLOT(display_setting_widget()));

schnapps_ = cgogn::make_unique<SCHNApps>(app_path, settings_path, this);

connect(action_Export_settings, SIGNAL(triggered()), schnapps_.get(), SLOT(export_settings()));
}

SCHNAppsWindow::~SCHNAppsWindow()
Expand Down

0 comments on commit c20958c

Please sign in to comment.