SciFigs/LineLayer.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 : 2007-05-30
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef LINELAYER_H
00029 #define LINELAYER_H
00030 
00031 #include "GraphContentLayer.h"
00032 #include "SciFigsDLLExport.h"
00033 #include "LineEditor.h"
00034 #include "AbstractLine.h"
00035 #include "Legend.h"
00036 
00037 namespace SciFigs {
00038 
00039 class LineProperties;
00040 class XMLSciFigs;
00041 
00042 class SCIFIGS_EXPORT LineLayer : public GraphContentLayer
00043 {
00044   Q_OBJECT
00045   // Compatibility
00046   Q_PROPERTY(bool logErrorBars READ dummyPropertyInt WRITE setLogErrorBar SCRIPTABLE true)
00047 
00048   Q_PROPERTY(QString errorBar READ errorBarString WRITE setErrorBar SCRIPTABLE true)
00049 public:
00050   LineLayer(AxisWindow * parent=0);
00051   ~LineLayer();
00052 
00053   virtual const QString& xml_tagName() const {return xmlLineLayerTag;}
00054   static const QString xmlLineLayerTag;
00055 
00056   void setReferenceLine (AbstractLine * l);
00057   void setReferencePen(const Pen& p);
00058   void setReferenceSymbol(const Symbol& s);
00059 
00060   void clear();
00061   void removeLine(int i);
00062   void removeLine(AbstractLine * l);
00063   void removeEmptyLines();
00064 
00065   AbstractLine * addLine();
00066   AbstractLine * addLine(const Pen& pen, const Symbol& sym);
00067 
00068   AbstractLine * line(int i) {return _lines.at(i);}
00069   const AbstractLine * line(int i) const {return _lines.at(i);}
00070   QList<AbstractLine *> lines() const;
00071 
00072   void setVisible(int i, bool v);
00073   void setSelected(int i, bool s);
00074   virtual Legend legend() const;
00075 
00076   // Return the number of curves
00077   int count() const {return _lines.count();}
00078   virtual bool trackRectangle(int, double rx1, double ry1, double rx2, double ry2, Qt::KeyboardModifiers m);
00079   // Calculate the rectangle that includes all the curves
00080   virtual Rect boundingRect() const;
00081   virtual void paintData(const LayerPainterRequest& lp, QPainter& p, double dotpercm) const;
00082 
00083   void mulYbyX(double constant);
00084   void divYbyX(double constant);
00085 
00086   enum ErrorBar {NoBar, VerticalBar, HorizontalBar, VerticalLogBar, HorizontalLogBar};
00087   void setLogErrorBar(bool b) {_errorBar=b ? VerticalLogBar : VerticalBar;} // Compatibility
00088   void setErrorBar(ErrorBar b) {_errorBar=b;}
00089   ErrorBar errorBar() const {return _errorBar;}
00090   void setErrorBar(QString b);
00091   QString errorBarString() const;
00092 
00093   void setPointOptions(CurvePointOptions * o) {_pointOptions=o;}
00094   const CurvePointOptions * pointOptions() const {return _pointOptions;}
00095 
00096   enum TrackingModes{Select=0, Pick, PickOrdered, Edit};
00097   virtual bool mousePressEvent (QMouseEvent * e, int id=-1);
00098   virtual bool mouseReleaseEvent (QMouseEvent * e, int id=-1);
00099   virtual void mouseMoveEvent (const QPoint& pt, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
00100   virtual bool wheelEvent (QWheelEvent * e);
00101   virtual bool keyPressEvent (QKeyEvent* e);
00102   virtual void toggleTrackingAction(bool checked, int id=-1);
00103 
00104   typedef QList<AbstractLine *>::const_iterator const_iterator;
00105   const_iterator begin() const {return _lines.begin();}
00106   const_iterator end() const {return _lines.end();}
00107 
00108   virtual bool hasProperties() {return true;}
00109   virtual void addProperties(PropertyProxy * pp);
00110   virtual void removeProperties(PropertyProxy * pp);
00111   void resetLineProperties();
00112 signals:
00113   void pointAdded(AbstractLine * line, int pointIndex);
00114   void pickLine(AbstractLine * line);
00115   void lineEdited(int lineIndex);
00116 public slots:
00117   Q_SCRIPTABLE void setPenColor(int curveIndex, int red, int green, int blue);
00118   Q_SCRIPTABLE void setPenStyle(int curveIndex, double width, QString lineStyle, QString capStyle, QString joinStyle);
00119   Q_SCRIPTABLE void setSymType(int curveIndex, QString type);
00120   Q_SCRIPTABLE void setSymSize(int curveIndex, double size);
00121   Q_SCRIPTABLE void setSymPenColor(int curveIndex, int red, int green, int blue);
00122   Q_SCRIPTABLE void setSymPenStyle(int curveIndex, double width, QString lineStyle, QString capStyle, QString joinStyle);
00123   Q_SCRIPTABLE void setSymBrushColor(int curveIndex, int red, int green, int blue);
00124   Q_SCRIPTABLE void setSymBrushStyle(int curveIndex, QString brushStyle);
00125   Q_SCRIPTABLE void rmStdDev(int curveIndex);
00126   Q_SCRIPTABLE void attributesHelp();
00127   Q_SCRIPTABLE virtual void setLegend(Legend legend);
00128 protected:
00129   virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00130   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00131   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00132 
00133   int _currentLine;
00134   LineEditor * _lineEditor;
00135   ErrorBar _errorBar;
00136   CurvePointOptions * _pointOptions;
00137 private:
00138   void resetLayerProperties();
00139 
00140   AbstractLine * _referenceLine;
00141   QList<AbstractLine *> _lines;
00142   static uint _tabLineLayer;
00143 
00144   inline void drawCurve(const GraphContentOptions& gc, QPainter& p, double dotpercm, int h,
00145                          Rect& r, const AbstractLine& line, int startAt, int endAt) const;
00146   inline void drawVerticalErrorBar(double x, double minY, double maxY, const GraphContentOptions& gc,
00147                                     QPainter& p, Rect& r, int tickLength) const;
00148   inline void drawHorizontalErrorBar(double y, double minX, double maxX, const GraphContentOptions& gc,
00149                                       QPainter& p, Rect& r, int tickLength) const;
00150 };
00151 
00152 class LineLayerContext: public XMLContext
00153 {
00154 public:
00155   LineLayerContext(XMLSciFigs * parent, CurvePointOptions * options) {
00156     _parent=parent;
00157     _pointOptions=options;
00158   }
00159 
00160   CurvePointOptions * options() const {return _pointOptions;}
00161   XMLSciFigs * parent() const {return _parent;}
00162 private:
00163   XMLSciFigs * _parent;
00164   CurvePointOptions * _pointOptions;
00165 };
00166 
00167 } // namespace SciFigs
00168 
00169 #endif // LINELAYER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines