Back to index

salome-gui  6.5.0
QtxActionMgr.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:      QtxActionMgr.h
00024 // Author:    Alexander SOLOVYOV, Sergey TELKOV
00025 //
00026 #ifndef QTXACTIONMGR_H
00027 #define QTXACTIONMGR_H
00028 
00029 #include "Qtx.h"
00030 
00031 #include <QMap>
00032 #include <QObject>
00033 #include <QPointer>
00034 
00035 class QTimer;
00036 class QAction;
00037 class QDomNode;
00038 
00039 #ifdef WIN32
00040 #pragma warning( disable:4251 )
00041 #endif
00042 
00043 
00044 class QTX_EXPORT QtxActionMgr : public QObject
00045 {
00046   Q_OBJECT 
00047 
00048   class SeparatorAction;
00049 
00050 public:
00051   class Reader;
00052   class XMLReader;
00053 
00054 protected:
00055   class Creator;
00056 
00057 public:
00058   QtxActionMgr( QObject* parent );
00059   virtual ~QtxActionMgr();
00060 
00061   virtual int      registerAction( QAction*, const int = -1 );
00062   virtual void     unRegisterAction( const int );
00063 
00064   QAction*         action( const int ) const;
00065   int              actionId( const QAction* ) const;
00066   bool             contains( const int ) const;
00067 
00068   int              count() const;
00069   bool             isEmpty() const;
00070   QIntList         idList() const;
00071 
00072   bool             isUpdatesEnabled() const;
00073   virtual void     setUpdatesEnabled( const bool );
00074 
00075   virtual bool     isVisible( const int, const int ) const;
00076   virtual void     setVisible( const int, const int, const bool );
00077 
00078   void             update();
00079 
00080   virtual bool     isEnabled( const int ) const;
00081   virtual void     setEnabled( const int, const bool );
00082 
00083   static QAction*  separator( const bool = false );
00084 
00085 protected:
00086   virtual void     internalUpdate();
00087   int              generateId() const;
00088 
00089   void             triggerUpdate();
00090   virtual void     updateContent();
00091 
00092 private slots:
00093   void             onUpdateContent();
00094 
00095 private:
00096   typedef QPointer<QAction>    ActionPtr; 
00097   typedef QMap<int, ActionPtr> ActionMap; 
00098 
00099 private:
00100   bool             myUpdate;     
00101   ActionMap        myActions;    
00102   QTimer*          myUpdTimer;   
00103 };
00104 
00105 
00106 QTX_EXPORT typedef QMap<QString, QString> ItemAttributes; 
00107 
00108 class QTX_EXPORT QtxActionMgr::Creator
00109 {
00110 public:
00111   Creator( QtxActionMgr::Reader* );
00112   virtual ~Creator();
00113 
00114   Reader* reader() const;
00115 
00116   virtual int    append( const QString&, const bool,
00117                          const ItemAttributes&, const int ) = 0;
00118   virtual void   connect( QAction* ) const;
00119 
00120   virtual bool   loadPixmap( const QString&, QPixmap& ) const;
00121 
00122 protected:
00123   static int     intValue( const ItemAttributes&, const QString&, const int );
00124   static QString strValue( const ItemAttributes&, const QString&,
00125                            const QString& = QString() );
00126 private:
00127   QtxActionMgr::Reader*  myReader;  
00128 };
00129 
00130 class QTX_EXPORT QtxActionMgr::Reader
00131 {
00132 public:
00133   Reader();
00134   virtual ~Reader();
00135 
00136   QStringList    options() const;
00137   QString        option( const QString&, const QString& = QString() ) const;
00138   void           setOption( const QString&, const QString& );
00139 
00140   virtual bool   read( const QString&, Creator& ) const = 0;
00141 
00142 private:
00143   QMap< QString, QString > myOptions;  
00144 };
00145 
00146 class QTX_EXPORT QtxActionMgr::XMLReader : public Reader
00147 {
00148 public:
00149   XMLReader( const QString&, const QString&, const QString& );
00150   virtual ~XMLReader();
00151 
00152   virtual bool   read( const QString&, Creator& ) const;
00153 
00154 protected:
00155   virtual void   read( const QDomNode&, const int, Creator& ) const;
00156   virtual bool   isNodeSimilar( const QDomNode&, const QString& ) const;
00157 };
00158 
00159 
00160 #endif