SciFigs/Axis.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 : 2002-04-18
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef AXIS_H
00030 #define AXIS_H
00031 
00032 #include <QGpGuiTools.h>
00033 
00034 #include "SciFigsDLLExport.h"
00035 #include "Scale.h"
00036 
00037 namespace SciFigs {
00038 
00039 class AxisGeneralProperties;
00040 class AxisFormatProperties;
00041 class GraphicObjectProperties;
00042 class AxisWindow;
00043 class GraphContent;
00044 
00045 class SCIFIGS_EXPORT Axis : public QWidget, public PropertyItem, public XMLClass
00046 {
00047   Q_OBJECT
00048   // Overload to mark the beginning of properties to save to XML
00049   Q_PROPERTY(QString objectName READ objectName WRITE setObjectName STORED true)
00050   // Compatibility
00051   Q_PROPERTY(QString name READ dummyPropertyString WRITE setObjectName STORED false)
00052   Q_PROPERTY(bool autoLabel READ dummyPropertyDouble WRITE setAutoTicks STORED false)
00053   Q_PROPERTY(double label READ dummyPropertyDouble WRITE setMajorTicks STORED false)
00054   Q_PROPERTY(double tick READ dummyPropertyDouble WRITE setMinorTicks STORED false)
00055   Q_PROPERTY(QString position READ dummyPropertyString WRITE setPositionString STORED false)
00056   Q_PROPERTY(QString numType READ dummyPropertyString WRITE setNumberTypeChar STORED false)
00057   Q_PROPERTY(int numPrec READ dummyPropertyInt WRITE setCurrentNumberPrecision STORED false)
00058   Q_PROPERTY(int inversedNumPrec READ dummyPropertyInt WRITE setCurrentInversedNumberPrecision STORED false)
00059   Q_PROPERTY(bool autoPrec READ dummyPropertyInt WRITE setAutoPrecision STORED false)
00060   Q_PROPERTY(bool zoomBlocked READ dummyPropertyInt WRITE setZoomBlocked STORED false)
00061   Q_PROPERTY(QString printScaleType READ dummyPropertyString WRITE setSizeType STORED false)
00062   Q_PROPERTY(double printLengthInfo READ dummyPropertyDouble WRITE setSizeInfo STORED false)
00063   Q_PROPERTY(double printLineWeight READ dummyPropertyDouble WRITE setLineWeight STORED false)
00064   Q_PROPERTY(double printTickLength READ dummyPropertyDouble WRITE setTickSize STORED false)
00065 
00066   Q_PROPERTY(QString scaleType READ scaleTypeString WRITE setScaleType SCRIPTABLE true)
00067   Q_PROPERTY(bool reversedScale READ reversedScale WRITE setReversedScale SCRIPTABLE true)
00068   Q_PROPERTY(double min READ minimum WRITE setMinimum SCRIPTABLE true)
00069   Q_PROPERTY(double max READ maximum WRITE setMaximum SCRIPTABLE true)
00070   Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks SCRIPTABLE true)
00071   Q_PROPERTY(double majorTicks READ majorTicks WRITE setMajorTicks SCRIPTABLE true)
00072   Q_PROPERTY(double minorTicks READ minorTicks WRITE setMinorTicks SCRIPTABLE true)
00073   Q_PROPERTY(QString stringLabels READ stringLabels WRITE setStringLabels SCRIPTABLE true)
00074   Q_PROPERTY(bool showLabels READ showLabels WRITE setShowLabels SCRIPTABLE true)
00075   Q_PROPERTY(bool zoomEnabled READ zoomEnabled WRITE setZoomEnabled SCRIPTABLE true)
00076   Q_PROPERTY(QString numberType READ numberTypeString WRITE setNumberType SCRIPTABLE true)
00077   Q_PROPERTY(int numberPrecision READ currentNumberPrecision WRITE setCurrentNumberPrecision SCRIPTABLE true)
00078   Q_PROPERTY(double unitFactor READ unitFactor WRITE setUnitFactor SCRIPTABLE true)
00079   Q_PROPERTY(bool autoPrecision READ autoPrecision WRITE setAutoPrecision SCRIPTABLE true)
00080   Q_PROPERTY(int inversedNumberPrecision READ currentInversedNumberPrecision WRITE setCurrentInversedNumberPrecision SCRIPTABLE true)
00081   Q_PROPERTY(QString orientation READ orientationString WRITE setOrientationString SCRIPTABLE true)
00082   Q_PROPERTY(QString title READ currentTitle WRITE setCurrentTitle SCRIPTABLE true)
00083   Q_PROPERTY(QString inversedTitle READ currentInversedTitle WRITE setCurrentInversedTitle SCRIPTABLE true)
00084   Q_PROPERTY(QString font READ fontString WRITE setFontString SCRIPTABLE true)
00085   Q_PROPERTY(QString sizeType READ sizeTypeString WRITE setSizeType SCRIPTABLE true)
00086   Q_PROPERTY(double sizeInfo READ sizeInfo WRITE setSizeInfo SCRIPTABLE true)
00087   Q_PROPERTY(double lineWeight READ lineWeight WRITE setLineWeight SCRIPTABLE true)
00088   Q_PROPERTY(double tickSize READ tickSize WRITE setTickSize SCRIPTABLE true)
00089   Q_PROPERTY(bool visible READ isEnabled WRITE setEnabled SCRIPTABLE true)
00090   Q_ENUMS (PrintScaleType);
00091   DUMMY_PROPERTIES;
00092 public:
00093   Axis(QWidget *parent=0);
00094   ~Axis();
00095 
00096   virtual const QString& xml_tagName() const {return xmlAxisTag;}
00097   static const QString xmlAxisTag;
00098 
00099   void operator=(const Axis& o);
00100   void setGraphContent(GraphContent * gc);
00101 
00102   enum SizeType {TotalSize=0, AxisSize, Scaled};
00103   enum Orientation {North=0, South, East, West};
00104 
00105   double minimum() const {return constScale().globalMinimum();}
00106   double maximum() const {return constScale().globalMaximum();}
00107   void setRange(double min, double max);
00108   void setMinimum(double m) {scale().setGlobalMinimum(m);}
00109   void setMaximum(double m) {scale().setGlobalMaximum(m);}
00110   double visibleMinimum() const {return constScale().minimum();}
00111   double visibleMaximum() const {return constScale().maximum();}
00112   Rect boundingRect() const;
00113 
00114   void addStringLabel(QString lab, bool updadeScale=true);
00115   void removeStringLabels();
00116   QString stringLabels() const;
00117   void setStringLabels(QString s);
00118 
00119   double majorTicks() const {return constScale().majorTicks();}
00120   void setMajorTicks(double m) {scale().setMajorTicks(m);}
00121   double minorTicks() const {return constScale().minorTicks();}
00122   void setMinorTicks(double m) {scale().setMinorTicks(m);}
00123   bool showLabels() const {return _showLabels;}
00124   void setShowLabels(bool m) {_showLabels=m;}
00125   bool autoTicks() const {return _autoTicks;}
00126   void setAutoTicks(bool m);
00127 
00128   bool zoomEnabled() const {return _zoomEnabled;}
00129   void setZoomEnabled(bool m) {_zoomEnabled=m;}
00130 
00131   Number::Type numberType() const {return _numberType;}
00132   QString numberTypeString() const;
00133   void setNumberType(Number::Type t);
00134   void setNumberType(QString t);
00135 
00136   int numberPrecision() const {return _numberPrecision;}
00137   void setNumberPrecision(int p) {_numberPrecision=p;}
00138   void setNumberPrecisionInversedScale(int np) {_numberPrecisionInversedScale=np;}
00139   int numberPrecisionInversedScale() const {return _numberPrecisionInversedScale;}
00140   int currentNumberPrecision() const;
00141   void setCurrentNumberPrecision(int p);
00142   int currentInversedNumberPrecision() const;
00143   void setCurrentInversedNumberPrecision(int p);
00144 
00145   void setUnitFactor(double s) {_unitFactor=s;}
00146   double unitFactor() const {return _unitFactor;}
00147 
00148   bool autoPrecision() const {return _autoPrecision;}
00149   void setAutoPrecision(bool p);
00150 
00151   void setScaleType(Scale::Type s);
00152   Scale::Type scaleType() const {return constScale().type();}
00153   QString scaleTypeString() const;
00154   void setScaleType(QString t);
00155   bool reversedScale() const {return constScale().isReversed();}
00156   void setReversedScale(bool b) {scale().setReversed(b);}
00157   bool isEffectivelyReversed() const {return constScale().isEffectivelyReversed();}
00158 
00159   QString title() const {return _title;}
00160   void setTitle(QString s) {_title=s;}
00161   void setTitleInversedScale(QString s) {_titleInversedScale=s;}
00162   QString titleInversedScale() const {return _titleInversedScale;}
00163   QString currentTitle() const;
00164   void setCurrentTitle(QString s);
00165   QString currentInversedTitle() const;
00166   void setCurrentInversedTitle(QString s);
00167 
00168   Orientation orientation() const {return _orientation;}
00169   void setOrientationBlocked(bool b) {_orientationBlocked=b;}
00170   void setOrientation(Orientation o);
00171   QString orientationString() const;
00172   void setOrientationString(QString o);
00173 
00174   QString fontString() const {return font().toString();}
00175   void setFontString(QString fs) {QFont f;f.fromString(fs);setFont(f);}
00176 
00177   SizeType sizeType() const {return _sizeType;}
00178   void setSizeType(SizeType st) {_sizeType=st;}
00179   QString sizeTypeString() const;
00180   void setSizeType(QString st);
00181 
00182   double sizeInfo() const {return _sizeInfo;}
00183   void setSizeInfo(double s) {if(s>0.0) _sizeInfo=s;}
00184   double lineWeight() const {return _lineWeight;}
00185   void setLineWeight(double val) {_lineWeight=val;}
00186   double tickSize() const {return _tickSize;}
00187   void setTickSize(double val) {_tickSize=val;}
00188 
00189   int lineCount() const {return constScale().lineCount();}
00190   void setCurrentLine(int line);
00191   int currentLine() const;
00192 
00193   void setVisibleRange(double val1, double val2);
00194   void setVisibleRange(bool zoomed);
00195   inline bool isZoomed();
00196 
00197   int lastMousePosition() {return _lastMousePosition;}
00198   bool isMouseTrack() {return _mouseTrack;}
00199   // Print the axis
00200   void setPrintScale(int w, int h);
00201   void paint(QPainter& p, double dotpercm, int w, int h, bool mask);
00202   int printThickness(int length, double dotpercm, QPainter * p=0);
00203 
00204   void addProperties(PropertyProxy * pp);
00205   void removeProperties(PropertyProxy * pp);
00206   virtual void properties(PropertyWidget * w) const;
00207   virtual void setProperty(uint wid, int pid, QVariant val);
00208 protected:
00209   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const {qobject_writeProperties(this, this, s, context);}
00210   virtual XMLMember xml_member(XML_MEMBER_ARGS) {return qobject_member(this, tag, attributes, context);}
00211   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS) {return qobject_setProperty(this, memberID, tag, attributes, content, context);}
00212 private:
00213   Scale& scale();
00214   const Scale& constScale() const;
00215 
00216   // XML property compatibility
00217   void setNumberTypeChar(QString t) {setNumberType(Number::type(t.toAscii().data()[0]));}
00218   void setPositionString(QString p);
00219   void setZoomBlocked(bool m) {setZoomEnabled(!m);}
00220 
00221   void setScaleTransformation(int w, int h);
00222   void calculatePrecicion();
00223 
00224   virtual void paintEvent(QPaintEvent * e);
00225   virtual void resizeEvent(QResizeEvent * e);
00226   void paintHorizontal(QPainter& p, double dotpercm, int w, int h, bool mask);
00227   void paintVertical(QPainter& p, double dotpercm, int w, int h, bool mask);
00228   // Used by paint() in Horizontal and Vertical axis
00229   inline void setPenFont(QPainter& p, bool mask, double dotpercm) const;
00230   // coordinates conversion
00231   int r2s(double val) const {return constScale().r2s(val);}
00232   double s2r(int val) const {return constScale().s2r(val);}
00233 
00234   // Graph content managed by this axis
00235   GraphContent * _content;
00236 
00237   Orientation _orientation;
00238   QVector<QString> * _stringLabels;
00239   Number::Type _numberType;
00240   int _numberPrecision;
00241   int _numberPrecisionInversedScale;
00242   double _unitFactor;
00243   // Title
00244   QString _title;
00245   QString _titleInversedScale;
00246 
00247   // Print properties
00248   SizeType _sizeType;
00249   double _sizeInfo;
00250   // Line weight for printing (in mm)
00251   double _lineWeight;
00252   // Tick length for printing (in mm)
00253   double _tickSize;
00254 
00255   // Last mouse position for mouse tracking
00256   int _lastMousePosition;
00257   // Boolean values
00258   uint _autoPrecision:1;
00259   uint _showLabels:1;
00260   uint _zoomEnabled:1;
00261   uint _autoTicks:1;
00262   uint _mouseTrack:1;
00263   uint _orientationBlocked:1;
00264 
00265   static uint _tabScale, _tabFormat;
00266 signals:
00267   void rangeChanged();
00268   void sizeChanged();
00269   void lengthChanged();
00270   void positionChanged();
00271   void orientationChanged();
00272   void contentChanged();
00273 public slots:
00274   void setMouseTrack(bool t);
00275   void trackMouse (QPoint mouseP);
00276 };
00277 
00278 inline bool Axis::isZoomed()
00279 {
00280   TRACE;
00281   return constScale().globalMinimum() < constScale().minimum() ||
00282          constScale().maximum() < constScale().globalMaximum();
00283 }
00284 
00285 } // namespace SciFigs
00286 
00287 #endif // AXIS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines