QGpGuiTools/PropertyWidget.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpGuiTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2008-04-01
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef PROPERTYWIDGET_H
00029 #define PROPERTYWIDGET_H
00030 
00031 #include "QGpGuiToolsDLLExport.h"
00032 #include "PropertyValue.h"
00033 
00034 namespace QGpGuiTools {
00035 
00036 class PropertyItem;
00037 
00038 class QGPGUITOOLS_EXPORT PropertyWidget : public QWidget
00039 {
00040   Q_OBJECT
00041 public:
00042   PropertyWidget(QWidget * parent=0);
00043   ~PropertyWidget();
00044 
00045   void setValue(int pid, QVariant val);
00046   QVariant value(int pid) {return _list[pid]->value();}
00047   bool constant(int pid) {return _list[pid]->constant();}
00048   PropertyValue * propertyValue(int pid) {return _list[pid];}
00049   int propertyCount() const {return _list.count();}
00050 
00051   virtual void setWidgets();
00052   virtual void reset();
00053 
00054   void setId(uint wid) {_wid=wid;}
00055   uint id() const {return _wid;}
00056 
00057   void linkTo(PropertyWidget * w);
00058 
00059   void touched(PropertyValue * p, QVariant val);
00060 private slots:
00061   void touched(PropertyValue * p) {touched(p, widgetValue( *p) );}
00062 signals:
00063   void setProperty(int id, QVariant val);
00064   void refreshValues();
00065   void touched();
00066 protected:
00067   PropertyValue * addProperty(int pid, QWidget * w, QWidget * label);
00068   PropertyValue * addProperty(int pid, QWidget * w=0) {return addProperty(pid, w, w);}
00069 
00070   virtual int determineCustomWidgetType(int /* pid */, QWidget * /* w */, QWidget * /* label */ ) {return 0;}
00071   virtual bool connectCustomWidget(PropertyValue & /* p */ ) {return false;}
00072   virtual bool setCustomWidget(PropertyValue & /* p */ )  {return false;}
00073   virtual QVariant customWidgetValue(PropertyValue & /* p */ ) {return QVariant();}
00074 private:
00075   inline int determineWidgetType(int pid, QWidget * w, QWidget * label);
00076   inline void connectWidget(PropertyValue & p);
00077   void setWidget(PropertyValue & p);
00078   QVariant widgetValue(PropertyValue & p);
00079 
00080   QHash<int, PropertyValue *> _list;
00081   uint _wid;
00082 };
00083 
00084 } // namespace QGpGuiTools
00085 
00086 #endif // PROPERTYWIDGET_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines