#include <qpopupmenu.h>
#include <qdatetime.h>
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+
+/*!
+ \return value of global parameter (depending on whole selection, but not dependending on one object of selection)
+ \param str - name of parameter
+
+ By default, it returns count of selected objects ("selcount") and list of parameters ("$<name>")
+*/
QtxValue QtxPopupMgr::Selection::globalParam( const QString& str ) const
{
if( str==selCountParam() )
return QtxValue();
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return symbole to detect name of parameter list
+*/
QChar QtxPopupMgr::Selection::equality() const
{
return defEquality();
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return name of parameter for count of selected objects
+*/
QString QtxPopupMgr::Selection::selCountParam() const
{
return defSelCountParam();
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return default symbole to detect name of parameter list
+*/
QChar QtxPopupMgr::Selection::defEquality()
{
return '$';
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return default name of parameter for count of selected objects
+*/
QString QtxPopupMgr::Selection::defSelCountParam()
{
return "selcount";
+/*!
+ \class QtxCacheSelection
+ Special selection class, that caches parameter values.
+ Every parameter during popup building is calculated only one time,
+ although it may be included to many rules. After calculation
+ it is stored in internal map
+*/
-//================================================================
-// Class :
-// Purpose :
-//================================================================
class QtxCacheSelection : public QtxPopupMgr::Selection
{
public:
CacheMap myParamCache;
};
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Constructor
+ \param sel - base selection used for parameter calculation
+*/
QtxCacheSelection::QtxCacheSelection( QtxPopupMgr::Selection* sel )
: mySel( sel )
{
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Destructor
+*/
QtxCacheSelection::~QtxCacheSelection()
{
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return count of selected objects
+*/
int QtxCacheSelection::count() const
{
return mySel ? mySel->count() : 0;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Calculates and caches parameters.
+ Already calculated parameters are returned without calculation
+ \return parameter value
+ \param i - index of selected object
+ \param name - name of parameter
+*/
QtxValue QtxCacheSelection::param( const int i, const QString& name ) const
{
QString param_name = name + "#####" + QString::number( i );
}
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Calculates and caches global parameters.
+ Already calculated parameters are returned without calculation
+ \return parameter value
+ \param name - name of parameter
+*/
QtxValue QtxCacheSelection::globalParam( const QString& name ) const
{
if( myParamCache.contains( name ) )
-
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Constructor
+ \param mgr - popup manager
+*/
QtxPopupMgr::Operations::Operations( QtxPopupMgr* mgr )
: QtxStrings(),
myPopupMgr( mgr )
myParser = new QtxParser( mgr->myOperations );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Destructor
+ Deletes internal parser
+*/
QtxPopupMgr::Operations::~Operations()
{
delete myParser;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return priority of popup operation 'op'.
+ \param isBin indicate whether the operation is binary
+*/
int QtxPopupMgr::Operations::prior( const QString& op, bool isBin ) const
{
if( !isBin && ( op=="every" || op=="any" || op=="onlyone" ) )
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Calculates result of operation
+ \return one of error states
+ \param op - name of operation
+ \param v1 - first operation argument (must be used also to store result)
+ \param v2 - second operation argument
+*/
QtxParser::Error QtxPopupMgr::Operations::calculate
( const QString& op, QtxValue& v1, QtxValue& v2 ) const
{
return QtxStrings::calculate( op, v1, v2 );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Clears internal map of values
+*/
void QtxPopupMgr::Operations::clear()
{
myValues.clear();
-
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Constructor
+*/
QtxPopupMgr::QtxPopupMgr( QPopupMenu* popup, QObject* parent )
: QtxActionMenuMgr( popup, parent ),
myCurrentSelection( 0 )
createOperations();
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Destructor
+*/
QtxPopupMgr::~QtxPopupMgr()
{
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Creates popup operations instance
+*/
void QtxPopupMgr::createOperations()
{
myOperations = new QtxListOfOperations;
myOperations->append( "custom", new Operations( this ), 200 );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Additional version of registerAction
+ \param act - action to be registered
+ \param visible - rule for visibility state
+ \param toggle - rule for toggle on state
+ \param id - proposed id (if it is less than 0, then id will be generated automatically)
+*/
int QtxPopupMgr::registerAction( QAction* act,
const QString& visible,
const QString& toggle,
return _id;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Removes action from internal map
+ \param id - action id
+*/
void QtxPopupMgr::unRegisterAction( const int id )
{
QAction* act = action( id );
//QtxActionMenuMgr::unRegisterAction( id );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return true if manager has rule for action
+ \param act - action
+ \param visibility - if it is true, then rule for "visibility" is checked, otherwise - for "toggle"
+*/
bool QtxPopupMgr::hasRule( QAction* act, bool visibility ) const
{
return map( visibility ).contains( act );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return true if manager has rule for action
+ \param id - action id
+ \param visibility - if it is true, then rule for "visibility" is checked, otherwise - for "toggle"
+*/
bool QtxPopupMgr::hasRule( const int id, bool visibility ) const
{
return hasRule( action( id ), visibility );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Sets new rule for action
+ \param act - action
+ \param rule - string expression of rule
+ \param visibility - if it is true, then rule for "visibility" will be set, otherwise - for "toggle"
+*/
void QtxPopupMgr::setRule( QAction* act, const QString& rule, bool visibility )
{
if( !act || rule.isEmpty() )
}
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Sets new rule for action
+ \param id - action id
+ \param rule - string expression of rule
+ \param visibility - if it is true, then rule for "visibility" will be set, otherwise - for "toggle"
+*/
void QtxPopupMgr::setRule( const int id, const QString& rule, bool visibility )
{
setRule( action( id ), rule, visibility );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return true if parser has finished work without errors
+ \param p - parser
+*/
bool result( QtxParser* p )
{
bool res = false;
return res;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Fills parser parameters with help of Selection::globalParam() method
+ \param p - parser
+ \param specific - list will be filled with names of parameters depending on selection objects (not global)
+*/
void QtxPopupMgr::setParams( QtxParser* p, QStringList& specific ) const
{
if( !p || !myCurrentSelection )
}
}
+/*!
+ \return true if 'v1'<'v2'
+ This function can work with many types of values
+*/
bool operator<( const QtxValue& v1, const QtxValue& v2 )
{
QVariant::Type t1 = v1.type(), t2 = v2.type();
return t1<t2;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return true if rule of action is satisfied on current selection
+ \param act - action
+ \param visibility - what rule is checked: for visibility(true) or for toggle(false)
+*/
bool QtxPopupMgr::isSatisfied( QAction* act, bool visibility ) const
{
QString menu = act->menuText();
return res;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return true if item corresponding to action is visible
+ \param actId - action id
+ \param place - index of place
+*/
bool QtxPopupMgr::isVisible( const int actId, const int place ) const
{
bool res = QtxActionMenuMgr::isVisible( actId, place );
return res;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Updates popup according to selection
+ \param p - popup menu
+ \param sel - selection
+*/
void QtxPopupMgr::updatePopup( QPopupMenu* p, Selection* sel )
{
QTime t1 = QTime::currentTime();
delete myCurrentSelection;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return reference to map of rules
+ \param visibility - type of map: visibility of toggle
+*/
QtxPopupMgr::RulesMap& QtxPopupMgr::map( bool visibility ) const
{
return ( RulesMap& )( visibility ? myVisibility : myToggle );
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Loads actions description from file
+ \param fname - name of file
+ \param r - reader of file
+ \return true on success
+*/
bool QtxPopupMgr::load( const QString& fname, QtxActionMgr::Reader& r )
{
PopupCreator cr( &r, this );
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ Constructor
+ \param r - menu reader
+ \param mgr - menu manager
+*/
QtxPopupMgr::PopupCreator::PopupCreator( QtxActionMgr::Reader* r,
QtxPopupMgr* mgr )
: QtxActionMgr::Creator( r ),
{
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
-QtxPopupMgr::PopupCreator::~PopupCreator()
+/*!
+ Destructor
+*/QtxPopupMgr::PopupCreator::~PopupCreator()
{
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+
+/*!
+ Appends new menu items
+ \param tag - tag of item
+ \param subMenu - it has submenu
+ \param attr - list of attributes
+ \param pId - id of action corresponding to parent item
+*/
int QtxPopupMgr::PopupCreator::append( const QString& tag, const bool subMenu,
const ItemAttributes& attr, const int pId )
{
return res;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return visibility rule by attributes
+ Default implementation is empty
+*/
QString QtxPopupMgr::PopupCreator::visibleRule( const ItemAttributes& ) const
{
return QString::null;
}
-//================================================================
-// Function :
-// Purpose :
-//================================================================
+/*!
+ \return toggle rule by attributes
+ Default implementation is empty
+*/
QString QtxPopupMgr::PopupCreator::toggleRule( const ItemAttributes& ) const
{
return QString::null;