From 360d67c4a327b86355a7627fc166e6ba70c43806 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 21 Mar 2008 13:48:31 +0000 Subject: [PATCH] Merging from QT4 porting. --- src/Qtx/QtxPopupMgr.cxx | 42 ++++++++++++++++++++++++++++++++++++++--- src/Qtx/QtxPopupMgr.h | 6 ++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Qtx/QtxPopupMgr.cxx b/src/Qtx/QtxPopupMgr.cxx index 3efd99ae1..36ecc8011 100644 --- a/src/Qtx/QtxPopupMgr.cxx +++ b/src/Qtx/QtxPopupMgr.cxx @@ -290,6 +290,8 @@ void QtxPopupMgr::setSelection( QtxPopupSelection* sel ) if ( mySelection ) mySelection->setParent( this ); + connect( mySelection, SIGNAL( destroyed( QObject* ) ), + this, SLOT( onSelectionDestroyed( QObject* ) ) ); QtxActionMgr::triggerUpdate(); } @@ -364,6 +366,26 @@ int QtxPopupMgr::insertAction( QAction* a, const int pId, const QString& rule, c return res; } +/*! + \return true if action has rule of given type + \param a - action + \param t - rule type +*/ +bool QtxPopupMgr::hasRule( QAction* a, const RuleType t ) const +{ + return a ? expression( a, t, false ) : false; +} + +/*! + \return true if action with given id has rule of given type + \param id - action id + \param t - rule type +*/ +bool QtxPopupMgr::hasRule( const int id, const RuleType t ) const +{ + return hasRule( action( id ), t ); +} + /*! \brief Get rule of type \a type for the action \a a. \param a action @@ -526,7 +548,7 @@ bool QtxPopupMgr::isSatisfied( QAction* act, const RuleType ruleType ) const */ bool QtxPopupMgr::isVisible( const int id, const int place ) const { - return QtxActionMenuMgr::isVisible( id, place ) && isSatisfied( action( id ) ); + return QtxActionMenuMgr::isVisible( id, place ) && ( !hasRule( id ) || isSatisfied( action( id ) ) ); } /*! @@ -625,6 +647,20 @@ QVariant QtxPopupMgr::parameter( const QString& name, const int idx ) const return val; } +/*! + \brief Called when selection is destroyed. + + Prevents crashes when the selection object is destroyed outside the + popup manager. + + \param o selection object being destroyed +*/ +void QtxPopupMgr::onSelectionDestroyed( QObject* o ) +{ + if ( o == mySelection ) + mySelection = 0; +} + /*! \class QtxPopupSelection \brief This class is a part of the popup menu management system. @@ -721,7 +757,7 @@ QString QtxPopupSelection::equalityParam() const */ QString QtxPopupSelection::selCountParam() const { - QString str = option( "equality" ); + QString str = option( "selcount" ); if ( str.isEmpty() ) str = "selcount"; return str; @@ -735,7 +771,7 @@ QString QtxPopupSelection::selCountParam() const /*! \fn QVariant QtxPopupSelection::parameter( const int idx, const QString& name ) const; - \brief Get number of the selected objects. + \brief Get value of the parameter which is of list type \param idx parameter index \param name parameter name \return parameter value diff --git a/src/Qtx/QtxPopupMgr.h b/src/Qtx/QtxPopupMgr.h index 2dbea1280..5fc946eeb 100644 --- a/src/Qtx/QtxPopupMgr.h +++ b/src/Qtx/QtxPopupMgr.h @@ -66,6 +66,9 @@ public: void setRule( QAction*, const QString&, const RuleType = VisibleRule ); void setRule( const int, const QString&, const RuleType = VisibleRule ); + bool hasRule( QAction*, const RuleType = VisibleRule ) const; + bool hasRule( const int, const RuleType = VisibleRule ) const; + QtxPopupSelection* selection() const; void setSelection( QtxPopupSelection* ); @@ -86,6 +89,9 @@ private: bool result( QtxEvalParser* p ) const; QVariant parameter( const QString&, const int = -1 ) const; +private slots: + void onSelectionDestroyed( QObject* ); + private: typedef QMap ExprMap; typedef QMap RuleMap; -- 2.39.2