Commit 2834f3ae authored by ledig's avatar ledig
Browse files

[FIX] config editor wont crash now after reopening,

also if no walnut.cfg is present the program won't hang any longer
parent f71e04f6
......@@ -766,8 +766,6 @@ void WMainWindow::setFibersLoaded()
void WMainWindow::openConfigDialog()
{
// boost::shared_ptr< WQtConfigWidget > configWidget = boost::shared_ptr< WQtConfigWidget >( new WQtConfigWidget );
// WQtConfigWidget *configWidget = new WQtConfigWidget;
m_configWidget = boost::shared_ptr< WQtConfigWidget >( new WQtConfigWidget );
m_configWidget->initAndShow();
......
......@@ -29,6 +29,8 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <boost/filesystem/path.hpp>
#include "WCfgOperations.h"
#include "../../kernel/WModuleFactory.h"
#include "../../common/WConditionOneShot.h"
......@@ -38,11 +40,9 @@
WQtConfigWidget::WQtConfigWidget() :
QWidget()
{
m_window = new QWidget();
m_window->setWindowTitle( "walnut.cfg Editor" );
this->setWindowTitle( "walnut.cfg Editor" );
QVBoxLayout *verticalLayout = new QVBoxLayout( m_window );
QVBoxLayout *verticalLayout = new QVBoxLayout( this );
m_tabWidget = new QTabWidget();
verticalLayout->addWidget( m_tabWidget );
QHBoxLayout *horizontalLayout = new QHBoxLayout();
......@@ -79,10 +79,6 @@ WQtConfigWidget::WQtConfigWidget() :
WQtConfigWidget::~WQtConfigWidget()
{
if ( m_window )
{
m_window->close();
}
}
void WQtConfigWidget::getAvailableModuleNames()
......@@ -1003,7 +999,7 @@ void WQtConfigWidget::saveToConfig()
}
}
if ( currentSectionWriten )
if ( currentSectionWriten || current_section == std::string( "" ) )
{
m_configLines.push_back( "[" + m_registeredSections[j] + "]" );
propertyInLine.push_back( noVar );
......@@ -1025,18 +1021,23 @@ void WQtConfigWidget::saveToConfig()
void WQtConfigWidget::loadConfigFile()
{
m_configLines = WCfgOperations::readCfg( "walnut.cfg" );
namespace fs = boost::filesystem;
if ( fs::exists( fs::path( std::string( "walnut.cfg" ) ) ) )
{
m_configLines = WCfgOperations::readCfg( "walnut.cfg" );
}
// copy all default properties into the loaded properties
copyProperties( m_defaultProperties, m_loadedProperties );
// parse the config file
createLineAssociation();
// update the loaded properties
updateGui( m_loadedProperties );
// copy all loaded properties into the current propertys where we create the gui from
// copy all loaded properties into the current properties where we create the gui from
copyProperties( m_loadedProperties, m_properties );
m_configState.setResetable( true, true );
m_configState.add( m_propCondition );
m_configState.add( m_shutdownFlag.getCondition() );
}
void WQtConfigWidget::updateGui( boost::shared_ptr< WProperties > properties )
......@@ -1133,9 +1134,7 @@ void WQtConfigWidget::initAndShow()
createGuiFromProperties( m_properties );
//m_shutdownFlag.set( false );
m_window->show();
this->show();
run();
}
......@@ -1264,7 +1263,7 @@ void WQtConfigWidget::save()
// and use every trigger that can be executed
saveToConfig();
setWalnutFromProperties();
m_window->hide();
this->hide();
requestStop();
}
......@@ -1281,7 +1280,7 @@ void WQtConfigWidget::cancel()
}
// and hide the window
m_window->hide();
this->hide();
requestStop();
}
......
......@@ -47,7 +47,7 @@
* This also creates a gui from all registered components and makes it possible to apply the changes
* made in the gui directly to the main program
*/
class WQtConfigWidget : public QWidget, WThreadedRunner
class WQtConfigWidget : public QWidget, public WThreadedRunner
{
Q_OBJECT
......@@ -207,7 +207,6 @@ private:
/**
* the static gui elements every config editor has got
*/
QWidget *m_window;
QTabWidget *m_tabWidget;
QPushButton *m_cancelButton;
QPushButton *m_okButton;
......
......@@ -32,11 +32,15 @@
WQtDSBWidget::WQtDSBWidget( std::string name, QWidget* parent )
: QWidget( parent ),
m_name( name.c_str() ),
m_controlLayout(),
m_pageLayout(),
// m_controlLayout(),
// m_pageLayout(),
m_numberOfWidgets( 0 )
{
m_pageLayout.addLayout( &m_controlLayout );
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
m_pageLayout = new QVBoxLayout();
m_controlLayout = new QGridLayout();
m_pageLayout->addLayout( m_controlLayout );
}
WQtDSBWidget::~WQtDSBWidget()
......@@ -47,49 +51,49 @@ WPropertyBoolWidget* WQtDSBWidget::addProp( WPropBool property )
{
++m_numberOfWidgets;
return new WPropertyBoolWidget( property, &m_controlLayout, this );
return new WPropertyBoolWidget( property, m_controlLayout, this );
}
WPropertyIntWidget* WQtDSBWidget::addProp( WPropInt property )
{
++m_numberOfWidgets;
return new WPropertyIntWidget( property, &m_controlLayout, this );
return new WPropertyIntWidget( property, m_controlLayout, this );
}
WPropertyDoubleWidget* WQtDSBWidget::addProp( WPropDouble property )
{
++m_numberOfWidgets;
return new WPropertyDoubleWidget( property, &m_controlLayout, this );
return new WPropertyDoubleWidget( property, m_controlLayout, this );
}
WPropertyStringWidget* WQtDSBWidget::addProp( WPropString property )
{
++m_numberOfWidgets;
return new WPropertyStringWidget( property, &m_controlLayout, this );
return new WPropertyStringWidget( property, m_controlLayout, this );
}
WPropertyColorWidget* WQtDSBWidget::addProp( WPropColor property )
{
++m_numberOfWidgets;
return new WPropertyColorWidget( property, &m_controlLayout, this );
return new WPropertyColorWidget( property, m_controlLayout, this );
}
WPropertyFilenameWidget* WQtDSBWidget::addProp( WPropFilename property )
{
++m_numberOfWidgets;
return new WPropertyFilenameWidget( property, &m_controlLayout, this );
return new WPropertyFilenameWidget( property, m_controlLayout, this );
}
WPropertyTriggerWidget* WQtDSBWidget::addProp( WPropTrigger property )
{
++m_numberOfWidgets;
return new WPropertyTriggerWidget( property, &m_controlLayout, this );
return new WPropertyTriggerWidget( property, m_controlLayout, this );
}
void WQtDSBWidget::addGroup( WQtDSBWidget* widget, bool asScrollArea )
......@@ -112,22 +116,22 @@ void WQtDSBWidget::addGroup( WQtDSBWidget* widget, bool asScrollArea )
}
// create a new group box
int row = m_controlLayout.rowCount();
int row = m_controlLayout->rowCount();
if ( asScrollArea )
{
m_controlLayout.addWidget( scrollArea, row, 0, 1, 2 );
m_controlLayout->addWidget( scrollArea, row, 0, 1, 2 );
}
else
{
m_controlLayout.addWidget( group, row, 0, 1, 2 );
m_controlLayout->addWidget( group, row, 0, 1, 2 );
}
}
void WQtDSBWidget::addSpacer()
{
m_pageLayout.addStretch();
setLayout( &m_pageLayout );
m_pageLayout->addStretch();
setLayout( m_pageLayout );
}
QString WQtDSBWidget::getName()
......
......@@ -189,12 +189,12 @@ private:
/**
* Layout used for each "widget combination".
*/
QGridLayout m_controlLayout;
QGridLayout *m_controlLayout;
/**
* Layout used for the whole widget.
*/
QVBoxLayout m_pageLayout;
QVBoxLayout *m_pageLayout;
/**
* The number of widgets inside this one.
......
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