From 908cbe15597885f6c2c81deeb15f79011e6b5cd0 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 10 Feb 2006 09:40:06 +0000 Subject: [PATCH] Support for correct caclculation rules which includes selection parameters without current selection. --- src/Qtx/QtxListOfOperations.cxx | 5 +- src/Qtx/QtxParser.cxx | 6 +-- src/Qtx/QtxPopupMgr.cxx | 87 +++++++++++++++++++++------------ src/Qtx/QtxPopupMgr.h | 1 + src/Qtx/QtxStdOperations.cxx | 15 +++++- src/Qtx/QtxStdOperations.h | 4 ++ 6 files changed, 79 insertions(+), 39 deletions(-) diff --git a/src/Qtx/QtxListOfOperations.cxx b/src/Qtx/QtxListOfOperations.cxx index 1be04a75d..0a4393b62 100644 --- a/src/Qtx/QtxListOfOperations.cxx +++ b/src/Qtx/QtxListOfOperations.cxx @@ -159,9 +159,8 @@ QtxParser::Error QtxListOfOperations::calculate( const QString& op, QtxParser::Error err = (*anIt).myOperations->calculate( op, nv1, nv2 ); if( err==QtxParser::OK || err==QtxParser::InvalidResult ) { - QString oop = (*anIt).myName; - const char* ooo = oop.latin1(); - v1 = nv1; v2 = nv2; + v1 = nv1; + v2 = nv2; return err; } } diff --git a/src/Qtx/QtxParser.cxx b/src/Qtx/QtxParser.cxx index 105ddb7a5..b2f7c72ac 100644 --- a/src/Qtx/QtxParser.cxx +++ b/src/Qtx/QtxParser.cxx @@ -552,10 +552,10 @@ QtxValue QtxParser::calculate() if( has( nn ) ) { QVariant& v = myParameters[ nn ]; - if( v.isValid() ) + //if( v.isValid() ) aStack.push( v ); - else - setLastError( InvalidToken ); + //else + // setLastError( InvalidToken ); } else setLastError( InvalidToken ); diff --git a/src/Qtx/QtxPopupMgr.cxx b/src/Qtx/QtxPopupMgr.cxx index f01716c16..b19a54cab 100644 --- a/src/Qtx/QtxPopupMgr.cxx +++ b/src/Qtx/QtxPopupMgr.cxx @@ -521,46 +521,53 @@ bool QtxPopupMgr::isSatisfied( QAction* act, bool visibility ) const QString menu = act->menuText(); bool res = false; - if( !act ) + if ( !act ) return res; - if( hasRule( act, visibility ) ) + if ( hasRule( act, visibility ) ) { QtxParser* p = map( visibility )[ act ]; QStringList specific; p->clear(); - ( ( Operations* )myOperations->operations( "custom" ) )->clear(); + ((Operations*)myOperations->operations( "custom" ))->clear(); setParams( p, specific ); QMap,int> aCorteges; QValueList c; - if( specific.count()>0 ) - if( myCurrentSelection ) + if ( specific.count() ) + { + if ( myCurrentSelection ) { - res = false; - - for( int i=0, n=myCurrentSelection->count(); iparam( i, *anIt1 ) ); - aCorteges.insert( c, 0 ); - } + res = false; + if ( myCurrentSelection->count() ) + { + for( int i = 0, n = myCurrentSelection->count(); i < n && !res; i++ ) + { + c.clear(); + for ( QStringList::const_iterator anIt1 = specific.begin(); anIt1 != specific.end(); anIt1++ ) + c.append( myCurrentSelection->param( i, *anIt1 ) ); + aCorteges.insert( c, 0 ); + } + } + else + { + for ( QStringList::const_iterator anIt1 = specific.begin(); anIt1 != specific.end(); anIt1++ ) + c.append( QtxValue() ); + aCorteges.insert( c, 0 ); + } - //qDebug( QString( "%1 corteges" ).arg( aCorteges.count() ) ); - QMap,int>::const_iterator anIt = aCorteges.begin(), aLast = aCorteges.end(); - for( ; anIt!=aLast; anIt++ ) - { - QStringList::const_iterator anIt1 = specific.begin(), aLast1 = specific.end(); - const QValueList& aCortege = anIt.key(); - QValueList::const_iterator anIt2 = aCortege.begin(); - for( ; anIt1!=aLast1; anIt1++, anIt2++ ) - p->set( *anIt1, *anIt2 ); - res = res || result( p ); - } + //qDebug( QString( "%1 corteges" ).arg( aCorteges.count() ) ); + for ( QMap,int>::const_iterator anIt = aCorteges.begin(); anIt != aCorteges.end(); anIt++ ) + { + QStringList::const_iterator anIt1 = specific.begin(), aLast1 = specific.end(); + const QValueList& aCortege = anIt.key(); + QValueList::const_iterator anIt2 = aCortege.begin(); + for ( ; anIt1 != aLast1; anIt1++, anIt2++ ) + p->set( *anIt1, *anIt2 ); + res = res || result( p ); + } /* for( int i=0, n=myCurrentSelection->count(); iisToggleAction() && hasRule( anIt.key(), false ) ) + setSelection( sel ); + + for ( RulesMap::iterator anIt = myToggle.begin(); anIt != myToggle.end(); anIt++ ) + { + if ( anIt.key()->isToggleAction() && hasRule( anIt.key(), false ) ) anIt.key()->setOn( isSatisfied( anIt.key(), false ) ); + } setWidget( ( QWidget* )p ); + updateMenu(); + QTime t2 = QTime::currentTime(); qDebug( QString( "update popup time = %1 msecs" ).arg( t1.msecsTo( t2 ) ) ); qDebug( QString( "number of objects = %1" ).arg( myCurrentSelection->count() ) ); + setSelection( 0 ); +} + +void QtxPopupMgr::setSelection( Selection* s ) +{ + if ( myCurrentSelection == s ) + return; + delete myCurrentSelection; + myCurrentSelection = 0; + + if ( s ) + myCurrentSelection = new QtxCacheSelection( s ); } //================================================================ diff --git a/src/Qtx/QtxPopupMgr.h b/src/Qtx/QtxPopupMgr.h index a75a7dced..7c6e86024 100644 --- a/src/Qtx/QtxPopupMgr.h +++ b/src/Qtx/QtxPopupMgr.h @@ -102,6 +102,7 @@ protected: typedef QMap< QAction*, QtxParser* > RulesMap; protected: + void setSelection( Selection* ); virtual bool isSatisfied( QAction*, bool visibility ) const; void setParams( QtxParser*, QStringList& ) const; RulesMap& map( bool visibility ) const; diff --git a/src/Qtx/QtxStdOperations.cxx b/src/Qtx/QtxStdOperations.cxx index 6d612b299..64339b855 100644 --- a/src/Qtx/QtxStdOperations.cxx +++ b/src/Qtx/QtxStdOperations.cxx @@ -544,6 +544,13 @@ QtxStrings::~QtxStrings() { } +QtxParser::Error QtxStrings::isValid( const QString& name, + const QVariant::Type t1, + const QVariant::Type t2 ) const +{ + return name == "=" ? QtxParser::OK : QtxStdOperations::isValid( name, t1, t2 ); +} + //================================================================ // Function : // Purpose : @@ -609,8 +616,10 @@ QtxParser::Error QtxStrings::calculate( const QString& op, else if( op==">=" ) set( v1, _v1>_v2 || _v1==_v2 ); } - else if( !v1.isValid() && v2.isValid() ) + else { + if( !v1.isValid() && v2.isValid() ) + { QString val = v2.toString(); if( op=="length" ) v2 = ( int )val.length(); @@ -618,8 +627,12 @@ QtxParser::Error QtxStrings::calculate( const QString& op, v2 = val.lower(); else if( op=="upper" ) v2 = val.upper(); + } + if ( op=="=" ) + set( v1, false ); } + return err; } diff --git a/src/Qtx/QtxStdOperations.h b/src/Qtx/QtxStdOperations.h index 5a8cfd48e..99d9a5557 100644 --- a/src/Qtx/QtxStdOperations.h +++ b/src/Qtx/QtxStdOperations.h @@ -107,6 +107,10 @@ public: QtxStrings(); virtual ~QtxStrings(); + virtual QtxParser::Error isValid( const QString&, + const QVariant::Type, + const QVariant::Type ) const; + virtual bool createValue( const QString&, QtxValue& ) const; virtual int prior( const QString&, bool isBin ) const; virtual QtxParser::Error calculate( const QString&, QtxValue&, QtxValue& ) const; -- 2.39.2