Added menu actions "Save settings..." and "Load settings..."

git-svn-id: http://find-object.googlecode.com/svn/trunk/find_object@198 620bd6b2-0a58-f614-fd9a-1bd335dccda9
This commit is contained in:
matlabbe 2014-03-24 21:11:02 +00:00
parent 7a3080cd43
commit 3eda414d91
3 changed files with 98 additions and 12 deletions

View File

@ -38,9 +38,10 @@
#include "utilite/UDirectory.h"
// Camera ownership transferred
MainWindow::MainWindow(Camera * camera, QWidget * parent) :
MainWindow::MainWindow(Camera * camera, const QString & settings, QWidget * parent) :
QMainWindow(parent),
camera_(camera),
settings_(settings),
likelihoodCurve_(0),
lowestRefreshRate_(99),
objectsModified_(false)
@ -67,9 +68,14 @@ MainWindow::MainWindow(Camera * camera, QWidget * parent) :
ui_->dockWidget_plot->setVisible(false);
ui_->widget_controls->setVisible(false);
if(settings_.isEmpty())
{
settings_ = Settings::iniDefaultPath();
}
QByteArray geometry;
QByteArray state;
Settings::loadSettings(Settings::iniDefaultPath(), &geometry, &state);
Settings::loadSettings(settings_, &geometry, &state);
this->restoreGeometry(geometry);
this->restoreState(state);
@ -121,6 +127,8 @@ connect(ui_->toolBox, SIGNAL(parametersChanged(const QStringList &)), this, SLOT
connect(ui_->actionAbout, SIGNAL(triggered()), aboutDialog_ , SLOT(exec()));
connect(ui_->actionRestore_all_default_settings, SIGNAL(triggered()), ui_->toolBox, SLOT(resetAllPages()));
connect(ui_->actionRemove_all_objects, SIGNAL(triggered()), this, SLOT(removeAllObjects()));
connect(ui_->actionSave_settings, SIGNAL(triggered()), this, SLOT(saveSettings()));
connect(ui_->actionLoad_settings, SIGNAL(triggered()), this, SLOT(loadSettings()));
connect(ui_->pushButton_play, SIGNAL(clicked()), this, SLOT(startProcessing()));
connect(ui_->pushButton_stop, SIGNAL(clicked()), this, SLOT(stopProcessing()));
@ -182,7 +190,7 @@ void MainWindow::closeEvent(QCloseEvent * event)
}
if(quit)
{
Settings::saveSettings(Settings::iniDefaultPath(), this->saveGeometry(), this->saveState());
Settings::saveSettings(settings_, this->saveGeometry(), this->saveState());
event->accept();
}
else
@ -201,6 +209,65 @@ void MainWindow::setSourceImageText(const QString & text)
ui_->imageView_source->setTextLabel(text);
}
void MainWindow::loadSettings()
{
QString path = QFileDialog::getOpenFileName(this, tr("Load settings..."), Settings::workingDirectory(), "*.ini");
if(!path.isEmpty())
{
if(QFileInfo(path).suffix().compare("ini") != 0)
{
path.append(".ini");
}
loadSettings(path);
}
}
void MainWindow::saveSettings()
{
QString path = QFileDialog::getSaveFileName(this, tr("Save settings..."), Settings::workingDirectory(), "*.ini");
if(!path.isEmpty())
{
if(QFileInfo(path).suffix().compare("ini") != 0)
{
path.append(".ini");
}
saveSettings(path);
}
}
bool MainWindow::loadSettings(const QString & path)
{
if(!path.isEmpty() && QFileInfo(path).suffix().compare("ini") == 0)
{
QByteArray geometry;
QByteArray state;
Settings::loadSettings(path, &geometry, &state);
this->restoreGeometry(geometry);
this->restoreState(state);
//update parameters tool box
const ParametersMap & parameters = Settings::getParameters();
for(ParametersMap::const_iterator iter = parameters.begin(); iter!= parameters.constEnd(); ++iter)
{
ui_->toolBox->updateParameter(iter.key());
}
return true;
}
printf("Path \"%s\" not valid (should be *.ini)\n", path.toStdString().c_str());
return false;
}
bool MainWindow::saveSettings(const QString & path)
{
if(!path.isEmpty() && QFileInfo(path).suffix().compare("ini") == 0)
{
Settings::saveSettings(path, this->saveGeometry(), this->saveState());
return true;
}
printf("Path \"%s\" not valid (should be *.ini)\n", path.toStdString().c_str());
return false;
}
int MainWindow::loadObjects(const QString & dirPath)
{
int loadedObjects = 0;

View File

@ -33,9 +33,12 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
MainWindow(Camera * camera = 0, QWidget * parent = 0);
MainWindow(Camera * camera = 0, const QString & settings = "", QWidget * parent = 0);
virtual ~MainWindow();
bool loadSettings(const QString & path);
bool saveSettings(const QString & path);
int loadObjects(const QString & dirPath);
void saveObjects(const QString & dirPath);
@ -51,6 +54,8 @@ public slots:
void pauseProcessing();
private slots:
void loadSettings();
void saveSettings();
void loadObjects();
bool saveObjects();
void addObjectFromScene();
@ -80,6 +85,7 @@ private:
private:
Ui_mainWindow * ui_;
Camera * camera_;
QString settings_;
rtabmap::PdfPlotCurve * likelihoodCurve_;
AboutDialog * aboutDialog_;
QList<ObjWidget*> objects_;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>825</width>
<height>441</height>
<width>826</width>
<height>448</height>
</rect>
</property>
<property name="windowTitle">
@ -108,7 +108,7 @@
<widget class="QWidget" name="widget_controls" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>-1</number>
<number>6</number>
</property>
<property name="margin">
<number>0</number>
@ -202,8 +202,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>825</width>
<height>22</height>
<width>826</width>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -213,6 +213,9 @@
<addaction name="actionLoad_objects"/>
<addaction name="actionSave_objects"/>
<addaction name="separator"/>
<addaction name="actionLoad_settings"/>
<addaction name="actionSave_settings"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuEdit">
@ -474,8 +477,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>114</height>
<width>360</width>
<height>120</height>
</rect>
</property>
<attribute name="label">
@ -533,7 +536,7 @@
<x>0</x>
<y>0</y>
<width>198</width>
<height>314</height>
<height>318</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_objects">
@ -696,6 +699,16 @@
<string>Camera from directory of images...</string>
</property>
</action>
<action name="actionSave_settings">
<property name="text">
<string>Save settings...</string>
</property>
</action>
<action name="actionLoad_settings">
<property name="text">
<string>Load settings...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>