Version: 6.3.1

src/Qtx/QtxPopupMgr.h

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      QtxPopupMgr.h
00024 // Author:    Alexander SOLOVYOV, Sergey TELKOV
00025 //
00026 #ifndef QTXPOPUPMGR_H
00027 #define QTXPOPUPMGR_H
00028 
00029 #include "QtxActionMenuMgr.h"
00030 
00031 #include <QMap>
00032 #include <QVariant>
00033 
00034 class QtxEvalExpr;
00035 class QtxEvalParser;
00036 class QtxPopupSelection;
00037 
00038 class QTX_EXPORT QtxPopupMgr : public QtxActionMenuMgr
00039 {
00040   Q_OBJECT
00041 
00042 public:
00044   typedef enum { 
00045     VisibleRule,   
00046     EnableRule,    
00047     ToggleRule     
00048   } RuleType;
00049 
00050 private:
00051   class PopupCreator;
00052 
00053 public:
00054   QtxPopupMgr( QObject* = 0 );
00055   QtxPopupMgr( QMenu*, QObject* = 0 );
00056   virtual ~QtxPopupMgr();
00057 
00058   int                insertAction( const int, const int, const QString&, const RuleType = VisibleRule );
00059   int                insertAction( QAction*, const int, const QString&, const RuleType = VisibleRule );
00060 
00061   virtual int        registerAction( QAction*, const int, const QString& rule,
00062                                      const RuleType = VisibleRule );
00063   virtual void       unRegisterAction( const int );
00064 
00065   virtual bool       isVisible( const int actId, const int place ) const;
00066 
00067   QString            rule( QAction*, const RuleType = VisibleRule ) const;
00068   QString            rule( const int, const RuleType = VisibleRule ) const;
00069 
00070   void               setRule( QAction*, const QString&, const RuleType = VisibleRule );
00071   void               setRule( const int, const QString&, const RuleType = VisibleRule );
00072 
00073   bool               hasRule( QAction*, const RuleType = VisibleRule ) const;
00074   bool               hasRule( const int, const RuleType = VisibleRule ) const;
00075 
00076   QtxPopupSelection* selection() const;
00077   void               setSelection( QtxPopupSelection* );
00078 
00079   QMenu*             menu() const;
00080   void               setMenu( QMenu* );
00081 
00082   void               updateMenu();
00083 
00084   virtual bool       load( const QString&, QtxActionMgr::Reader& );
00085 
00086 protected:
00087   virtual void       internalUpdate();
00088   void               setParameters( QtxEvalParser*, QStringList& ) const;
00089   virtual bool       isSatisfied( QAction*, const RuleType = VisibleRule ) const;
00090   QtxEvalExpr*       expression( QAction*, const RuleType = VisibleRule, const bool = false ) const;
00091 
00092 private:
00093   bool               result( QtxEvalParser* p ) const;
00094   QVariant           parameter( const QString&, const int = -1 ) const;
00095 
00096 private slots:
00097   void               onSelectionDestroyed( QObject* );
00098 
00099 private:
00100   typedef QMap<RuleType, QtxEvalExpr*> ExprMap;
00101   typedef QMap<QAction*, ExprMap>      RuleMap;
00102   typedef QMap<QString, QVariant>      CacheMap;
00103 
00104 private:
00105   RuleMap            myRules;
00106   CacheMap           myCache;
00107   QtxPopupSelection* mySelection;
00108 };
00109 
00110 class QTX_EXPORT QtxPopupSelection : public QObject
00111 {
00112   Q_OBJECT
00113 
00114 public:
00115   QtxPopupSelection();
00116   virtual ~QtxPopupSelection();
00117 
00118   virtual int        count() const = 0;
00119   virtual QVariant   parameter( const QString& ) const;
00120   virtual QVariant   parameter( const int, const QString& ) const = 0;
00121 
00122   QString            option( const QString& ) const;
00123   void               setOption( const QString&, const QString& );
00124 
00125 private:
00126   QString            equalityParam() const;
00127   QString            selCountParam() const;
00128 
00129 private:
00130   typedef QMap<QString, QString> OptionsMap;
00131 
00132 private:
00133   OptionsMap         myOptions;
00134 };
00135 
00136 #endif // QTXPOPUPMGR_H
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS