Back to index

salome-gui  6.5.0
QtxPopupMgr.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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   friend class QtxPopupSelection;
00110 };
00111 
00112 class QTX_EXPORT QtxPopupSelection : public QObject
00113 {
00114   Q_OBJECT
00115 
00116 public:
00117   QtxPopupSelection();
00118   virtual ~QtxPopupSelection();
00119 
00120   virtual int        count() const = 0;
00121   virtual QVariant   parameter( const QString& ) const;
00122   virtual QVariant   parameter( const int, const QString& ) const = 0;
00123 
00124   QString            option( const QString& ) const;
00125   void               setOption( const QString&, const QString& );
00126 
00127   QtxPopupMgr*       popupMgr() const;
00128   void               setPopupMgr( QtxPopupMgr* );
00129 
00130 private:
00131   QString            equalityParam() const;
00132   QString            selCountParam() const;
00133 
00134 private:
00135   typedef QMap<QString, QString> OptionsMap;
00136   typedef QPointer<QtxPopupMgr>  PopupMgrPtr;
00137 
00138 private:
00139   OptionsMap         myOptions;
00140   PopupMgrPtr        myPopupMgr;
00141 };
00142 
00143 #endif // QTXPOPUPMGR_H