|
From: <sv...@va...> - 2010-03-12 20:40:37
|
Author: cerion
Date: 2010-03-12 20:40:12 +0000 (Fri, 12 Mar 2010)
New Revision: 495
Log:
Much refactoring of the option widgets (how did they ever work before!): if they don't work now, at least they all don't work in the same way ;-)
- all conform to a more general abstract interface
- removed knowledge of valgrind/valkyrie from these internals
- two standard signals:
* valueChanged(): emitted on all edit changes
- triggers updates of dialog: apply/cancel button state etc. etc.
* editDone(): emitted once editing finished for that widget
- triggers immediate validation of input via vkObject::checkOptArg()
plus:
- fixed VkConfig::strToBool() to tell us if parsing string->bool actually failed,
- pulled out some input checks from the option widgets/pages, and put them in their appropriate vkObject::checkOptArg() functions, where they belong (and added the necessary new PERROR_ types).
Modified:
branches/valkyrie_qt4port/objects/valgrind_object.cpp
branches/valkyrie_qt4port/objects/valkyrie_object.cpp
branches/valkyrie_qt4port/options/valgrind_options_page.cpp
branches/valkyrie_qt4port/options/valkyrie_options_page.cpp
branches/valkyrie_qt4port/options/vk_option.cpp
branches/valkyrie_qt4port/options/vk_option.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_base_widget.h
branches/valkyrie_qt4port/options/widgets/opt_cb_widget.cpp
branches/valkyrie_qt4port/options/widgets/opt_cb_widget.h
branches/valkyrie_qt4port/options/widgets/opt_ck_widget.cpp
branches/valkyrie_qt4port/options/widgets/opt_ck_widget.h
branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp
branches/valkyrie_qt4port/options/widgets/opt_lb_widget.h
branches/valkyrie_qt4port/options/widgets/opt_le_widget.cpp
branches/valkyrie_qt4port/options/widgets/opt_le_widget.h
branches/valkyrie_qt4port/options/widgets/opt_sp_widget.cpp
branches/valkyrie_qt4port/options/widgets/opt_sp_widget.h
branches/valkyrie_qt4port/utils/vk_config.cpp
branches/valkyrie_qt4port/utils/vk_config.h
Modified: branches/valkyrie_qt4port/objects/valgrind_object.cpp
===================================================================
--- branches/valkyrie_qt4port/objects/valgrind_object.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/objects/valgrind_object.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -542,14 +542,17 @@
for ( ; it != files.end(); ++it ) {
// check file ok and has at least R permissions
*it = fileCheck( &errval, *it, true );
-
if ( errval != PARSED_OK ) {
- break;
+ return errval;
}
-
// TODO: ? check valid suppression files
}
-
+
+ // check for duplicates
+ if ( files.removeDuplicates() > 0 ) {
+ return PERROR_DUPLICATE;
+ }
+
argval = files.join( sep );
}
break;
Modified: branches/valkyrie_qt4port/objects/valkyrie_object.cpp
===================================================================
--- branches/valkyrie_qt4port/objects/valkyrie_object.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/objects/valkyrie_object.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -26,6 +26,7 @@
#include "utils/vk_utils.h"
#include <QFile>
+#include <QFileInfo>
#include <QPoint>
#include <QStringList>
@@ -554,8 +555,20 @@
( void ) dirCheck( &errval, argval, true, true, true );
} break;
- // helper executables
- case VALKYRIE::BROWSER:
+ // browser executable
+ case VALKYRIE::BROWSER: {
+ if ( argval.isEmpty() ) {
+ // empty is fine.
+ } else {
+ // check for at least X permissions.
+ QString path = argval.split( " " ).first();
+ QString file = fileCheck( &errval, path, false, false, true );
+ argval.replace( path, file );
+ argval = argval.simplified();
+ }
+ } break;
+
+ // editor executable
case VALKYRIE::SRC_EDITOR: {
if ( argval.isEmpty() ) {
// empty is fine.
@@ -565,9 +578,19 @@
QString file = fileCheck( &errval, path, false, false, true );
argval.replace( path, file );
argval = argval.simplified();
+
+ if ( !argval.contains( "%n" ) ) {
+ // for a few well-known editors, add the go-to-line
+ // editor flag, plus our replacement string (%n)
+ QFileInfo fi( argval );
+ QString fname = fi.fileName();
+ if ( fname.contains( QRegExp( "^(emacs|gedit|gvim|nano|nedit)[\\W]*" ) ) ) {
+ argval += " +%n";
+ }
+ }
}
} break;
-
+
// valkyrie project file
case VALKYRIE::PROJ_FILE: {
// check file exists and has RW perms
Modified: branches/valkyrie_qt4port/options/valgrind_options_page.cpp
===================================================================
--- branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -175,7 +175,6 @@
insertOptionWidget( VALGRIND::DB_COMMAND, egroup1, false ); // ledit+button
LeWidget* dbLedit = (( LeWidget* )m_itemList[VALGRIND::DB_COMMAND] );
dbLedit->addButton( egroup1, this, SLOT( getDbBin() ) );
- connect( dbLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALGRIND::INPUT_FD, egroup1, true ); // spinbox
insertOptionWidget( VALGRIND::LOG_FD, egroup1, true ); // spinbox
Modified: branches/valkyrie_qt4port/options/valkyrie_options_page.cpp
===================================================================
--- branches/valkyrie_qt4port/options/valkyrie_options_page.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/valkyrie_options_page.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -88,16 +88,13 @@
insertOptionWidget( VALKYRIE::BINARY, group1, false ); // ledit + button
LeWidget* binLedit = (( LeWidget* )m_itemList[VALKYRIE::BINARY] );
binLedit->addButton( group1, this, SLOT( getBinary() ) );
- connect( binLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALKYRIE::BIN_FLAGS, group1, true ); // ledit
LeWidget* binFlgsLedit = (( LeWidget* )m_itemList[VALKYRIE::BIN_FLAGS] );
- connect( binFlgsLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALKYRIE::WORKING_DIR, group1, false ); // line edit + button
LeWidget* dirWorking = (( LeWidget* )m_itemList[VALKYRIE::WORKING_DIR] );
dirWorking->addButton( group1, this, SLOT( getWorkingDir() ) );
- connect( dirWorking, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
// target setup - layout
grid->addWidget( binLedit->button(), i, 0 );
@@ -115,24 +112,20 @@
insertOptionWidget( VALKYRIE::SRC_EDITOR, group1, false ); // ledit + button
LeWidget* editLedit = (( LeWidget* )m_itemList[VALKYRIE::SRC_EDITOR] );
editLedit->addButton( group1, this, SLOT( getEditor() ) );
- connect( editLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALKYRIE::SRC_LINES, group1, true ); // intspin
insertOptionWidget( VALKYRIE::BROWSER, group1, false ); // line edit
LeWidget* brwsrLedit = (( LeWidget* )m_itemList[VALKYRIE::BROWSER] );
brwsrLedit->addButton( group1, this, SLOT( getBrowser() ) );
- connect( brwsrLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALKYRIE::DFLT_LOGDIR, group1, false ); // line edit + button
LeWidget* dirLogSave = (( LeWidget* )m_itemList[VALKYRIE::DFLT_LOGDIR] );
dirLogSave->addButton( group1, this, SLOT( getDfltLogDir() ) );
- connect( dirLogSave, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
insertOptionWidget( VALKYRIE::VG_EXEC, group1, false ); // ledit + button
LeWidget* vgbinLedit = (( LeWidget* )m_itemList[VALKYRIE::VG_EXEC] );
vgbinLedit->addButton( group1, this, SLOT( getVgExec() ) );
- connect( vgbinLedit, SIGNAL( returnPressed() ), this, SIGNAL( apply() ) );
// general prefs - layout
grid->addWidget( editLedit->button(), i, 0 );
@@ -210,7 +203,7 @@
QFont font = QFontDialog::getFont( &ok, afont, this, "Select General Font" );
if ( ok ) {
- fontLedit->setCurrValue( font.toString() );
+ fontLedit->setValue( font.toString() );
}
}
@@ -228,7 +221,7 @@
QFont font = QFontDialog::getFont( &ok, afont, this, "Select Tool Font" );
if ( ok ) {
- fontLedit->setCurrValue( font.toString() );
+ fontLedit->setValue( font.toString() );
}
}
@@ -258,20 +251,8 @@
start_dir, tr("All Files (*)"));
if ( !editor.isEmpty() ) { // user might have clicked Cancel
-
- // for a few well known editors, add the
- // go-to-line editor flag, plus our replacement string (%n)
- QFileInfo fi( editor );
- if ( fi.fileName().startsWith( "emacs " ) ||
- fi.fileName().startsWith( "gedit " ) ||
- fi.fileName().startsWith( "gvim " ) ||
- fi.fileName().startsWith( "nano " ) ||
- fi.fileName().startsWith( "nedit " ) ) {
- editor += " +%n";
- }
-
- editLedit->setCurrValue( editor );
- checkOption( VALKYRIE::SRC_EDITOR );
+ editLedit->setValue( editor );
+ // update triggers checkOption()
}
}
@@ -286,8 +267,8 @@
"./", tr("All Files (*)"));
if ( !binfile.isEmpty() ) { // user might have clicked Cancel
- (( LeWidget* )m_itemList[VALKYRIE::BINARY] )->setCurrValue( binfile );
- checkOption( VALKYRIE::BINARY );
+ (( LeWidget* )m_itemList[VALKYRIE::BINARY] )->setValue( binfile );
+ // update triggers checkOption()
}
}
@@ -302,8 +283,8 @@
"./", tr("All Files (*)"));
if ( !brwsr.isEmpty() ) { // user might have clicked Cancel
- (( LeWidget* )m_itemList[VALKYRIE::BROWSER] )->setCurrValue( brwsr );
- checkOption( VALKYRIE::BROWSER );
+ (( LeWidget* )m_itemList[VALKYRIE::BROWSER] )->setValue( brwsr );
+ // update triggers checkOption()
}
}
@@ -318,8 +299,8 @@
"./", tr("All Files (*)"));
if ( !vg_exec.isEmpty() ) { // user might have clicked Cancel
- (( LeWidget* )m_itemList[VALKYRIE::VG_EXEC] )->setCurrValue( vg_exec );
- checkOption( VALKYRIE::VG_EXEC );
+ (( LeWidget* )m_itemList[VALKYRIE::VG_EXEC] )->setValue( vg_exec );
+ // update triggers checkOption()
}
}
@@ -338,8 +319,8 @@
QFileDialog::ShowDirsOnly );
if ( !dir_logsave.isEmpty() ) { // user might have clicked Cancel
- (( LeWidget* )m_itemList[VALKYRIE::DFLT_LOGDIR] )->setCurrValue( dir_logsave );
- checkOption( VALKYRIE::DFLT_LOGDIR );
+ (( LeWidget* )m_itemList[VALKYRIE::DFLT_LOGDIR] )->setValue( dir_logsave );
+ // update triggers checkOption()
}
}
@@ -357,7 +338,7 @@
QFileDialog::ShowDirsOnly );
if ( !dir_working.isEmpty() ) { // user might have clicked Cancel
- (( LeWidget* )m_itemList[VALKYRIE::WORKING_DIR] )->setCurrValue( dir_working );
- checkOption( VALKYRIE::WORKING_DIR );
+ (( LeWidget* )m_itemList[VALKYRIE::WORKING_DIR] )->setValue( dir_working );
+ // update triggers checkOption()
}
}
Modified: branches/valkyrie_qt4port/options/vk_option.cpp
===================================================================
--- branches/valkyrie_qt4port/options/vk_option.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/vk_option.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -93,6 +93,8 @@
return "number is not a power of two";
case PERROR_BADVERSION:
return "Bad program version";
+ case PERROR_DUPLICATE:
+ return "Duplicate entries";
default:
return "unknown error";
}
Modified: branches/valkyrie_qt4port/options/vk_option.h
===================================================================
--- branches/valkyrie_qt4port/options/vk_option.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/vk_option.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -93,6 +93,7 @@
#define PERROR_DB_OUTPUT -31 // using db-attach, but not sending output to stderr
#define PERROR_POWER_OF_TWO -32 // number not a power of two
#define PERROR_BADVERSION -33 // bad program version
+#define PERROR_DUPLICATE -34 // duplicate entries
const char* parseErrString( const int error );
Modified: branches/valkyrie_qt4port/options/vk_options_page.cpp
===================================================================
--- branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -126,41 +126,34 @@
/*!
applyEdits()
- Called from OptionsDialog::apply(), accept()
+ user clicked Ok/Apply after editing some items
*/
bool VkOptionsPage::applyEdits()
{
if ( m_editList.isEmpty() && m_mod == false ) {
return true;
}
-
- // user clicked Ok/Apply after editing some items
-
- // verify all entries before committing any
- OptionWidget* optw;
-
- for ( int i = 0; i < m_editList.size(); ++i ) {
- optw = m_editList.at( i );
- if ( !checkOption( optw->id() ) ) {
+ // verify all edited entries before committing any.
+ // TODO: shouldn't need to do this anymore, as we now verify upon
+ // edit completion. But keeping it in for now.
+ foreach( OptionWidget* optw, m_editList ) {
+ if ( !checkOption( optw ) ) {
return false;
}
}
- // all entries ok: commit them
+ // all edited entries ok: commit them all
QList<OptionWidget*> tmpList;
-
- for ( int i = 0; i < m_editList.size(); ++i ) {
- optw = m_editList.at( i );
-
+ foreach( OptionWidget* optw, m_editList ) {
// optw->option emits valueChanged() on save:
optw->saveEdit();
tmpList.append( optw );
}
// now remove all the saved items from m_editList
- for ( int i = 0; i < tmpList.size(); ++i ) {
- updateEditList( false, tmpList.at( i ) );
+ foreach( OptionWidget* optw, tmpList ) {
+ updateEditList( false, optw );
}
vk_assert( m_mod == false );
@@ -173,30 +166,26 @@
checkOption()
Check valid option via VkObject
*/
-bool VkOptionsPage::checkOption( unsigned int optId )
+bool VkOptionsPage::checkOption( OptionWidget* opt )
{
- vk_assert( optId < m_vkObj->maxOptId() );
+ vk_assert( opt );
+ vk_assert( opt->id() < (int)m_vkObj->maxOptId() );
+
+ QString argval = opt->currValue();
+ int errval = m_vkObj->checkOptArg( opt->id(), argval );
- QString argval = m_itemList[optId]->currValue();
- // Note: argval may be altered by checkOptArg()
- int errval = m_vkObj->checkOptArg( optId, argval );
-
if ( errval != PARSED_OK ) {
-
- vkError( this, "Invalid Entry", "%s:\n\"%s\"",
+ vkError( this, "Invalid Entry", "%s:<br><i>%s</i>",
parseErrString( errval ),
- qPrintable( m_itemList[optId]->currValue() ) );
-
- m_itemList[optId]->cancelEdit();
+ qPrintable( opt->printCurrValue() ) );
+
+ opt->cancelEdit();
return false;
}
// 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]->inherits( "LeWidget" ) ) {
- (( LeWidget* )m_itemList[optId] )->setCurrValue( argval );
- }
+ if ( argval != opt->currValue() ) {
+ opt->setValue( argval );
}
return true;
@@ -243,7 +232,7 @@
if ( !ok ) {
cerr << "Error in VkOptionsPage::insertOptionWidget( " << optid << " ): "
<< "VkOPT::WDG_SPINBOX: bad int conversion from: '"
- << val.toLatin1().data() << "'" << endl;
+ << qPrintable( val ) << "'" << endl;
// soldier on...
ival = 0;
}
@@ -261,7 +250,11 @@
optWidget = 0;
break;
}
-
+
+ // check validity of option values immediately upon finishing edit
+ connect( optWidget, SIGNAL( editDone( OptionWidget* ) ),
+ this, SLOT( checkOption( OptionWidget* ) ) );
+
// ------------------------------------------------------------
// Insert into the itemlist
m_itemList.insert( optid, optWidget );
Modified: branches/valkyrie_qt4port/options/vk_options_page.h
===================================================================
--- branches/valkyrie_qt4port/options/vk_options_page.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/vk_options_page.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -74,15 +74,14 @@
protected slots:
void updateEditList( bool, OptionWidget* );
-
+ bool checkOption( OptionWidget* opt );
+
protected:
virtual void setupOptions() = 0;
OptionWidget* insertOptionWidget( int optid, QWidget* parent, bool mklabel );
QFrame* sep( QWidget* parent );
-
- bool checkOption( unsigned int optId );
-
+
protected:
bool m_mod;
int lineHeight;
Modified: branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_base_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -53,6 +53,21 @@
{ }
+void OptionWidget::setCurrValue( const QString& txt )
+{
+ if ( m_currentValue != txt ) {
+ m_currentValue = txt;
+ bool edited = (m_currentValue != m_initialValue);
+ emit valueChanged( edited, this );
+
+ // default behaviour is that any change is a complete change
+ // - can then e.g. test new value.
+ if ( edited ) {
+ emit editDone( this );
+ }
+ }
+}
+
int OptionWidget::id()
{
return m_opt->optid;
@@ -78,6 +93,33 @@
return m_initialValue;
}
+
+
+void OptionWidget::setValue( const QString& txt )
+{
+ update( txt );
+}
+
+void OptionWidget::reset()
+{
+ update( m_initialValue );
+}
+
+void OptionWidget::resetDefault()
+{
+ update( m_opt->dfltValue.toString() );
+}
+
+
+/*!
+ virtual function to print current value prettily
+ - some widgets (e.g. listbox) need to overload this.
+*/
+QString OptionWidget::printCurrValue()
+{
+ return currValue();
+}
+
void OptionWidget::saveEdit()
{
m_initialValue = m_currentValue;
@@ -86,8 +128,6 @@
void OptionWidget::cancelEdit()
{
- m_currentValue = m_initialValue;
- emit valueChanged( false, this );
reset();
}
Modified: branches/valkyrie_qt4port/options/widgets/opt_base_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_base_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_base_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -26,7 +26,10 @@
#include <QWidget>
#include <QVBoxLayout>
+#include <iostream>
+using namespace std;
+
// ============================================================
class VkOption;
@@ -42,20 +45,32 @@
int id();
QLabel* label();
QWidget* widget();
+
QString currValue();
QString initValue();
+ QString changedValue();
void setEnabled( bool enable );
-
- virtual void reset() = 0;
- virtual void resetDefault() = 0; //TODO: not used: wanted?
+
+ void setValue( const QString& txt );
+ void reset();
+ void resetDefault(); //TODO: not used: wanted?
+
+ virtual QString printCurrValue();
+
virtual void saveEdit();
virtual void cancelEdit();
+
virtual QHBoxLayout* hlayout();
virtual QVBoxLayout* vlayout();
signals:
void valueChanged( bool, OptionWidget* );
+ void editDone( OptionWidget* );
+protected slots:
+ virtual void setCurrValue( const QString& txt );
+ virtual void update( const QString& txt ) = 0;
+
protected:
QWidget* m_widg;
QLabel* m_wLabel;
Modified: branches/valkyrie_qt4port/options/widgets/opt_cb_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_cb_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_cb_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -57,7 +57,7 @@
m_combo->setCurrentIndex( m_currIdx );
connect( m_combo, SIGNAL( activated( const QString& ) ),
- this, SLOT( cbChanged( const QString& ) ) );
+ this, SLOT( update( const QString& ) ) );
// not added if the url is empty
ContextHelp::addHelp( m_widg, m_opt->urlAddress );
@@ -77,10 +77,10 @@
-void CbWidget::cbChanged( const QString& txt )
+void CbWidget::update( const QString& txt )
{
bool found = false;
-
+
for ( int i = 0; i < m_combo->count(); ++i ) {
if ( txt == m_combo->itemText( i ) ) {
found = true;
@@ -95,22 +95,11 @@
}
else {
m_currIdx = m_combo->currentIndex();
- m_currentValue = m_combo->currentText();
- bool edited = m_currentValue != m_initialValue;
- emit valueChanged( edited, this );
+ setCurrValue( m_combo->currentText() );
}
}
-void CbWidget::reset()
-{
- cbChanged( m_initialValue );
-}
-void CbWidget::resetDefault()
-{
- cbChanged( m_opt->dfltValue.toString() );
-}
-
QHBoxLayout* CbWidget::hlayout()
{
vk_assert( m_wLabel != 0 );
Modified: branches/valkyrie_qt4port/options/widgets/opt_cb_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_cb_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_cb_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -37,13 +37,11 @@
CbWidget( QWidget* parent, VkOption* vkopt, bool mklabel );
~CbWidget();
- void reset();
- void resetDefault();
QHBoxLayout* hlayout();
private slots:
- void cbChanged( const QString& txt );
-
+ void update( const QString& txt );
+
private:
int m_currIdx;
QComboBox* m_combo;
Modified: branches/valkyrie_qt4port/options/widgets/opt_ck_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_ck_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_ck_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -61,31 +61,22 @@
void CkWidget::ckChanged( bool on )
{
- m_currentValue = ( on ) ? m_opt->possValues[0] : m_opt->possValues[1];
- bool edited = m_currentValue != m_initialValue;
- emit valueChanged( edited, this );
+ setCurrValue( m_opt->possValues[ (on ? 0 : 1) ] );
+
// for dis/enabling associated widgets
emit changed( on );
- emit clicked( m_opt->optid );
}
-void CkWidget::reset()
+/*!
+ txt value translated to boolean to check box.
+ only updates if value valid 'boolean' string
+*/
+void CkWidget::update( const QString& txt )
{
- bool cfgChecked = VkConfig::strToBool( m_initialValue );
- m_cbox->setChecked( cfgChecked );
+ bool ok;
+ bool checked = VkConfig::strToBool( txt, &ok );
+ if ( ok ) {
+ m_cbox->setChecked( checked );
+ // toggled signal sent -> calls ckChanged()
+ }
}
-
-void CkWidget::resetDefault()
-{
- setOn( VkConfig::strToBool( m_opt->dfltValue.toString() ) );
-}
-
-bool CkWidget::isOn()
-{
- return m_cbox->isChecked();
-}
-
-void CkWidget::setOn( bool on )
-{
- m_cbox->setChecked( on );
-}
Modified: branches/valkyrie_qt4port/options/widgets/opt_ck_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_ck_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_ck_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -37,18 +37,13 @@
CkWidget( QWidget* parent, VkOption* vkopt, bool mklabel );
~CkWidget();
- bool isOn();
- void reset();
- void resetDefault();
- void setOn( bool on );
-
signals:
- void clicked( int );
void changed( bool );
private slots:
void ckChanged( bool );
-
+ void update( const QString& txt );
+
private:
QCheckBox* m_cbox;
};
Modified: branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -75,7 +75,7 @@
m_sep = vkConfig->vkSepChar;
- reset();
+ update( m_currentValue );
m_lbox->setContextMenuPolicy( Qt::CustomContextMenu );
connect( m_lbox, SIGNAL( customContextMenuRequested( const QPoint& ) ),
this, SLOT( popupMenu( const QPoint& ) ) );
@@ -95,11 +95,12 @@
/*!
- reset lbox to m_currentValue
- called from OptionWidget::cancelEdit(), after m_currentValue reset.
+ reload lbox from m_currentValue
*/
-void LbWidget::reset()
+void LbWidget::update( const QString& txt )
{
+ setCurrValue( txt );
+
m_lbox->clear();
QStringList sfiles = m_currentValue.split( m_sep, QString::SkipEmptyParts );
@@ -110,24 +111,14 @@
/*!
- called from OptionsPage::resetDefaults()
- reset to installation defaults
- */
-void LbWidget::resetDefault()
+ Pretty print current value
+*/
+QString LbWidget::printCurrValue()
{
- m_currentValue = m_opt->dfltValue.toString();
- reset();
- lbChanged();
+ return "For one (or more) of:<br>" + currValue().replace( m_sep, "<br>" );
}
-void LbWidget::setCurrValue( const QString& txt )
-{
- m_currentValue = txt;
- reset();
- lbChanged();
-}
-
/*!
return all contents concat'd with m_sep
*/
@@ -136,7 +127,6 @@
QStringList items;
for ( int i = 0; i < m_lbox->count(); i++ ) {
- m_lbox->removeItemWidget( m_lbox->item( i ) );
items += m_lbox->item( i )->text();
}
@@ -145,15 +135,6 @@
/*!
- emit signals to indicate widget content has changed
-*/
-void LbWidget::lbChanged()
-{
- emit valueChanged( (m_currentValue != m_initialValue), this );
-}
-
-
-/*!
different menus and stuff for the different modes
*/
void LbWidget::popupMenu( const QPoint& pos )
@@ -175,9 +156,7 @@
if ( act == &actRemove ) {
vk_assert( lb_item );
m_lbox->takeItem( m_lbox->row( lb_item ) );
- // update currentvalue, and emit signal
- m_currentValue = lbText();
- lbChanged();
+ setCurrValue( lbText() );
}
else if ( act == &actAdd ) {
QString supp_file =
@@ -186,19 +165,8 @@
"./", tr("Suppression Files (*.supp)") );
if ( ! supp_file.isEmpty() ) { // user clicked Cancel ?
- // check not a duplicate entry
- if ( ! m_lbox->findItems( supp_file, Qt::MatchExactly ).isEmpty() ) {
-
- vkInfo( m_lbox, "Duplicate Entry",
- "The entry '%s' is already in the list.",
- qPrintable( supp_file ) );
- }
- else {
- m_lbox->addItem( supp_file );
- // update currentvalue, and emit signal
- m_currentValue = lbText();
- lbChanged();
- }
+ m_lbox->addItem( supp_file );
+ setCurrValue( lbText() );
}
}
}
Modified: branches/valkyrie_qt4port/options/widgets/opt_lb_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_lb_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_lb_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -33,13 +33,13 @@
public:
LbWidget( QWidget* parent, VkOption* vkopt, bool mklabel );
~LbWidget();
- void reset();
- void resetDefault();
- void setCurrValue( const QString& );
-
+
+ QString printCurrValue(); // overloads base class
+
private slots:
void popupMenu( const QPoint& );
-
+ void update( const QString& txt );
+
private:
QString lbText();
void lbChanged();
Modified: branches/valkyrie_qt4port/options/widgets/opt_le_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_le_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_le_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -38,10 +38,10 @@
m_ledit->setText( m_initialValue );
connect( m_ledit, SIGNAL( textChanged( const QString& ) ),
- this, SLOT( leChanged( const QString& ) ) );
- connect( m_ledit, SIGNAL( returnPressed() ),
- this, SIGNAL( returnPressed() ) );
-
+ this, SLOT( setCurrValue( const QString& ) ) );
+ connect( m_ledit, SIGNAL( editingFinished() ),
+ this, SLOT( editingFinished() ) );
+
// not added if the url is empty
ContextHelp::addHelp( m_widg, m_opt->urlAddress );
}
@@ -64,51 +64,43 @@
}
-void LeWidget::setCurrValue( const QString& txt )
+void LeWidget::editingFinished()
{
- m_ledit->setText( txt ); /* calls leChanged(txt) */
-
- if ( txt.length() > 0 ) {
- m_ledit->setCursorPosition( 0 );
- }
+ emit editDone( this );
}
-void LeWidget::addCurrValue( const QString& txt )
+/*!
+ overloaded from base class
+ just emit valueChanged, _not_ editDone()
+ - we do that on signal m_ledit->editingFinished()
+*/
+void LeWidget::setCurrValue( const QString& value )
{
- if ( m_currentValue.isEmpty() ) {
- setCurrValue( txt );
+ m_currentValue = value;
+ emit valueChanged( (m_currentValue != m_initialValue), this );
+}
+
+
+void LeWidget::update( const QString& txt )
+{
+ m_ledit->setText( txt );
+ // m_ledit signal -> calls setCurrValue()
+
+ if ( txt.length() > 0 ) {
+ m_ledit->setCursorPosition( 0 );
}
- else {
- setCurrValue( m_ledit->text() + "," + txt );
- }
}
+
void LeWidget::setDisabled( bool disable )
{
m_ledit->setDisabled( disable );
-
+
if ( m_pb != 0 ) {
m_pb->setDisabled( disable );
}
}
-void LeWidget::leChanged( const QString& txt )
-{
- m_currentValue = txt;
- bool edited = m_currentValue != m_initialValue;
- emit valueChanged( edited, this );
-}
-
-void LeWidget::reset()
-{
- m_ledit->setText( m_initialValue );
-}
-
-void LeWidget::resetDefault()
-{
- setCurrValue( m_opt->dfltValue.toString() );
-}
-
QPushButton* LeWidget::button()
{
return m_pb;
Modified: branches/valkyrie_qt4port/options/widgets/opt_le_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_le_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_le_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -39,10 +39,6 @@
LeWidget( QWidget* parent, VkOption* vkopt, bool mklabel );
~LeWidget();
- void reset();
- void resetDefault();
- void setCurrValue( const QString& );
- void addCurrValue( const QString& );
void addButton( QWidget* parent, const QObject* receiver,
const char* slot, QString txt = QString::null,
bool icon = false );
@@ -50,16 +46,17 @@
QPushButton* button();
QHBoxLayout* hlayout();
-signals:
- void returnPressed();
-
public slots:
void setDisabled( bool disable );
-
+
private slots:
- void leChanged( const QString& txt );
-
+ void editingFinished();
+ void update( const QString& txt );
+
private:
+ void setCurrValue( const QString& value ); // overloaded
+
+private:
QLineEdit* m_ledit;
QPushButton* m_pb;
};
Modified: branches/valkyrie_qt4port/options/widgets/opt_sp_widget.cpp
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_sp_widget.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_sp_widget.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -41,8 +41,8 @@
m_numSections = num_sections;
connect( m_intspin, SIGNAL( valueChanged( const QString& ) ),
- this, SLOT( spChanged( const QString& ) ) );
-
+ this, SLOT( setCurrValue( const QString& ) ) );
+
// not added if the url is empty
ContextHelp::addHelp( m_widg, m_opt->urlAddress );
}
@@ -119,44 +119,17 @@
m_intspin->addSection( min, max, defval, step, sep_char );
}
-void SpWidget::spChanged( const QString& val )
-{
- m_currentValue = val;
- bool edited = m_currentValue != m_initialValue;
- emit valueChanged( edited, this );
-}
-void SpWidget::reset()
+void SpWidget::update( const QString& txt )
{
if ( m_numSections == 1 ) {
//TODO: multisections
// m_intspin->setValue( m_initialValue.toInt(), 0 );
- m_intspin->setValue( m_initialValue.toInt() );
+ m_intspin->setValue( txt.toInt() );
}
else {
- QStringList values = m_initialValue.split( ",", QString::SkipEmptyParts );
-
- for ( int i = 0; i < values.count(); i++ ) {
- //TODO: multisections
- // m_intspin->setValue( values[i].toInt(), i );
- m_intspin->setValue( values[i].toInt() );
- }
- }
-}
+ QStringList values = txt.split( ",", QString::SkipEmptyParts );
-void SpWidget::resetDefault()
-{
- QString dflt = m_opt->dfltValue.toString();
- spChanged( dflt );
-
- if ( m_numSections == 1 ) {
- //TODO: multisections
- // m_intspin->setValue( dflt.toInt(), 0 );
- m_intspin->setValue( dflt.toInt() );
- }
- else {
- QStringList values = dflt.split( ",", QString::SkipEmptyParts );
-
for ( int i = 0; i < values.count(); i++ ) {
//TODO: multisections
// m_intspin->setValue( values[i].toInt(), i );
@@ -165,6 +138,7 @@
}
}
+
QHBoxLayout* SpWidget::hlayout()
{
vk_assert( m_wLabel != 0 );
Modified: branches/valkyrie_qt4port/options/widgets/opt_sp_widget.h
===================================================================
--- branches/valkyrie_qt4port/options/widgets/opt_sp_widget.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/options/widgets/opt_sp_widget.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -36,16 +36,14 @@
SpWidget( QWidget* parent, VkOption* vkopt, bool mklabel, int num_sections );
~SpWidget();
- void reset();
- void resetDefault();
void addSection( int min, int max, int defval = 0,
int step = 1, QString sep_char = " : " );
QHBoxLayout* hlayout();
-
-private slots:
- void spChanged( const QString& val );
-
+
private:
+ void update( const QString& txt );
+
+private:
IntSpin* m_intspin;
int m_numSections;
};
Modified: branches/valkyrie_qt4port/utils/vk_config.cpp
===================================================================
--- branches/valkyrie_qt4port/utils/vk_config.cpp 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/utils/vk_config.cpp 2010-03-12 20:40:12 UTC (rev 495)
@@ -288,16 +288,28 @@
-/*! Translate valgrind's booleans
+/*!
+ Translate boolean strings into booleans
+ returns true if successfully parsed a 'true' string.
+ returns false otherwise
+ Use argment 'ok' to detect failed 'false' parsing.
*/
-bool VkConfig::strToBool( QString str )
+bool VkConfig::strToBool( QString str, bool* ok )
{
+ if ( ok ) *ok = true;
+
if ( str == "true" || str == "on" ||
str == "yes" || str == "1" ||
str == "T" ) {
return true;
}
+ if ( str == "false" || str == "off" ||
+ str == "no" || str == "0" ||
+ str == "F" ) {
+ return false;
+ }
+ if ( ok ) *ok = false;
return false;
}
Modified: branches/valkyrie_qt4port/utils/vk_config.h
===================================================================
--- branches/valkyrie_qt4port/utils/vk_config.h 2010-03-12 13:32:28 UTC (rev 494)
+++ branches/valkyrie_qt4port/utils/vk_config.h 2010-03-12 20:40:12 UTC (rev 495)
@@ -98,7 +98,7 @@
public:
// util functions
- static bool strToBool( QString str );
+ static bool strToBool( QString str, bool* ok=0 );
static QString vkCfgGlblFilename();
static QString vkTmpDir();
|