From: <sv...@va...> - 2010-01-08 00:46:58
|
Author: cerion Date: 2010-01-08 00:46:31 +0000 (Fri, 08 Jan 2010) New Revision: 462 Log: Sorted out the config settings some more: - Used QSettings: Creates a 'working' config, which is temporarily saved to disc (tmp_cfg, deleted upon exit) - Introduced 'projects' abstraction: A user works either within or outside of a project: - If no project is in use, any configuration changes made (via either the command line arguments or the GUI) will be used for the 'working' config, but will be discarded upon application exit. - If a project is in use (created/opened), config settings are transparently saved to that project file (no more 'saving'). - Config settings are read in in order from 3 sources, each overriding the last: 1. Global configuration file (static location per user) 2. Project configuration file 3. Command line arguments (when these are working again, anyway :-) Plus the usual: Cleaned up, fixed bugs, etc. Added: branches/valkyrie_qt4port/utils/vk_config.cpp branches/valkyrie_qt4port/utils/vk_config.h Modified: branches/valkyrie_qt4port/core/valgrind_object.cpp branches/valkyrie_qt4port/core/valgrind_object.h branches/valkyrie_qt4port/core/valkyrie_object.cpp branches/valkyrie_qt4port/core/valkyrie_object.h branches/valkyrie_qt4port/core/vk_objects.cpp branches/valkyrie_qt4port/core/vk_objects.h branches/valkyrie_qt4port/main.cpp branches/valkyrie_qt4port/mainwindow.cpp branches/valkyrie_qt4port/mainwindow.h branches/valkyrie_qt4port/options/valgrind_options_page.cpp branches/valkyrie_qt4port/options/valgrind_options_page.h branches/valkyrie_qt4port/options/valkyrie_options_page.cpp branches/valkyrie_qt4port/options/valkyrie_options_page.h branches/valkyrie_qt4port/options/vk_option.cpp branches/valkyrie_qt4port/options/vk_option.h branches/valkyrie_qt4port/options/vk_options_dialog.cpp branches/valkyrie_qt4port/options/vk_options_dialog.h branches/valkyrie_qt4port/options/vk_options_page.cpp branches/valkyrie_qt4port/options/vk_options_page.h branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp branches/valkyrie_qt4port/options/widgets/opt_cb_widget.cpp branches/valkyrie_qt4port/options/widgets/opt_ck_widget.cpp branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp branches/valkyrie_qt4port/options/widgets/opt_le_widget.cpp branches/valkyrie_qt4port/options/widgets/opt_sp_widget.cpp branches/valkyrie_qt4port/toolview/helgrindview.cpp branches/valkyrie_qt4port/toolview/toolview.cpp branches/valkyrie_qt4port/utils/vk_utils.cpp branches/valkyrie_qt4port/utils/vk_utils.h branches/valkyrie_qt4port/valkyrie.pro Modified: branches/valkyrie_qt4port/core/valgrind_object.cpp =================================================================== --- branches/valkyrie_qt4port/core/valgrind_object.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/valgrind_object.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -23,8 +23,9 @@ #include "core/valgrind_object.h" #include "options/valgrind_options_page.h" // createVkOptionsPage() -//#include "config.h" // VK_CFG_DIR, VK_SUPPS_DIR -//#include "vk_config.h" +#include "utils/vk_config.h" + +//#include "config.h" //#include "html_urls.h" //#include "memcheck_object.h" //#include "cachegrind_object.h" @@ -33,10 +34,6 @@ //#include "vk_utils.h" // vk_assert, VK_DEBUG, etc. -//TODO: from config.h -#define VK_CFG_DIR ".valkyrie" -#define VK_SUPPS_DIR "suppressions/" - //#include <ctype.h> //#include <stdlib.h> //#include <string.h> @@ -389,7 +386,7 @@ // ------------------------------------------------------------ // Can't access vkConfig->suppDir(): config created after us! - QString defSuppDir = QDir::homePath() + "/" + VK_CFG_DIR + VK_SUPPS_DIR; + QString defSuppDir = QDir::homePath() + "/" + QString(VK_CFG_GLBL_DIR) + VK_SUPPS_DIR; /* list of dirs holding suppression files */ options.addOpt( VALGRIND::SUPPS_DIRS, @@ -519,6 +516,7 @@ } + /* check argval for this option, updating if necessary. called by parseCmdArgs() and gui option pages -------------------- */ int Valgrind::checkOptArg( int optid, QString& argval ) Modified: branches/valkyrie_qt4port/core/valgrind_object.h =================================================================== --- branches/valkyrie_qt4port/core/valgrind_object.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/valgrind_object.h 2010-01-08 00:46:31 UTC (rev 462) @@ -83,8 +83,8 @@ #if 0 /* returns a list of non-default flags to pass to valgrind */ QStringList modifiedVgFlags( const ToolObject* tool_obj ); - unsigned int maxOptId() { return NUM_OPTS; } #endif + unsigned int maxOptId() { return VALGRIND::NUM_OPTS; } int checkOptArg( int optid, QString& argval ); Modified: branches/valkyrie_qt4port/core/valkyrie_object.cpp =================================================================== --- branches/valkyrie_qt4port/core/valkyrie_object.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/valkyrie_object.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -20,6 +20,8 @@ #include "core/valkyrie_object.h" #include "options/valkyrie_options_page.h" // createVkOptionsPage() +#include "utils/vk_config.h" +#include "utils/vk_utils.h" // TODO: put this in a define in the build scripts,or something. @@ -204,7 +206,7 @@ '\0', "", "", - "", // TODO: BIN_EDITOR, + VK_BIN_EDITOR, "Src Editor:", "", "", // TODO: urlValkyrie::srcEditor @@ -249,7 +251,7 @@ '\0', "", "", - "", //TODO: get_VK_LOGS_DIR(), + get_VK_LOGS_DIR(), "Log Dir:", "", "", // TODO: urlValkyrie::logDir @@ -272,7 +274,22 @@ VkOPT::WDG_LEDIT ); + options.addOpt( + VALKYRIE::PROJ_FILE, + this->objectName(), + "proj-file", + 'f', + "<project.vk>", + "", + "", + "", + "use settings from project file", + "", // TODO: urlValkyrie::workingDir + VkOPT::ARG_STRING, + VkOPT::WDG_LEDIT + ); + /* path to valgrind executable (maybe found by configure) */ options.addOpt( VALKYRIE::VG_EXEC, @@ -281,7 +298,7 @@ '\0', "", "", - "", // TODO: BIN_VALGRIND, + VK_BIN_VALGRIND, "Valgrind:", "", "", // TODO: urlValkyrie::vgDir @@ -322,19 +339,38 @@ +void Valkyrie::setConfigDefaults() +{ + vkConfig->beginGroup( this->objectName() ); + OptionHash opts = options.getOptionHash(); + for ( Iter_OptionHash it = opts.begin(); it != opts.end(); ++it ) { + VkOption* opt = it.value(); + + /* Don't create config entries for these options: + They don't hold persistent data, and have no associated option widget */ + if (opt->optid == VALKYRIE::HELP ) continue; + if (opt->optid == VALKYRIE::VGHELP ) continue; + + vkConfig->setValue( opt->longFlag, opt->dfltValue ); + } + + vkConfig->endGroup(); +} + + + /*! Check \a argval for the option given by \a optid, updating if necessary. Called by parseCmdArgs() and gui option pages */ -//int Valkyrie::checkOptArg( int optid, QString& argval ) -int Valkyrie::checkOptArg( int, QString& ) +int Valkyrie::checkOptArg( int optid, QString& argval ) { - // VkOption* opt = this->options.getOption( optid ); + vk_assert( optid >= 0 && optid < VALKYRIE::NUM_OPTS ); + VkOption* opt = this->options.getOption( optid ); + #if 0 // TODO - vk_assert( optid >= 0 && optid < NUM_OPTS ); - int errval = PARSED_OK; // Option* opt = findOption( optid ); @@ -442,15 +478,13 @@ /*! Return list of all VkObjects - - TODO: const. */ -VkObjectList Valkyrie::vkObjList() +const VkObjectList Valkyrie::vkObjList() { VkObjectList vkObjList; vkObjList.append( this ); - vkObjList.append( this->valgrind() ); + vkObjList.append( valgrind() ); #if 0 // TODO ToolObjList tools = valgrind()->toolObjList(); Modified: branches/valkyrie_qt4port/core/valkyrie_object.h =================================================================== --- branches/valkyrie_qt4port/core/valkyrie_object.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/valkyrie_object.h 2010-01-08 00:46:31 UTC (rev 462) @@ -44,6 +44,7 @@ BROWSER, DFLT_LOGDIR, WORKING_DIR, + PROJ_FILE, VG_EXEC, // path to valgrind executable BINARY, // user-binary to be valgrindised BIN_FLAGS, // flags for user-binary @@ -68,6 +69,7 @@ void stopTool( int tId ); bool queryToolDone( int tId ); #endif + unsigned int maxOptId() { return VALKYRIE::NUM_OPTS; } int checkOptArg( int optid, QString& argval ); @@ -76,8 +78,10 @@ Valgrind* valgrind() { return m_valgrind; } - /* for simplicity */ - VkObjectList vkObjList(); + virtual void setConfigDefaults(); + + // list of all objects + const VkObjectList vkObjList(); // VkObject* vkObject( int objId ); private: Modified: branches/valkyrie_qt4port/core/vk_objects.cpp =================================================================== --- branches/valkyrie_qt4port/core/vk_objects.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/vk_objects.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -19,16 +19,17 @@ ****************************************************************************/ #include "core/vk_objects.h" +#include "core/vk_objects.h" +#include "utils/vk_config.h" +#include "options/vk_option.h" - /***************************************************************************/ /*! Constructs a VkObject */ VkObject::VkObject( QString objName ) - // : QObject( 0, capt ) { this->setObjectName( objName ); } @@ -49,3 +50,20 @@ { return options.getOption( optid ); } + + + +void VkObject::setConfigDefaults() +{ + vkConfig->beginGroup( this->objectName() ); + + OptionHash opts = options.getOptionHash(); + for ( Iter_OptionHash it = opts.begin(); it != opts.end(); ++it ) { + VkOption* opt = it.value(); + QString config_key = opt->longFlag; + QString config_value = opt->dfltValue; + vkConfig->setValue( config_key, config_value ); + } + + vkConfig->endGroup(); +} Modified: branches/valkyrie_qt4port/core/vk_objects.h =================================================================== --- branches/valkyrie_qt4port/core/vk_objects.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/core/vk_objects.h 2010-01-08 00:46:31 UTC (rev 462) @@ -45,10 +45,16 @@ VkObject( QString objectName ); ~VkObject(); + virtual unsigned int maxOptId() = 0; + /*! check argval for this option, updating if necessary. called by parseCmdArgs() and gui option pages */ virtual int checkOptArg( int optid, QString& argval ) = 0; + + /*! Set default config entries for thies object */ + virtual void setConfigDefaults(); + virtual VkOptionsPage* createVkOptionsPage() = 0; VkOption* getOption( int optid ); @@ -56,6 +62,8 @@ protected: virtual void setupOptions() = 0; VkOptionHash options; + + }; Modified: branches/valkyrie_qt4port/main.cpp =================================================================== --- branches/valkyrie_qt4port/main.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/main.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -25,8 +25,14 @@ #include "toolview/toolview.h" #include "mainwindow.h" +#include "utils/vk_config.h" +VkConfig* vkConfig = 0; + + + + /*! Main program entry point arguments parsed, Qt setup, application setup, the ball set rolling. @@ -42,11 +48,29 @@ Valkyrie valkyrie; // ------------------------------------------------------------ - // start turning the engine over + // Start turning the engine over app = new QApplication( argc, argv ); + // ------------------------------------------------------------ - // start up the gui + // Setup application config settings + QCoreApplication::setOrganizationName("OpenWorks"); + QCoreApplication::setOrganizationDomain("openworks.co.uk"); + QCoreApplication::setApplicationName("Valkyrie"); + QString tmp_cfg = VkConfig::vkCfgMakeTempFilename(); + if ( tmp_cfg.isNull() ) { + // TODO: workout what really happens to QSettings. + cerr << "Error: no tmpfile for working config. No guarantees from here!" << endl; + } + vkConfig = new VkConfig( tmp_cfg ); + bool ok = vkConfig->initCfg( &valkyrie ); + if ( !ok ) { + // TODO: deal with this nicely. + cerr << "Error: config not initialised properly: No guarantees from here!" << endl; + } + + // ------------------------------------------------------------ + // Start up the gui vkWin = new MainWindow( &valkyrie ); vkWin->show(); vkWin->showToolView( vk::ID_MEMCHECK ); @@ -54,13 +78,15 @@ qApp->processEvents(); // ------------------------------------------------------------ - // hand over to QtApp. + // Hand over to QtApp. res = app->exec(); + // ------------------------------------------------------------ - // we're done. - if ( vkWin ) delete vkWin; - if ( app ) delete app; + // We're done - clean up and return. + if ( vkWin ) delete vkWin; + if ( vkConfig ) delete vkConfig; + if ( app ) delete app; return res; } Modified: branches/valkyrie_qt4port/mainwindow.cpp =================================================================== --- branches/valkyrie_qt4port/mainwindow.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/mainwindow.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -19,6 +19,8 @@ ****************************************************************************/ #include <QApplication> +#include <QFileDialog> +#include <QInputDialog> #include <QMenu> #include <QMenuBar> #include <QToolBar> @@ -28,6 +30,7 @@ #include "toolview/helgrindview.h" #include "options/vk_option.h" +#include "utils/vk_config.h" /***************************************************************************/ @@ -55,11 +58,11 @@ : QMainWindow(), valkyrie( vk ), optionsDialog( 0 ) { - setObjectName(QString::fromUtf8("MainWindowClass")); + setObjectName( QString::fromUtf8("MainWindowClass") ); + QString title = vkConfig->vkName; + title[0] = title[0].toUpper(); + setWindowTitle( title ); - // TODO: vkConfig->vkName() instead of Valkyrie - setWindowTitle( QApplication::translate("MainWindowClass", "Valkyrie", 0, QApplication::UnicodeUTF8) ); - // TODO: QtCoreApplication? //setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); @@ -83,8 +86,15 @@ */ MainWindow::~MainWindow() { - cerr << "MainWindow::~MainWindow()" << endl; - cerr << "TODO: write windows attributes to config" << endl; +// cerr << "MainWindow::~MainWindow()" << endl; + + // cleanup toolviews + delete toolViewStack; + + // Save window position to config. + vkConfig->setValue( "mainwindow/size", size() ); + vkConfig->setValue( "mainwindow/pos", pos() ); + vkConfig->sync(); } @@ -104,7 +114,7 @@ /*! Allow a tool to remove a (previously inserted) menu from the main menuBar. A tool could do this directly via 'parent', but insert can't be - done directly, so user this function for consistency. + done directly, so use this function for consistency. \sa insertToolMenuAction() */ @@ -119,9 +129,9 @@ */ void MainWindow::setupLayout() { - // TODO: size from config. - resize(500, 500); - + resize( vkConfig->value( "mainwindow/size", QSize(600, 600)).toSize()); + move( vkConfig->value( "mainwindow/pos", QPoint(400, 0)).toPoint()); + toolViewStack = new ToolViewStack( this ); setCentralWidget( toolViewStack ); } @@ -132,13 +142,23 @@ */ void MainWindow::setupActions() { - // TODO: + // TODO: shortcuts & tips // act->setShortcut( tr("Ctrl+XXX") ); // act->setStatusTip( tr("here's a tip") ); + actFile_NewProj = new QAction( this ); + actFile_NewProj->setObjectName( QString::fromUtf8("actFile_NewProj") ); + actFile_NewProj->setText( QApplication::translate("MainWindowClass", "&New Project...", 0, QApplication::UnicodeUTF8) ); + connect( actFile_NewProj, SIGNAL( triggered() ), this, SLOT( createNewProject() ) ); + + actFile_OpenProj = new QAction( this ); + actFile_OpenProj->setObjectName( QString::fromUtf8("actFile_OpenProj") ); + actFile_OpenProj->setText( QApplication::translate("MainWindowClass", "&Open Project...", 0, QApplication::UnicodeUTF8) ); + connect( actFile_OpenProj, SIGNAL( triggered() ), this, SLOT( openProject() ) ); + actFile_Close = new QAction( this ); actFile_Close->setObjectName( QString::fromUtf8("actFile_Close") ); - actFile_Close->setText( QApplication::translate("MainWindowClass", "&Close", 0, QApplication::UnicodeUTF8) ); + actFile_Close->setText( QApplication::translate("MainWindowClass", "&Close Tool", 0, QApplication::UnicodeUTF8) ); connect( actFile_Close, SIGNAL( triggered() ), this, SLOT( closeToolView() ) ); actFile_Exit = new QAction( this ); @@ -272,6 +292,8 @@ menuBar->addAction( menuTools->menuAction() ); menuBar->addAction( menuHelp->menuAction() ); + menuFile->addAction( actFile_NewProj ); + menuFile->addAction( actFile_OpenProj ); menuFile->addSeparator(); menuFile->addAction( actFile_Close ); menuFile->addAction( actFile_Exit ); @@ -422,7 +444,69 @@ } + /*! + Create a new project: + Save configuration in a project file. +*/ +void MainWindow::createNewProject() +{ + // ensure any existing project settings are saved first. + vkConfig->sync(); + + // TODO: put dir & name choice in one dialog. + + // Choose project directory + QString dir = QFileDialog::getExistingDirectory( this, "Choose Project Directory", "./", + QFileDialog::ShowDirsOnly | + QFileDialog::DontResolveSymlinks ); + if ( dir.isEmpty() || dir.isNull() ) { + return; + } + + // Choose project name + QString proj_name; + while ( true ) { + bool ok = true; + proj_name = QInputDialog::getText( this, "Choose New Project Name", + "Project Name:", QLineEdit::Normal, + "", &ok); + + if ( !ok ) { // User chaged their minds. + return; + } + if ( !proj_name.isEmpty() ) { // loop if empty name. + break; + } + } + +// TODO: check if exists may overwrite, etc... + + vkConfig->createNewProject( dir, proj_name ); +} + + +/*! + Open an existing project. +*/ +void MainWindow::openProject() +{ + // ensure any existing project settings are saved first. + vkConfig->sync(); + + QString proj_filename = QFileDialog::getOpenFileName( this, "Open Valkyrie Project", + "./", "Valkyrie Projects (*.vk)" ); + if ( proj_filename.isEmpty() || proj_filename.isNull() ) { + // Cancelled + return; + } + + vkConfig->openProject( proj_filename ); +} + + + +/*! Close the currently-shown ToolView. Calls the ToolViewStack to remove the toolview from the stack, @@ -483,25 +567,18 @@ void MainWindow::openOptions() { // TODO: decide whether really want a modeless dialog: is this functionality useful/used? - // - easier to deal with a modal dialog: plus it's clearer what settings are actually being used (saved vs. non-saved settings) - + // if non-modal, rem to reinit all opt widgets when a project is created/opened +#if 0 if (!optionsDialog) { - optionsDialog = new VkOptionsDialog(this); + optionsDialog = new VkOptionsDialog( this ); } optionsDialog->show(); optionsDialog->raise(); optionsDialog->activateWindow(); - - - // TODO: something like this... -#if 0 - QSettings *settings = new QSettings(optionsDialog->format(), - optionsDialog->scope(), - optionsDialog->organization(), - optionsDialog->application()); - setSettingsObject(settings); - fallbacksAct->setEnabled(true); +#else + VkOptionsDialog optionsDlg( this ); + optionsDlg.exec(); #endif } Modified: branches/valkyrie_qt4port/mainwindow.h =================================================================== --- branches/valkyrie_qt4port/mainwindow.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/mainwindow.h 2010-01-08 00:46:31 UTC (rev 462) @@ -61,6 +61,8 @@ private slots: void toolGroupTriggered( QAction* ); + void createNewProject(); + void openProject(); void closeToolView(); void openOptions(); void runTool(); @@ -76,6 +78,8 @@ QLabel* statusLabel; private: + QAction* actFile_NewProj; + QAction* actFile_OpenProj; QAction* actFile_Exit; QAction* actFile_Close; QAction* actEdit_Options; Modified: branches/valkyrie_qt4port/options/valgrind_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -22,7 +22,7 @@ #include <QListWidget> #include <QTabWidget> -//#include "vk_config.h" +#include "utils/vk_config.h" //#include "vk_messages.h" #include "utils/vk_utils.h" //#include "context_help.h" @@ -296,7 +296,7 @@ { /* if usr gave suppfile on cmdline (updating lbSel) - update suppDirs, suppsAvail from each path in lbSel */ - QChar sep = vkConfig->sepChar(); + QChar sep = vkConfig->vkSepChar; LbWidget* lbSel = (LbWidget*)m_itemList[Valgrind::SUPPS_SEL ]; QStringList currSupps = QStringList::split( sep, lbSel->currValue() ); LbWidget* lbDirs = (LbWidget*)m_itemList[Valgrind::SUPPS_DIRS]; @@ -316,12 +316,13 @@ /* init suppsAvail */ suppDirsChanged(); } +#endif - /* called when user clicks "Apply" / "Ok" / "Reset" buttons. */ void ValgrindOptionsPage::applyOption( int optId ) { - vk_assert( optId >= 0 && optId < Valgrind::NUM_OPTS ); +#if 0 + vk_assert( optId >= 0 && optId < Valgrind::NUM_OPTS ); // QString argval = m_itemList[optId]->currValue(); @@ -330,8 +331,8 @@ default: break; } -} #endif +} void ValgrindOptionsPage::getDbBin() @@ -348,12 +349,10 @@ { m_allAvailSuppFiles = QStringList(); LbWidget* lbDirs = (LbWidget*)m_itemList[VALGRIND::SUPPS_DIRS]; -//TODO -// QChar m_sep = vkConfig->sepChar(); - QChar m_sep = ':'; + QChar sep = vkConfig->vkSepChar; /* Get list of dirs from "valgrind::supps-dirs" */ - QStringList suppDirs = lbDirs->currValue().split( m_sep ); + QStringList suppDirs = lbDirs->currValue().split( sep ); for ( int i=0; i<suppDirs.count(); i++ ) { /* for each suppDir, find all supp files */ @@ -375,13 +374,11 @@ */ void ValgrindOptionsPage::updateSuppsAvail() { -//TODO -// QChar m_sep = vkConfig->sepChar(); -QChar m_sep = ':'; + QChar sep = vkConfig->vkSepChar; LbWidget* lbAvail = (LbWidget*)m_itemList[VALGRIND::SUPPS_AVAIL]; LbWidget* lbSel = (LbWidget*)m_itemList[VALGRIND::SUPPS_SEL ]; QStringList suppsAvail = m_allAvailSuppFiles; - QStringList currSupps = lbSel->currValue().split( m_sep ); + QStringList currSupps = lbSel->currValue().split( sep ); for ( int i=0; i<currSupps.count(); i++ ) { int idx = suppsAvail.indexOf( currSupps[i] ); @@ -390,7 +387,7 @@ } } - lbAvail->setCurrValue( suppsAvail.join( m_sep ) ); + lbAvail->setCurrValue( suppsAvail.join( sep ) ); } @@ -404,8 +401,7 @@ if (((QListWidget*)lbSel->widget())->count() < VG_CLO_MAX_SFILES) { lbSel->insertItem(suppr); } else { -//TODO - cerr << "FIXME: Valgrind won't accept more than %d suppression files" << endl; +cerr << "TODO: vkError: Valgrind won't accept more than VG_CLO_MAX_SFILES suppression files" << endl; #if 0 /* valgrind doesn't accept any more suppression files */ vkError( this, "Error", Modified: branches/valkyrie_qt4port/options/valgrind_options_page.h =================================================================== --- branches/valkyrie_qt4port/options/valgrind_options_page.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/valgrind_options_page.h 2010-01-08 00:46:31 UTC (rev 462) @@ -34,8 +34,8 @@ public: ValgrindOptionsPage( VkObject* obj ); + void applyOption( int optId ); #if 0 - void applyOption( int optId ); void init(); #endif Modified: branches/valkyrie_qt4port/options/valkyrie_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/valkyrie_options_page.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/valkyrie_options_page.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -23,10 +23,12 @@ #include <QLabel> #include "utils/vk_utils.h" +#include "utils/vk_config.h" +#include "options/widgets/opt_ck_widget.h" + #if 0 #include "vk_objects.h" -#include "vk_config.h" #include "main_window.h" #include "vk_messages.h" #include "context_help.h" @@ -126,9 +128,7 @@ fontGenLedit->setReadOnly( true ); // don't allow direct editing // start up in correct state -//TODO -// bool use_sys_font = vkConfig->rdBool("font-gen-sys", "valkyrie"); - bool use_sys_font = true; + bool use_sys_font = vkConfig->value( "valkyrie/font-gen-sys" ).toBool(); fontGenLedit->setDisabled( use_sys_font ); connect( fontGenSysLedit, SIGNAL(changed(bool)), fontGenLedit, SLOT(setDisabled(bool)) ); @@ -194,17 +194,22 @@ /* called when user clicks "Apply" / "Ok" / "Reset" buttons. */ -void ValkyrieOptionsPage::applyOption( int ) //optId ) +void ValkyrieOptionsPage::applyOption( int optId ) { -#if 0 // TODO - vk_assert( optId >= 0 && optId < VALKYRIE::NUM_OPTS ); + std::cerr << "vk-applyOption(): 0 (" << optId << ")" << std::endl; + + vk_assert( optId >= 0 && optId < VALKYRIE::NUM_OPTS ); + OptionWidget* optWidg = m_itemList[optId]; vk_assert( optWidg != 0 ); QString argval = optWidg->currValue(); - /* apply option */ + std::cerr << "applyOption(): 1" << std::endl; + + /* apply option */ switch ( optId ) { +#if 0 case VALKYRIE::TOOLTIP: { MainWindow* vkWin = (MainWindow*)qApp->mainWidget(); vkWin->toggleToolTips(); @@ -262,17 +267,19 @@ } } } break; +#endif default: break; } -#endif } + /* called by pbFont: conjures up a QFontDialog */ void ValkyrieOptionsPage::chooseGenFont() { + cerr << "TODO: ValkyrieOptionsPage::chooseGenFont()" << endl; #if 0 // TODO LeWidget* fontLedit = ((LeWidget*)m_itemList[VALKYRIE::FNT_GEN_USR]); @@ -292,6 +299,7 @@ /* called by pbFont: conjures up a QFontDialog */ void ValkyrieOptionsPage::chooseToolFont() { + cerr << "TODO: ValkyrieOptionsPage::chooseToolFont()" << endl; #if 0 // TODO LeWidget* fontLedit = ((LeWidget*)m_itemList[VALKYRIE::FNT_TOOL_USR]); @@ -308,6 +316,7 @@ void ValkyrieOptionsPage::getEditor() { + cerr << "TODO: ValkyrieOptionsPage::getEditor()" << endl; #if 0 // TODO /* try and start up somewhere sensible */ QString ed = m_itemList[VALKYRIE::SRC_EDITOR]->currValue(); @@ -339,6 +348,7 @@ /* allows user to select executable-to-debug */ void ValkyrieOptionsPage::getBinary() { + cerr << "TODO: ValkyrieOptionsPage::getBinary()" << endl; #if 0 // TODO QString binfile = QFileDialog::getOpenFileName( QString::null, "All Files (*)", @@ -354,6 +364,7 @@ /* allows user to select default browser */ void ValkyrieOptionsPage::getBrowser() { + cerr << "TODO: ValkyrieOptionsPage::getBrowser()" << endl; #if 0 // TODO QString brwsr = QFileDialog::getOpenFileName( QString::null, "All Files (*)", @@ -370,6 +381,7 @@ of this fn are essentially the same as the one in config.tests/valgrind.test */ void ValkyrieOptionsPage::getVgExec() { + cerr << "TODO: ValkyrieOptionsPage::getVgExec()" << endl; #if 0 // TODO QString vg_exec_path = QFileDialog::getOpenFileName( QString::null, "All Files (*)", @@ -385,6 +397,7 @@ /* RM: allows user to specify which default log dir to use */ void ValkyrieOptionsPage::getDfltLogDir() { + cerr << "TODO: ValkyrieOptionsPage::getDfltLogDir()" << endl; #if 0 // TODO QString currdir = m_itemList[VALKYRIE::DFLT_LOGDIR]->currValue(); QString dir_logsave = @@ -401,6 +414,7 @@ /* RM: allows user to specify which default log dir to use */ void ValkyrieOptionsPage::getWorkingDir() { + cerr << "TODO: ValkyrieOptionsPage::getWorkingDir()" << endl; #if 0 // TODO QString currdir = m_itemList[VALKYRIE::WORKING_DIR]->currValue(); QString dir_working = Modified: branches/valkyrie_qt4port/options/valkyrie_options_page.h =================================================================== --- branches/valkyrie_qt4port/options/valkyrie_options_page.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/valkyrie_options_page.h 2010-01-08 00:46:31 UTC (rev 462) @@ -35,6 +35,9 @@ void applyOption( int optId ); + bool saveToProjectCfg(); + + private slots: void chooseGenFont(); void chooseToolFont(); Modified: branches/valkyrie_qt4port/options/vk_option.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_option.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_option.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -100,7 +100,7 @@ */ VkOption* VkOptionHash::getOption( int optid ) { - // TODO: check for non-existant options + // TODO: check for non-existent options return optionHash.value( optid ); } Modified: branches/valkyrie_qt4port/options/vk_option.h =================================================================== --- branches/valkyrie_qt4port/options/vk_option.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_option.h 2010-01-08 00:46:31 UTC (rev 462) @@ -25,15 +25,7 @@ #include <QStringList> -// TODO: remove once done with cerr's etc. -#include <iostream> -using namespace std; - -// TODO: perhaps better to replace this class with QSetting? -// TODO: const everywhere where possible. - - // ============================================================ class VkOption; @@ -126,6 +118,9 @@ VkOption* getOption( int optid ); + OptionHash& getOptionHash() { return optionHash; } + + void addOpt( int optid, QString cfg_group, QString long_flag, @@ -170,13 +165,16 @@ QString longFlag; // eg. --leak-resolution QChar shortFlag; // eg. --l QString flagDescr; // eg. <file> + QStringList possValues; // eg. low | med | high + QString dfltValue; // eg. [low] QString shortHelp; // txt for OptionsWindow QString longHelp; // txt for help --> stdout QString urlAddress; // context help url - QString dfltValue; // eg. [low] - QStringList possValues; // eg. low | med | high VkOPT::ArgType argType; // eg. ARG_UINT VkOPT::WidgType widgType; // eg. VkOPTION::WDG_LEDIT + + // configuration settings key: + QString configKey() { return configGrp + "/" + longFlag; } }; #endif // __VK_OPTION_H Modified: branches/valkyrie_qt4port/options/vk_options_dialog.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_options_dialog.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_options_dialog.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -23,12 +23,14 @@ #include <QLabel> #include <QPushButton> +#include "utils/vk_config.h" +#include "utils/vk_utils.h" + #if 0 #include "html_urls.h" #include "context_help.h" #include "vk_utils.h" #include "vk_objects.h" -#include "vk_config.h" #include "main_window.h" #include "vk_messages.h" #endif @@ -55,26 +57,18 @@ // ------------------------------------------------------------ // basic dialog setup setObjectName(QString::fromUtf8("VkOptionsDialog[*]")); // Note: "[*]" placeholder for 'windowModified' -// TODO: get values from config - setWindowTitle( QApplication::translate("VkOptionsDialog", "Valkyrie Options Dialog", 0, QApplication::UnicodeUTF8) ); - + setWindowTitle( "Valkyrie Options Dialog" ); setupLayout(); // ------------------------------------------------------------ // setup default state // TODO: find out more how Qt4 does this stuff. // they have a '*' for the window title, too, to indicate changes... -// REM: vkConfig->isDirty() -/* - QPushButton* restoreButton = optionsButtonBox->button( QDialogButtonBox::RestoreDefaults ); + QPushButton* applyButton = optionsButtonBox->button( QDialogButtonBox::Apply ); QPushButton* cancelButton = optionsButtonBox->button( QDialogButtonBox::Cancel ); - QPushButton* okButton = optionsButtonBox->button( QDialogButtonBox::Ok ); - restoreButton->setEnabled( true ); - applyButton->setEnabled( false ); // nothing to apply yet - cancelButton->setEnabled( true ); - okButton->setEnabled( false ); -*/ + applyButton->setEnabled( false ); + cancelButton->setEnabled( false ); // ------------------------------------------------------------ // Add categories, and the default page (other pages loaded on demand) @@ -85,20 +79,11 @@ // Pass 'this' so constructor widgets auto-size correctly. VkObject* obj = objList.at(i); VkOptionsPage* page = obj->createVkOptionsPage(); + vk_assert( page != 0 ); + connect( page, SIGNAL(modified()), this, SLOT(pageModified()) ); + // handle e.g. user pressing return in an ledit + connect( page, SIGNAL(apply()), this, SLOT(apply()) ); -//TODO -// vk_assert( page != 0 ); -// connect( page, SIGNAL(modified()), this, SLOT(modified()) ); -// /* handle e.g. user pressing return in an ledit */ -// connect( page, SIGNAL(apply()), this, SLOT(apply()) ); - - if ( page == 0 ) { - // TODO: on-screen error? -// VK_DEBUG("cit->text = %s", cit->text().latin1() ); - cerr << "*** page == 0" << endl; - return; - } - // Set list item entry QListWidgetItem *item = new QListWidgetItem( contentsListWidget ); QString itemName = obj->objectName(); @@ -131,30 +116,21 @@ { // ------------------------------------------------------------ // top layout - vLayout = new QVBoxLayout( this ); + QVBoxLayout* vLayout = new QVBoxLayout( this ); vLayout->setObjectName(QString::fromUtf8("vlayout")); // ------------------------------------------------------------ // parent widget for the contents + pages - hLayoutWidget = new QWidget( this ); + QWidget* hLayoutWidget = new QWidget( this ); + hLayoutWidget->setObjectName(QString::fromUtf8("hLayoutWidget")); vLayout->addWidget( hLayoutWidget ); // ------------------------------------------------------------ - // The button box - optionsButtonBox = new QDialogButtonBox( this ); - optionsButtonBox->setObjectName(QString::fromUtf8("optionsButtonBox")); - optionsButtonBox->setOrientation(Qt::Horizontal); - optionsButtonBox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults); - vLayout->addWidget( optionsButtonBox ); - - - // ------------------------------------------------------------ // contents + pages layout - hLayout = new QHBoxLayout( hLayoutWidget ); + QHBoxLayout* hLayout = new QHBoxLayout( hLayoutWidget ); hLayout->setObjectName(QString::fromUtf8("hLayout")); hLayout->setContentsMargins( 0, 0, 0, 0 ); - // ------------------------------------------------------------ // The contents list // Note: give this its maximum width once filled with items @@ -164,6 +140,7 @@ contentsListWidget->setSortingEnabled(false); QSizePolicy sizePolicyContents(QSizePolicy::Maximum, QSizePolicy::Expanding); contentsListWidget->setSizePolicy( sizePolicyContents ); + contentsListWidget->setSelectionMode( QAbstractItemView::SingleSelection ); hLayout->addWidget( contentsListWidget ); optionPages = new QStackedWidget( hLayoutWidget ); @@ -173,274 +150,147 @@ hLayout->addWidget( optionPages ); + // ------------------------------------------------------------ + // parent widget for the buttons + QWidget* hButtonWidget = new QWidget( this ); + hButtonWidget->setObjectName(QString::fromUtf8("hButtonWidget")); + vLayout->addWidget( hButtonWidget ); // ------------------------------------------------------------ - // signals / slots - QPushButton* restoreButton = optionsButtonBox->button( QDialogButtonBox::RestoreDefaults ); - QPushButton* applyButton = optionsButtonBox->button( QDialogButtonBox::Apply ); - connect(restoreButton, SIGNAL(released()), this, SLOT(restoreDefaults())); - connect(applyButton, SIGNAL(released()), this, SLOT(apply())); - connect(optionsButtonBox, SIGNAL(rejected()), this, SLOT(reject())); - connect(optionsButtonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(contentsListWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(showPage(QListWidgetItem*,QListWidgetItem*))); -} + // options button box + QHBoxLayout* hLayoutButtons = new QHBoxLayout( hButtonWidget ); + hLayoutButtons->setObjectName(QString::fromUtf8("hLayoutButtons")); + saveGlblButton = new QPushButton( QPixmap( ":/vk_icons/icons/tb_mainwin_filesave2.xpm" ), + "Save To Global Config" ); + hLayoutButtons->addWidget( saveGlblButton ); + hLayoutButtons->addStretch( 1 ); -#if 0 // TODO -void VkOptionsDialog::addCategory( VkObject* obj ) -{ - /* to look up object later to call obj->createVkOptionsPage() */ - int catId = obj->objId(); - VkOptionsPage* page = NULL; + optionsButtonBox = new QDialogButtonBox( hButtonWidget ); + optionsButtonBox->setObjectName(QString::fromUtf8("optionsButtonBox")); + optionsButtonBox->setOrientation(Qt::Horizontal); + optionsButtonBox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + hLayoutButtons->addWidget( optionsButtonBox ); - wStack->addWidget( page, catid ); - new CategItem( categories, page, obj->title(), catid ); -} -#endif + // ------------------------------------------------------------ + // signals / slots + connect(contentsListWidget, SIGNAL(itemClicked(QListWidgetItem*)), + this, SLOT(showPage(QListWidgetItem*))); + QPushButton* applyButton = optionsButtonBox->button( QDialogButtonBox::Apply ); + connect(applyButton, SIGNAL(released()), this, SLOT(apply())); // Apply + connect(optionsButtonBox, SIGNAL(rejected()), this, SLOT(reject())); // Cancel + connect(optionsButtonBox, SIGNAL(accepted()), this, SLOT(accept())); // Ok + connect(saveGlblButton, SIGNAL(released()), this, SLOT(saveToGlobalConfig())); +} -/* we make the widgets on demand here */ -void VkOptionsDialog::showPage( QListWidgetItem* currItem, - QListWidgetItem* prevItem ) +/*! + Show the chosen options page +*/ +void VkOptionsDialog::showPage( QListWidgetItem* nextItem ) { - int nextIdx = contentsListWidget->row( currItem ); - int prevIdx = contentsListWidget->row( prevItem ); + int nextIdx = contentsListWidget->row( nextItem ); - std::cerr << "showPage( " << prevIdx << " -> " << nextIdx << " )" << std::endl; +// std::cerr << "showPage( " << nextIdx << " )" << std::endl; -// TODO: check last page edits saved/rejected -// optionPages->currentWidget(); +// TODO: check no uncommited edits in last page +// proper way to do this is subclass contentsListWidget to catch click events... - // all well => change to next page +//TODO? setWindowTitle( capt + item->text() ); optionPages->setCurrentIndex( nextIdx ); - - -#if 0 // TODO - if ( item ) { - CategItem* cit = (CategItem*)item; - - /* check no uncommited edits in last page */ - VkOptionsPage* last_page = (VkOptionsPage*)wStack->visibleWidget(); - - if (last_page != 0 && /* moving from previous */ - last_page != cit->page()) { /* prev not same as next */ - /* first pull back to the right item selection */ - categories->setSelected( last_page->optId(), true ); - - if (applyButton->isEnabled()) { - /* choose to apply/reset edits */ - CategItem* last_cit = (CategItem*)categories->item( last_page->optId()); - int ok = vkQuery( this, "Apply/Reset Edits", - "&Apply;&Reset;&Cancel", - "<p>There are non-committed edits in option page %s.<br/>" - "Would you like to Apply or Reset these edits?</p>", - last_cit->text().latin1() ); - switch ( ok ) { - case MsgBox::vkYes: apply(); break; - case MsgBox::vkNo: reject(); break; - case MsgBox::vkCancel: return; /* jump back to last page */ - default: - vk_assert_never_reached(); - } - } - } - - setCaption( capt + item->text() ); - - /* first time this item has been selected */ - if ( cit->page() == 0 ) { - VkOptionsPage* page = mkVkOptionsPage( cit->catId() ); - if ( page == 0 ) { - VK_DEBUG("cit->text = %s", cit->text().latin1() ); - return; - } - cit->setWidget( page ); - wStack->addWidget( page, cit->catId() ); - } - - /* make sure the item seletion is sync'd */ - categories->setSelected( cit->catId(), true ); - wStack->raiseWidget( cit->page() ); - cit->page()->init(); - } -#endif } -#if 0 // TODO -VkOptionsPage* VkOptionsDialog::mkVkOptionsPage( int catid ) -{ - VkObject* obj = ((MainWindow*)parent())->valkyrie()->vkObject( catid ); - VkOptionsPage* page = obj->createVkOptionsPage( this ); - vk_assert( page != 0 ); - - optPages.append( page ); - connect( page, SIGNAL(modified()), this, SLOT(modified()) ); - - /* handle e.g. user pressing return in an ledit */ - connect( page, SIGNAL(apply()), this, SLOT(apply()) ); - - return page; -} - - -void VkOptionsDialog::showPage( int catid ) -{ - if ( isMinimized() ) { - setCategory( catid ); - showNormal(); - return; - } - - /* been there, done that ... */ - if ( xpos != -1 && ypos != -1 ) { - setCategory( catid ); - show(); - return; - } - - /* first time we've been shown */ - if ( !isVisible() ) { -// adjustSize(); - setCategory( catid ); - show(); - } -} - - -/* save edits to disk - - applies current page edits - - saves all changes to disk. - - Need a 'save' because we're not auto-saving 'applied' edits. - 'Apply' just means check edits and update Valkyrie. - 'Save' means save changes to disk for next startup. - This is because Vk accepts cmdline values... if started with option - values xyz, don't necessarily want those saved to disk for next run. - This needs some clear thinking... -*/ -void VkOptionsDialog::save() -{ - if (!apply()) - return; - - /* save opts to disk... */ - if ( vkConfig->isDirty() ) - vkConfig->sync( ((MainWindow*)parent())->valkyrie() ); - - saveButton->setEnabled( vkConfig->isDirty() ); -} - -#endif - - - /* reject edits - only current page can be in an edited state. - don't emit flagsChanged - only 'changed' once they're 'applied'. */ void VkOptionsDialog::reject() { - std::cerr << "reject()" << std::endl; - QDialog::reject(); +// std::cerr << "VkOptionsDialog::reject()" << std::endl; -#if 0 // TODO - VkOptionsPage* page = (VkOptionsPage*)wStack->visibleWidget(); + VkOptionsPage* page = (VkOptionsPage*)optionPages->currentWidget(); vk_assert( page ); if ( !page->rejectEdits() ) { VK_DEBUG("Failed to reject edits"); } -#endif + + QDialog::reject(); } -// TODO: really want this? -// - because now non-modal dlg, only conceivable use is -// to make look'n'feel changes directly visible... + /*! Apply edits - - only current page can be in an edited state. + The 'apply' button is important for look and feel options to be tried out + Only current page can be in an edited state. */ -void VkOptionsDialog::apply() +bool VkOptionsDialog::apply() { - std::cerr << "apply()" << std::endl; +// std::cerr << "VkOptionsDialog::apply()" << std::endl; -#if 0 // TODO - VkOptionsPage* page = (VkOptionsPage*)wStack->visibleWidget(); + VkOptionsPage* page = (VkOptionsPage*)optionPages->currentWidget(); vk_assert( page ); if ( !page->applyEdits() ) { VK_DEBUG("Failed to apply edits"); return false; } - /* let the toolviews know that the flags (may) have changed */ + // ensure changes saved to disc + vkConfig->sync(); + + // let the toolviews know that the flags (may) have changed emit flagsChanged(); return true; -#endif } -/* apply edits and quit if no problems */ + +/*! + apply edits and quit if no problems + - save the settings to the Project cfg file if specified +*/ void VkOptionsDialog::accept() { -#if 0 // TODO - if ( apply() ) - close(); -#endif +// std::cerr << "VkOptionsDialog::apply()" << std::endl; - std::cerr << "accept()" << std::endl; - - // TODO: save() - - QDialog::accept(); + if ( apply() ) { + QDialog::accept(); + } + // Else, we have a problem. + // Best to let the user know changes didn't get committed, and let them cancel. } -void VkOptionsDialog::restoreDefaults() -{ - std::cerr << "restoreDefaults" << std::endl; -} - - - -#if 0 // TODO -/* reset to installation defaults - - only reset current page +/*! + save applied edits to global config file + - only enabled when no edits outstanding, to prevent any confusion. */ -void VkOptionsDialog::resetDefaults() +void VkOptionsDialog::saveToGlobalConfig() { - VkOptionsPage* page = (VkOptionsPage*)wStack->visibleWidget(); - vk_assert( page ); - page->resetDefaults(); + vkConfig->saveToGlblConfigFile(); } -void VkOptionsDialog::moveEvent( QMoveEvent* me ) -{ - xpos = me->pos().x(); - ypos = me->pos().y(); -} -void VkOptionsDialog::closeEvent( QCloseEvent * ) -{ hide(); } - - -/* slot called by page->modified() signal - - only current page can have been modified. +/*! + Enable/disable buttons. + This slot is called by page->modified() signal + - only current page can have been modified. */ -void VkOptionsDialog::modified() +void VkOptionsDialog::pageModified() { - bool edited = false; - VkOptionsPage* page = (VkOptionsPage*)wStack->visibleWidget(); + VkOptionsPage* page = (VkOptionsPage*)optionPages->currentWidget(); vk_assert( page ); - edited = page->isModified(); + bool modified = page->isModified(); - applyButton->setEnabled( edited ); - resetButton->setEnabled( edited ); - saveButton->setEnabled( edited || vkConfig->isDirty() ); + QPushButton* applyButton = optionsButtonBox->button( QDialogButtonBox::Apply ); + QPushButton* cancelButton = optionsButtonBox->button( QDialogButtonBox::Cancel ); + applyButton->setEnabled( modified ); + cancelButton->setEnabled( modified ); + // enable save only when no edits + saveGlblButton->setEnabled( !modified ); } -#endif Modified: branches/valkyrie_qt4port/options/vk_options_dialog.h =================================================================== --- branches/valkyrie_qt4port/options/vk_options_dialog.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_options_dialog.h 2010-01-08 00:46:31 UTC (rev 462) @@ -24,55 +24,38 @@ #include <QDialog> #include <QDialogButtonBox> -#include <QFrame> -#include <QHBoxLayout> #include <QListWidget> #include <QStackedWidget> #include <QWidget> // ============================================================ -class VkObject; -class VkOptionsPage; - - -// ============================================================ class VkOptionsDialog : public QDialog { Q_OBJECT public: - VkOptionsDialog( QWidget* parent=0 ); + VkOptionsDialog( QWidget* ); ~VkOptionsDialog(); private: void setupLayout(); private slots: - void restoreDefaults(); - void apply(); + bool apply(); void accept(); void reject(); - void showPage( QListWidgetItem* prev, QListWidgetItem* curr ); -// TODO -// void pageModified(); + void showPage( QListWidgetItem* ); + void pageModified(); + void saveToGlobalConfig(); -private: - void addPage( VkObject* obj ); - VkOptionsPage* createPage(); -// TODO -// void save(); +signals: + void flagsChanged(); -// TODO -//signals: void flagsChanged(); - private: - QVBoxLayout* vLayout; - QWidget* hLayoutWidget; - QHBoxLayout* hLayout; QListWidget* contentsListWidget; - QFrame* pagesFrame; QStackedWidget* optionPages; QDialogButtonBox* optionsButtonBox; + QPushButton* saveGlblButton; }; Modified: branches/valkyrie_qt4port/options/vk_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_options_page.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -20,6 +20,8 @@ ** ****************************************************************************/ +#include "utils/vk_utils.h" + #if 0 #include "vk_utils.h" #include "vk_config.h" @@ -34,8 +36,11 @@ #include "options/widgets/opt_lb_widget.h" #include "options/widgets/opt_le_widget.h" #include "options/widgets/opt_sp_widget.h" +#include "utils/vk_config.h" +#include <QList> + /***************************************************************************/ /*! Constructs an Categories @@ -45,8 +50,7 @@ { this->setObjectName( obj->objectName() + "OptPage" ); -//TODO -// m_mod = false; + m_mod = false; lineHeight = fontMetrics().height(); pageTopVLayout = new QVBoxLayout( this ); @@ -60,11 +64,14 @@ */ VkOptionsPage::~VkOptionsPage() { -#if 0// TODO m_editList.clear(); - m_itemList.setAutoDelete( true ); + + // cleanup all option widgets + foreach ( OptionWidget* optw, m_itemList) { + delete optw; + optw = 0; + } m_itemList.clear(); -#endif } @@ -86,61 +93,41 @@ } -#if 0 // TODO -void VkOptionsPage::resetDefaults() -{ - int ok = vkQuery( this, 2, "Reset Defaults", - "<p>This will reset <b>all</b> options for the " - "option page %s to the installation defaults.<br/>" - "(Other option pages will be unaffected).</p>" - "<p>Continue ?</p>", m_vkObj->title().latin1() ); - if ( ok == MsgBox::vkYes ) { - QIntDictIterator<OptionWidget> it( m_itemList ); - for ( ; it.current(); ++it ) { - it.current()->resetDefault(); - } - } -} -#endif - +/*! + updateEditList + Only here is m_editList managed. +*/ void VkOptionsPage::updateEditList( bool edstate, OptionWidget* optw ) { -edstate = edstate; optw = optw; -#if 0 // TODO - /* check this widget isn't already in the list */ - int indx = m_editList.findRef( optw ); + // check this widget isn't already in the list + int indx = m_editList.indexOf( optw ); - /* widget has been edited and is not already in the list */ + // widget has been edited and is not already in the list if ( edstate == true && indx == -1 ) { m_editList.append( optw ); } else if ( edstate == false && indx != -1 ) { - /* widget was reset and is already in the list */ - m_editList.remove( indx ); + // widget was reset and is already in the list + m_editList.removeAt( indx ); } m_mod = m_editList.isEmpty() ? false : true; emit modified(); -#endif } -#if 0 // TODO /* reset button clicked */ bool VkOptionsPage::rejectEdits() { if ( m_editList.count() != 0 ) { - OptionWidget* optw; - QPtrList<OptionWidget> tmpList; + // first copy the list: the list is managed by this->updateEditList(). + QList<OptionWidget*> tmpList = m_editList; - for ( optw=m_editList.first(); optw; optw=m_editList.next() ) { - tmpList.append( optw ); + // now remove all the items from m_editList: + // signal is emitted for by each optw, calls this->updateEditList() + for (int i = 0; i < tmpList.size(); ++i) { + tmpList.at(i)->cancelEdit(); } - /* now remove all the items from m_editList: signal is emitted */ - for ( optw=tmpList.first(); optw; optw=tmpList.next() ) { - optw->cancelEdit(); - } - tmpList.clear(); } vk_assert( m_mod == false ); @@ -150,34 +137,47 @@ } -/* called from OptionsWindow::apply(), accept() */ +/*! + applyEdits() + Called from OptionsWindow::apply(), accept() +*/ bool VkOptionsPage::applyEdits() { - if ( m_editList.isEmpty() && m_mod == false ) +// std::cerr << "applyEDITS()" << std::endl; + + if ( m_editList.isEmpty() && m_mod == false ) return true; - /* user clicked Ok/Apply after editing some items */ + std::cerr << "applyEDITS(): 2" << std::endl; + + // user clicked Ok/Apply after editing some items + + // verify entries before committing them OptionWidget* optw; - QPtrList<OptionWidget> tmpList; + for (int i = 0; i < m_editList.size(); ++i) { + optw = m_editList.at(i); + if ( !checkOption( optw->id() ) ) { + return false; + } + std::cerr << "applyEDITS(): 3 (" << i << ")" << std::endl; - /* verify entries before committing them */ - for ( optw=m_editList.first(); optw; optw=m_editList.next() ) { - if ( !checkOption( optw->id() ) ) - return false; - /* update any Valkyrie state dependent on this option */ + // update any Valkyrie state dependent on this option applyOption( optw->id() ); } - - /* if we got to here, then we passed all checks */ - for ( optw=m_editList.first(); optw; optw=m_editList.next() ) { - /* no signal emitted: optw is still in m_editList */ + std::cerr << "applyEDITS(): 4" << std::endl; + + // if we got to here, then we passed all checks -> save the edits + QList<OptionWidget*> tmpList; + for (int i = 0; i < m_editList.size(); ++i) { + optw = m_editList.at(i); + // no signal emitted: optw is still in m_editList optw->saveEdit(); tmpList.append( optw ); } - /* now remove all the saved items from m_editList */ - for ( optw=tmpList.first(); optw; optw=tmpList.next() ) - updateEditList( false, optw ); - tmpList.clear(); + // now remove all the saved items from m_editList + for (int i = 0; i < tmpList.size(); ++i) { + updateEditList( false, tmpList.at(i) ); + } vk_assert( m_mod == false ); vk_assert( m_editList.isEmpty() == true ); @@ -185,33 +185,38 @@ } -/* check valid option via VkObject - argval may be altered by checks, so return it */ +/*! + checkOption() + Check valid option via VkObject +*/ bool VkOptionsPage::checkOption( unsigned int optId ) { vk_assert( optId < m_vkObj->maxOptId() ); QString argval = m_itemList[optId]->currValue(); - /* argval may be altered by checkOptArg() */ + // Note: argval may be altered by checkOptArg() int errval = m_vkObj->checkOptArg( optId, argval ); if ( errval != PARSED_OK ) { +cerr << "TODO: vkError: Invalid Entry: " << errval << endl; +#if 0 // TODO vkError( this, "Invalid Entry", "%s:\n\"%s\"", parseErrString(errval), m_itemList[optId]->currValue().latin1() ); +#endif m_itemList[optId]->cancelEdit(); return false; } - /* argval may have been altered by checkOptArg(), e.g. a file path - - only applies to line-edit widgets. */ + // argval may have been altered by checkOptArg(), e.g. a file path + // - only applies to line-edit widgets. if ( argval != m_itemList[optId]->currValue() ) { - if ( m_itemList[optId]->isA("LeWidget") ) + if ( m_itemList[optId]->inherits( "LeWidget" ) ) ((LeWidget*)m_itemList[optId])->setCurrValue( argval ); } return true; } -#endif + OptionWidget* VkOptionsPage::insertOptionWidget( int optid, QWidget* parent, bool mklabel ) @@ -221,8 +226,7 @@ switch ( opt->widgType ) { case VkOPT::WDG_NONE: - // TODO -// vk_assert_never_reached(); + vk_assert_never_reached(); break; case VkOPT::WDG_CHECK: optWidget = (OptionWidget*)new CkWidget( parent, opt, mklabel ); @@ -244,15 +248,21 @@ case VkOPT::WDG_SPINBOX: { SpWidget* spinw = new SpWidget( parent, opt, mklabel, 1 ); + bool ok; int step = (opt->argType == VkOPT::ARG_PWR2) ? 0 : 1; -// TODO -// QString ival = vkConfig->rdEntry( opt->cfgKey(), opt->cfgGroup() ); - QString ival = "1"; + QString val = vkConfig->value( opt->configKey() ).toString(); + int ival = val.toInt(&ok); + if ( !ok ) { + cerr << "Error in VkOptionsPage::insertOptionWidget( " << optid << " ): " << + "VkOPT::WDG_SPINBOX: bad int conversion from: '" << val.toLatin1().data() << "'" << endl; + // soldier on... + ival = 0; + } spinw->addSection( opt->possValues[0].toInt(), // min opt->possValues[1].toInt(), // max - ival.toInt(), // def - step ); // step (if 0: pwr2) + ival, // default + step ); // step (if 0: pwr2) optWidget = (OptionWidget*)spinw; } Modified: branches/valkyrie_qt4port/options/vk_options_page.h =================================================================== --- branches/valkyrie_qt4port/options/vk_options_page.h 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/vk_options_page.h 2010-01-08 00:46:31 UTC (rev 462) @@ -62,13 +62,12 @@ VkOptionsPage( VkObject* obj ); ~VkOptionsPage(); -#if 0 // TODO bool rejectEdits(); bool applyEdits(); bool isModified() { return m_mod; } - void resetDefaults(); - /* init page on open */ +#if 0 // TODO + // init page on open virtual void init() { /*do nothing*/ } int optId(); @@ -87,14 +86,13 @@ OptionWidget* insertOptionWidget( int optid, QWidget* parent, bool mklabel ); QFrame* sep( QWidget* parent ); -#if 0 // TODO bool checkOption( unsigned int optId ); - /* apply option: update Valkyrie state dependent on this option */ + + // apply option: update Valkyrie state dependent on this option virtual void applyOption( int id ) = 0; -#endif protected: -// bool m_mod; + bool m_mod; int lineHeight; QVBoxLayout *pageTopVLayout; Modified: branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp =================================================================== --- branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp 2009-12-19 23:12:34 UTC (rev 461) +++ branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp 2010-01-08 00:46:31 UTC (rev 462) @@ -20,10 +20,10 @@ #include "options/widgets/opt_base_widget.h" #include "options/vk_option.h" // for listbox fileCheck() +#include "utils/vk_config.h" #if 0 #include "vk_utils.h" -#include "vk_config.h" #include "v... [truncated message content] |