From c920ebe540ea3415bec6776991bc0d77bb7f2b3e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Mon, 23 Mar 2015 00:30:15 +0000 Subject: [PATCH] Create a dialog to configure module options --- app/CMakeLists.txt | 1 + app/ConfigureFormatDialog.cpp | 2 +- app/ModulesHandle.cpp | 4 +++ app/PlaYUVerAppModuleIf.h | 12 ++++--- lib/ProgramOptions.cpp | 50 +++++++++++++-------------- lib/ProgramOptions.h | 63 +++++++++++++++-------------------- 6 files changed, 65 insertions(+), 67 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 0c5c485..153d69f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -62,6 +62,7 @@ set(plaYUVer_App_SRCS external/qcustomplot.cpp # Module Plugins ModulesHandle.cpp + ModulesHandleOptDialog.cpp ModuleHandleDock.cpp PlaYUVerAppModuleIf.cpp GridManager.cpp diff --git a/app/ConfigureFormatDialog.cpp b/app/ConfigureFormatDialog.cpp index e5dc4fa..25b415f 100644 --- a/app/ConfigureFormatDialog.cpp +++ b/app/ConfigureFormatDialog.cpp @@ -243,4 +243,4 @@ void ConfigureFormatDialog::StandardResolutionSelection() m_spinBoxheight->setValue( currSize.height() ); } -} // Namespace SCode +} // NAMESPACE diff --git a/app/ModulesHandle.cpp b/app/ModulesHandle.cpp index 4e19ce7..629e23a 100644 --- a/app/ModulesHandle.cpp +++ b/app/ModulesHandle.cpp @@ -28,6 +28,7 @@ #include "VideoHandle.h" #include "PlaYUVerModuleFactory.h" #include "DialogSubWindowSelector.h" +#include "ModulesHandleOptDialog.h" namespace plaYUVer { @@ -302,6 +303,9 @@ Void ModulesHandle::enableModuleIf( PlaYUVerAppModuleIf *pcCurrModuleIf ) pcCurrModuleIf->m_pcSubWindow[i] = videoSubWindowList.at( i ); } + ModulesHandleOptDialog moduleOptDialog( m_pcParent, pcCurrModuleIf ); + moduleOptDialog.runConfiguration(); + if( pcCurrModuleIf->m_pcModule->m_iModuleType == FRAME_PROCESSING_MODULE ) { if( ( pcCurrModuleIf->m_pcModule->m_uiModuleRequirements & MODULE_REQUIRES_NEW_WINDOW ) || bShowModulesNewWindow ) diff --git a/app/PlaYUVerAppModuleIf.h b/app/PlaYUVerAppModuleIf.h index 5dda03d..69524b3 100644 --- a/app/PlaYUVerAppModuleIf.h +++ b/app/PlaYUVerAppModuleIf.h @@ -43,20 +43,20 @@ class VideoSubWindow; class PlaYUVerAppModuleIf #ifdef PLAYUVER_THREADED_MODULES - : public QThread + : public QThread #else - : public QObject + : public QObject #endif { friend class ModulesHandle; friend class ModuleHandleDock; + friend class ModulesHandleOptDialog; private: QAction* m_pcModuleAction; PlaYUVerModuleIf* m_pcModule; - VideoSubWindow* m_pcSubWindow[MAX_NUMBER_FRAMES]; VideoSubWindow* m_pcDisplaySubWindow; @@ -83,8 +83,10 @@ public: PlaYUVerAppModuleIf* m_pcModule; }; - PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ); - virtual ~PlaYUVerAppModuleIf() {} + PlaYUVerAppModuleIf( QObject* parent, QAction* action, PlaYUVerModuleIf* module ); + virtual ~PlaYUVerAppModuleIf() + { + } protected: virtual void run(); diff --git a/lib/ProgramOptions.cpp b/lib/ProgramOptions.cpp index 985859c..233ae41 100644 --- a/lib/ProgramOptions.cpp +++ b/lib/ProgramOptions.cpp @@ -59,7 +59,7 @@ Options::Options( const std::string& name ) Options::~Options() { - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) { delete *it; } @@ -72,12 +72,12 @@ OptionBase* Options::operator[]( const std::string& optName ) OptionBase* Options::getOption( const std::string& optName ) { - Options::NamesMap::iterator opt_it; + Options::OptionMap::iterator opt_it; opt_it = opt_short_map.find( optName ); if( opt_it != opt_short_map.end() ) { - NamesPtrList opt_list = ( *opt_it ).second; - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + OptionsList opt_list = ( *opt_it ).second; + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { return ( *it )->opt; } @@ -85,8 +85,8 @@ OptionBase* Options::getOption( const std::string& optName ) opt_it = opt_long_map.find( optName ); if( opt_it != opt_long_map.end() ) { - NamesPtrList opt_list = ( *opt_it ).second; - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + OptionsList opt_list = ( *opt_it ).second; + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { return ( *it )->opt; } @@ -96,7 +96,7 @@ OptionBase* Options::getOption( const std::string& optName ) void Options::addOption( OptionBase *opt ) { - Names* names = new Names(); + Option* names = new Option(); names->opt = opt; string& opt_string = opt->opt_string; @@ -136,17 +136,17 @@ OptionSpecific Options::addOptions() * default value */ Void Options::setDefaults() { -// for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) +// for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); it++ ) // { // ( *it )->opt->setDefault(); // } } -static void setOptions( Options::NamesPtrList& opt_list, const string& value ) +static void setOptions( Options::OptionsList& opt_list, const string& value ) { /* multiple options may be registered for the same name: * allow each to parse value */ - for( Options::NamesPtrList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) + for( Options::OptionsList::iterator it = opt_list.begin(); it != opt_list.end(); ++it ) { ( *it )->opt->parse( value ); } @@ -158,7 +158,7 @@ static const char spaces[41] = " "; * using the formatting: "-x, --long", * if a short/long option isn't specified, it is not printed */ -static void doHelpOpt( ostream& out, const Options::Names& entry, unsigned pad_short = 0 ) +static void doHelpOpt( ostream& out, const Options::Option& entry, unsigned pad_short = 0 ) { pad_short = min( pad_short, 8u ); @@ -192,7 +192,7 @@ void doHelp( ostream& out, Options& opts, unsigned columns ) const unsigned pad_short = 3; /* first pass: work out the longest option name */ unsigned max_width = 0; - for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) { ostringstream line( ios_base::out ); doHelpOpt( line, **it, pad_short ); @@ -207,7 +207,7 @@ void doHelp( ostream& out, Options& opts, unsigned columns ) * - if the option text is longer than opt_width, place the help * text at opt_width on the next line. */ - for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) + for( Options::OptionsList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) { ostringstream line( ios_base::out ); line << " "; @@ -288,7 +288,7 @@ void doHelp( ostream& out, Options& opts, unsigned columns ) bool storePair( Options& opts, bool allow_long, bool allow_short, const string& name, const string& value ) { bool found = false; - Options::NamesMap::iterator opt_it; + Options::OptionMap::iterator opt_it; if( allow_long ) { opt_it = opts.opt_long_map.find( name ); @@ -310,16 +310,16 @@ bool storePair( Options& opts, bool allow_long, bool allow_short, const string& if( !found ) { - if( !opts.allow_unknow ) - { - /* not found */ - cerr << "Unknown option: `" - << name - << "' (value:`" - << value - << "')" - << endl; - } +// if( !opts.allow_unknow ) +// { +// /* not found */ +// cerr << "Unknown option: `" +// << name +// << "' (value:`" +// << value +// << "')" +// << endl; +// } return false; } @@ -535,7 +535,7 @@ void scanFile( Options& opts, istream& in ) * default value */ void setDefaults( Options& opts ) { -// for( Options::NamesPtrList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) +// for( Options::OptionsList::iterator it = opts.opt_list.begin(); it != opts.opt_list.end(); it++ ) // { // ( *it )->opt->setDefault(); // } diff --git a/lib/ProgramOptions.h b/lib/ProgramOptions.h index f96d588..dc6fd20 100644 --- a/lib/ProgramOptions.h +++ b/lib/ProgramOptions.h @@ -106,7 +106,6 @@ struct OptionBase virtual void parse( const std::string& arg ) = 0; /* set the argument to the default value */ //virtual void setDefault() = 0; - int count() { return arg_count; @@ -143,9 +142,9 @@ struct FlagOpt: public OptionBase /** Type specific option storage */ template -struct Option: public OptionBase +struct StandardOpt: public OptionBase { - Option( const std::string& name, T& storage, const std::string& desc ) : + StandardOpt( const std::string& name, T& storage, const std::string& desc ) : OptionBase( name, desc ), opt_storage( storage ) { @@ -163,7 +162,7 @@ struct Option: public OptionBase /* Generic parsing */ template -inline void Option::parse( const std::string& arg ) +inline void StandardOpt::parse( const std::string& arg ) { std::istringstream arg_ss( arg, std::istringstream::in ); arg_ss.exceptions( std::ios::failbit ); @@ -181,7 +180,7 @@ inline void Option::parse( const std::string& arg ) /* string parsing is specialized -- copy the whole string, not just the * first word */ template<> -inline void Option::parse( const std::string& arg ) +inline void StandardOpt::parse( const std::string& arg ) { opt_storage = arg; arg_count++; @@ -190,7 +189,7 @@ inline void Option::parse( const std::string& arg ) /* string parsing is specialized -- copy the whole string, not just the * first word */ template<> -inline void Option >::parse( const std::string& arg ) +inline void StandardOpt >::parse( const std::string& arg ) { opt_storage.push_back( arg ); arg_count++; @@ -225,22 +224,18 @@ private: }; class OptionSpecific; -struct Options +class Options { - Options( const std::string& name = "" ); - ~Options(); +public: - OptionSpecific addOptions(); - Void setDefaults(); - - struct Names + struct Option { - Names() : + Option() : opt( 0 ) { } ; - ~Names() + ~Option() { if( opt ) delete opt; @@ -249,18 +244,28 @@ struct Options std::list opt_short; OptionBase* opt; }; + typedef std::list OptionsList; + OptionsList opt_list; + + Options( const std::string& name = "" ); + ~Options(); + + OptionSpecific addOptions(); + Void setDefaults(); OptionBase* operator[]( const std::string& optName ); OptionBase* getOption( const std::string& optName ); + OptionsList& getOptionList() + { + return opt_list; + } + void addOption( OptionBase *opt ); - typedef std::list NamesPtrList; - NamesPtrList opt_list; - - typedef std::map NamesMap; - NamesMap opt_long_map; - NamesMap opt_short_map; + typedef std::map OptionMap; + OptionMap opt_long_map; + OptionMap opt_short_map; std::string opt_name; @@ -286,24 +291,10 @@ public: OptionSpecific& operator()( const std::string& name, T& storage, const std::string& desc ) { - parent.addOption( new Option( name, storage, desc ) ); + parent.addOption( new StandardOpt( name, storage, desc ) ); return *this; } -// /** -// * Add option described by name to the parent Options list, -// * with storage for the option's value -// * with default_val as the default value -// * with desc as an optional help description -// */ -// template -// OptionSpecific& -// operator()( const std::string& name, T& storage, const std::string& desc ) -// { -// parent.addOption( new Option( name, storage, desc ) ); -// return *this; -// } - /** * Add option described by name to the parent Options list, * with storage for the option's value