Commit c86863a2 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Refactored settings related code a bit, improved menu modification functionality a bit.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17068 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 854ee1d8
......@@ -111,6 +111,12 @@ signals:
* @param _name Name of the menu
*/
virtual void addMenubarAction(QAction* _action, QString _name ) {};
/**
* Does the same as multiple calls to addMenubarAction except
* it doesn't insert a separator between the individual items.
*/
virtual void addMenubarActions(std::vector<QAction*> &_action, QString _name ) {};
};
......
......@@ -924,6 +924,10 @@ private slots:
/// Save current status to a settings file. Solicit file name through dialog.
void saveSettings();
/// Save current status to a the provided settings file
void saveSettings(QString filePath, bool is_saveObjectInfo, bool is_targetOnly, bool is_saveAll,
bool is_askOverwrite, bool is_saveProgramSettings, bool is_savePluginSettings);
/// Open Load Widget
void loadObject();
......
......@@ -991,6 +991,9 @@ void Core::loadPlugin(const QString& _filename,const bool _silent, QString& _lic
if ( checkSignal(plugin,"addMenubarAction(QAction*,QString)") )
connect(plugin , SIGNAL(addMenubarAction(QAction*,QString)),
coreWidget_ , SLOT(slotAddMenubarAction(QAction*,QString)),Qt::DirectConnection);
if ( checkSignal(plugin,"addMenubarActions(std::vector<QAction*>, QString)") )
connect(plugin , SIGNAL(addMenubarActions(std::vector<QAction*>,QString)),
coreWidget_ , SLOT(slotAddMenubarActions(std::vector<QAction*>,QString)),Qt::DirectConnection);
if ( checkSignal(plugin,"getMenubarMenu (QString,QMenu*&,bool)") )
connect(plugin , SIGNAL(getMenubarMenu (QString,QMenu*&,bool)),
coreWidget_ , SLOT(slotGetMenubarMenu (QString,QMenu*&,bool)),Qt::DirectConnection);
......
......@@ -863,13 +863,12 @@ void Core::loadSettings(QString _filename){
QString newpath = _filename.section(OpenFlipper::Options::dirSeparator(),0,-2);
OpenFlipperSettings().setValue("Core/CurrentDir", newpath);
if ( _filename.endsWith("ini",Qt::CaseInsensitive) ) {
if ( _filename.endsWith("obj",Qt::CaseInsensitive) ) {
loadObject(_filename);
applyOptions();
} else {
// Loaded function for recent files. Load everything.
openIniFile(_filename,true,true,true);
applyOptions();
} else if ( _filename.endsWith("obj",Qt::CaseInsensitive) ) {
loadObject(_filename);
applyOptions();
}
}
......@@ -64,8 +64,6 @@ void Core::saveSettings(){
// generate the saveSettings-Dialog
// ========================================================================================
QString complete_name;
QFileDialog fileDialog( coreWidget_,
tr("Save Settings"),
OpenFlipperSettings().value("Core/CurrentDir").toString(),
......@@ -138,7 +136,7 @@ void Core::saveSettings(){
return;
}
complete_name = fileNames[0];
QString complete_name = fileNames[0];
//check the extension if its a known one
if ( !complete_name.endsWith(".ini", Qt::CaseInsensitive) && !complete_name.endsWith(".obj", Qt::CaseInsensitive) ){
......@@ -151,6 +149,18 @@ void Core::saveSettings(){
}
bool is_saveObjectInfo = saveObjectInfo->isChecked();
bool is_targetOnly = targetOnly->isChecked();
bool is_saveAll = saveAllBox->isChecked();
bool is_askOverwrite = askOverwrite->isChecked();
bool is_saveProgramSettings = saveProgramSettings->isChecked();
bool is_savePluginSettings = savePluginSettings->isChecked();
saveSettings(complete_name, is_saveObjectInfo, is_targetOnly, is_saveAll, is_askOverwrite, is_saveProgramSettings, is_savePluginSettings);
}
void Core::saveSettings(QString complete_name, bool is_saveObjectInfo, bool is_targetOnly, bool is_saveAll,
bool is_askOverwrite, bool is_saveProgramSettings, bool is_savePluginSettings){
// Get the chosen directory and remember it.
QFileInfo fileInfo(complete_name);
OpenFlipperSettings().setValue("Core/CurrentDir", fileInfo.absolutePath() );
......@@ -173,10 +183,10 @@ void Core::saveSettings(){
// Memorize saved files new file names
std::map<int,QString> savedFiles;
if ( saveObjectInfo->isChecked() ) {
if ( is_saveObjectInfo ) {
PluginFunctions::IteratorRestriction restriction;
if ( targetOnly->isChecked() )
if ( is_targetOnly )
restriction = PluginFunctions::TARGET_OBJECTS;
else
restriction = PluginFunctions::ALL_OBJECTS;
......@@ -233,7 +243,7 @@ void Core::saveSettings(){
{
QString filename;
if ( saveAllBox->isChecked() )
if ( is_saveAll )
{
// Use path of settings file for all objects
filename = fileInfo.absolutePath() + OpenFlipper::Options::dirSeparator() + o_it->name();
......@@ -310,7 +320,7 @@ void Core::saveSettings(){
}
// decide whether to use saveObject or saveObjectTo
if ( !QFile(filename).exists() || !askOverwrite->isChecked() )
if ( !QFile(filename).exists() || !is_askOverwrite )
saveObject( o_it->id(), filename);
else
saveObjectTo(o_it->id(), filename);
......@@ -325,22 +335,20 @@ void Core::saveSettings(){
// ========================================================================================
// Finally save all Settings
// ========================================================================================
if ( complete_name.endsWith("ini") ) {
// write to ini
writeIniFile( complete_name,
saveAllBox->isChecked(),
targetOnly->isChecked(),
saveProgramSettings->isChecked(),
savePluginSettings->isChecked(),
saveObjectInfo->isChecked(),
savedFiles);
} else if ( complete_name.endsWith("obj") ) {
if ( complete_name.endsWith("obj") ) {
//write to obj
writeObjFile(complete_name, saveAllBox->isChecked(), targetOnly->isChecked(), savedFiles);
writeObjFile(complete_name, is_saveAll, is_targetOnly, savedFiles);
} else {
// write to ini
writeIniFile( complete_name,
is_saveAll,
is_targetOnly,
is_saveProgramSettings,
is_savePluginSettings,
is_saveObjectInfo,
savedFiles);
}
// update status
......
......@@ -760,6 +760,7 @@ public:
private slots :
void slotAddMenubarAction( QAction* _action , QString _name );
void slotAddMenubarActions( std::vector<QAction*> _actions , QString _name );
void slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create);
private:
......
......@@ -82,6 +82,30 @@ void CoreWidget::slotAddMenubarAction( QAction* _action , QString _name ) {
}
void CoreWidget::slotAddMenubarActions( std::vector<QAction*> _actions , QString _name ) {
if (!menus_.contains(_name))
return;
if (_name == FILEMENU) {
fileMenu_->insertSeparator(fileMenuEnd_);
for (std::vector<QAction*>::iterator it = _actions.begin(); it != _actions.end(); ++it )
fileMenu_->insertAction(fileMenuEnd_, *it);
} else if (_name == ALGORITHMMENU) {
// We insert the algorithms menu if it is not available yet
if ( menuBar()->actions().contains(helpMenu_->menuAction()) )
menuBar()->insertMenu(helpMenu_->menuAction(), algorithmMenu_);
for (std::vector<QAction*>::iterator it = _actions.begin(); it != _actions.end(); ++it )
menus_[_name]->addAction(*it);
} else {
for (std::vector<QAction*>::iterator it = _actions.begin(); it != _actions.end(); ++it )
menus_[_name]->addAction(*it);
}
}
//=============================================================================
void CoreWidget::slotGetMenubarMenu (QString _name, QMenu *& _menu, bool _create)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment