SciFigs/GraphContentLayer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of SciFigs.
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 : 2003-02-17
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef GRAPHCONTENTLAYER_H
00030 #define GRAPHCONTENTLAYER_H
00031 
00032 #include <QtGui>
00033 #include <QGpGuiTools.h>
00034 #include "SciFigsDLLExport.h"
00035 
00036 namespace SciFigs {
00037 
00038 class GraphContent;
00039 class AxisWindow;
00040 class GraphContentProperties;
00041 class LayerMouseTracking;
00042 class LayerPainterRequest;
00043 class GraphContentOptions;
00044 
00045 //#define GRAPHCONTENTLAYER_TESTING
00046 
00047 class SCIFIGS_EXPORT GraphContentLayer :  public QObject, public PropertyItem, public XMLClass
00048 {
00049   Q_OBJECT
00050   // Overload to mark the beginning of properties to save to XML
00051   Q_PROPERTY(QString objectName READ objectName WRITE setObjectName STORED true)
00052   // Kept only to avoid warning on loading old files
00053   Q_PROPERTY(QString name READ dummyPropertyString WRITE setObjectName STORED false)
00054 
00055   Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity STORED true)
00056   DUMMY_PROPERTIES;
00057 public:
00058   GraphContentLayer(AxisWindow * parent=0);
00059 
00060   virtual const QString& xml_tagName() const {return xmlGraphContentLayerTag;}
00061   static const QString xmlGraphContentLayerTag;
00062 
00063   void lock() {_mutex.lock();}
00064   void lockDelayPainting();
00065   void unlock() {_mutex.unlock();}
00066 
00067   virtual void setParent(GraphContent * parent);
00068   // Returns the graphcontent parent
00069   GraphContent * graphContent() {return reinterpret_cast<GraphContent *>(parent());}
00070   const GraphContent * graphContent() const {return reinterpret_cast<const GraphContent *>(parent());}
00071   // Returns the axiswindow parent
00072   AxisWindow * graph() const {return reinterpret_cast<AxisWindow *>(parent()->parent());}
00073 
00074   // From user changes, update the properties
00075   virtual bool mousePressEvent (QMouseEvent * e, int id=-1) {Q_UNUSED(e); Q_UNUSED(id); return true;}
00076   virtual bool mouseReleaseEvent (QMouseEvent * e, int id=-1) {Q_UNUSED(e); Q_UNUSED(id); return true;}
00077   virtual void mouseMoveEvent (const QPoint& pt, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) {
00078     Q_UNUSED(pt);
00079     Q_UNUSED(buttons);
00080     Q_UNUSED(modifiers);
00081   }
00082   virtual bool wheelEvent(QWheelEvent * e) {Q_UNUSED(e); return true;}
00083   virtual bool keyPressEvent(QKeyEvent* e) {Q_UNUSED(e); return true;}
00084   virtual bool keyReleaseEvent(QKeyEvent* e) {Q_UNUSED(e); return true;}
00085   virtual inline bool trackRectangle(int id, double rx1,double ry1, double rx2, double ry2, Qt::KeyboardModifiers m);
00086   void paint(const LayerPainterRequest& lp, QPainter& p, double dotpercm);
00087   virtual inline void paintText(const LayerPainterRequest& lp, double dotpercm);
00088   virtual Rect boundingRect() const=0;
00089   virtual QString coordinateTipInfo(const Point2D& p) const;
00090 
00091   void setOpacity(qreal o);
00092   qreal opacity() const {return _opacity;}
00093 
00094   void addReference() {_referenceCount++;}
00095   void removeReference() {_referenceCount--; ASSERT(_referenceCount>=0);}
00096   bool isRemovable() const {return _referenceCount==0;}
00097 
00098   void setEditable(bool r) {_isEditable=r;}
00099   bool isEditable() const {return _isEditable;}
00100 
00101   void setSelected(bool s) {_isSelected=s;}
00102   bool isSelected() const {return _isSelected;}
00103 
00104   QAction * addTrackingAction(QString text, int id=0, QString statusTip=QString::null);
00105   void setTrackingAction(int id, bool checked);
00106   static QString trackingActionCtrlHelp();
00107 
00108   virtual bool hasProperties() {return false;}
00109   virtual void addProperties(PropertyProxy * /* pp */ ) {}
00110   virtual void removeProperties(PropertyProxy * /* pp */ ) {}
00111   virtual void properties(PropertyWidget * /* w */ ) const {}
00112   virtual void setProperty(uint /* wid */, int /* pid */, QVariant /* val */ ) {}
00113 
00114   virtual void xml_layerPolish(XML_POLISH_ARGS) {Q_UNUSED(context);}
00115 public slots:
00116   Q_SCRIPTABLE void deepUpdate();
00117   virtual void toggleTrackingAction(bool checked, int id=-1);
00118 signals:
00119   void dataPainted(QPainter& p, double dotpercm, int w, int h) const;
00120 protected:
00121   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00122   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00123   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS) {return qobject_setProperty(this, memberID, tag, attributes, content, context);}
00124 #ifdef GRAPHCONTENTLAYER_TESTING
00125   virtual void paintData(const LayerPainterRequest& lp, QPainter& p, double dotpercm) const;
00126 #else
00127   virtual void paintData(const LayerPainterRequest& lp, QPainter& p, double dotpercm) const=0;
00128 #endif
00129   void beginMouseTracking(const LayerMouseTracking& mt);
00130   void endMouseTracking(int id=0);
00131   bool isMouseTracking(int id=0);
00132 
00133   // visible flag replace by more general "opacity": 0=invisible, 1=opaque
00134   qreal _opacity;
00135   int _referenceCount;
00136   uint _isEditable:1;
00137   uint _isSelected:1;
00138 
00139   // Avoid a layer to be painted at the same time by two distinct threads
00140   mutable QMutex _mutex;
00141 };
00142 
00143 inline bool GraphContentLayer::trackRectangle(int id, double rx1,double ry1, double rx2, double ry2, Qt::KeyboardModifiers m)
00144 {
00145   TRACE;
00146   Q_UNUSED(id);
00147   Q_UNUSED(rx1);
00148   Q_UNUSED(ry1);
00149   Q_UNUSED(rx2);
00150   Q_UNUSED(ry2);
00151   Q_UNUSED(m);
00152   return false;
00153 }
00154 
00155 inline void GraphContentLayer::paintText(const LayerPainterRequest& lp, double dotpercm)
00156 {
00157   TRACE;
00158   Q_UNUSED(lp);
00159   Q_UNUSED(dotpercm);
00160 }
00161 
00162 } // namespace SciFigs
00163 
00164 #endif // GRAPHCONTENTLAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines