File indexing completed on 2024-12-22 04:17:39

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #ifndef PLOTAXIS_H
0014 #define PLOTAXIS_H
0015 
0016 #include <QObject>
0017 
0018 #include "plotitem.h"
0019 #include "plotmarkers.h"
0020 #include "ksttimezone.h"
0021 #include "plottickcalculator.h"
0022 
0023 namespace Kst {
0024 
0025 class PlotAxis : public QObject
0026 {
0027   Q_OBJECT
0028   public:
0029 
0030     enum ZoomMode { Auto, AutoBorder, FixedExpression, SpikeInsensitive, MeanCentered };
0031 
0032     PlotAxis(PlotItem *plotItem, Qt::Orientation orientation);
0033     ~PlotAxis();
0034 
0035     PlotItem* plotItem() { return _plotItem; }
0036 
0037     bool isAxisVisible() const;
0038     void setAxisVisible(bool visible);
0039 
0040     MajorTickMode axisMajorTickMode() const;
0041     void setAxisMajorTickMode(MajorTickMode mode);
0042 
0043     int axisMinorTickCount() const;
0044     void setAxisMinorTickCount(const int count);
0045 
0046     bool axisAutoMinorTicks() const;
0047     void setAxisAutoMinorTicks(const bool enabled);
0048 
0049     bool drawAxisMajorTicks() const;
0050     void setDrawAxisMajorTicks(const bool draw);
0051 
0052     bool drawAxisMinorTicks() const;
0053     void setDrawAxisMinorTicks(const bool draw);
0054 
0055     bool drawAxisMajorGridLines() const;
0056     void setDrawAxisMajorGridLines(const bool draw);
0057 
0058     bool drawAxisMinorGridLines() const;
0059     void setDrawAxisMinorGridLines(const bool draw);
0060 
0061     QColor axisMajorGridLineColor() const;
0062     void setAxisMajorGridLineColor(const QColor &color);
0063 
0064     QColor axisMinorGridLineColor() const;
0065     void setAxisMinorGridLineColor(const QColor &color);
0066 
0067     Qt::PenStyle axisMajorGridLineStyle() const;
0068     void setAxisMajorGridLineStyle(const Qt::PenStyle style);
0069 
0070     Qt::PenStyle axisMinorGridLineStyle() const;
0071     void setAxisMinorGridLineStyle(const Qt::PenStyle style);
0072 
0073     qreal axisMajorGridLineWidth() const;
0074     void setAxisMajorGridLineWidth(qreal width);
0075 
0076     qreal axisMinorGridLineWidth() const;
0077     void setAxisMinorGridLineWidth(qreal width);
0078 
0079     int axisSignificantDigits() const;
0080     void setAxisSignificantDigits(const int digits);
0081 
0082     ZoomMode axisZoomMode() const;
0083     void setAxisZoomMode(ZoomMode mode);
0084 
0085     bool axisLog() const;
0086     void setAxisLog(bool log);
0087 
0088     bool axisReversed() const;
0089     void setAxisReversed(const bool enabled);
0090 
0091     bool axisAutoBaseOffset() const;
0092     void setAxisAutoBaseOffset(const bool enabled);
0093 
0094     bool axisBaseOffset() const;
0095     void setAxisBaseOffset(const bool enabled);
0096 
0097     bool axisForceOffsetMin() const {return _axisForceOffsetMin;}
0098     void setAxisForceOffsetMin(bool enabled);
0099 
0100     bool axisInterpret() const;
0101     void setAxisInterpret(const bool enabled);
0102 
0103     QString timezoneName() const;
0104     void setTimezoneName(QString timezone);
0105 
0106     AxisDisplayType axisDisplay() const;
0107     void setAxisDisplay(const AxisDisplayType display);
0108 
0109     QString axisDisplayFormatString() const;
0110     void setAxisDisplayFormatString(const QString& formatString);
0111 
0112     AxisInterpretationType axisInterpretation() const;
0113     void setAxisInterpretation(const AxisInterpretationType interpret);
0114 
0115     int axisLabelRotation() const;
0116     void setAxisLabelRotation(const int rotation);
0117 
0118     PlotMarkers axisPlotMarkers() { return _axisPlotMarkers; }
0119     void setAxisPlotMarkers(const PlotMarkers &plotMarkers) { _axisPlotMarkers = plotMarkers; _ticksUpdated = true; }
0120 
0121     QMap<double, QString> axisLabels() { return _axisLabels; }
0122     QList<double> axisMajorTicks() { return _axisMajorTicks; }
0123     QList<double> axisMinorTicks() { return _axisMinorTicks; }
0124     QString baseLabel() { return _baseLabel; }
0125 
0126     void saveInPlot(QXmlStreamWriter &xml, QString axisId);
0127     bool configureFromXml(QXmlStreamReader &xml, ObjectStore *store);
0128 
0129     void validateDrawingRegion(QPainter *painter);
0130 
0131     // return the value and reset.
0132     bool ticksUpdated() { bool bReturn = _ticksUpdated; _ticksUpdated = false; return bReturn; }
0133     bool isDirty() { return _dirty; }
0134 
0135     void copyProperties(PlotAxis *source);
0136 
0137     void saveAsDialogDefaults(const QString &group) const;
0138 
0139     QString statusBarString(double X);
0140 
0141     int nsZoomLevel() { return _ns_zoom_level;}
0142 
0143   public Q_SLOTS:
0144     void updateTicks(bool useOverrideTicks = false);
0145     void setTicksUpdated() { _ticksUpdated = true; }
0146 
0147   private:
0148     double convertTimeValueToJD(double valueIn);
0149     double convertJDtoCTime(double jdIn);
0150     double convertJDtoDisplayTime(double T);
0151     QString convertJDToDateString(double jday, double range_jd);
0152 
0153     void updateLogTicks(MajorTickMode tickMode);
0154     void updateInterpretTicks(MajorTickMode tickMode);
0155     void updateLinearTicks(MajorTickMode tickMode);
0156     bool isLinearTickMode();
0157     MajorTickMode convertToMajorTickMode(int tickCount, MajorTickMode old_mode = TicksVeryFine);
0158 
0159   private:
0160 
0161     PlotItem *_plotItem;
0162     Qt::Orientation _orientation;
0163 
0164     bool _dirty;
0165 
0166     ZoomMode _axisZoomMode;
0167     bool _isAxisVisible;
0168     int _ns_zoom_level;
0169 
0170     bool _ticksUpdated;
0171 
0172     QRectF _labelRect;
0173     QMap<double, QString> _axisLabels;
0174     QList<double> _axisMajorTicks;
0175     QList<double> _axisMinorTicks;
0176 
0177     QString _baseLabel;
0178 
0179     bool _axisLog;
0180     bool _axisReversed;
0181     bool _axisAutoBaseOffset;
0182     bool _axisBaseOffset;
0183     bool _axisBaseOffsetOverride;
0184     bool _axisForceOffsetMin;
0185 
0186     bool _axisInterpret;
0187     AxisDisplayType _axisDisplay;
0188     QString _axisDisplayFormatString;
0189     AxisInterpretationType _axisInterpretation;
0190     KstTimeZone _timeZone;
0191 
0192     MajorTickMode _axisMajorTickMode;
0193     MajorTickMode _axisOverrideMajorTicks;
0194 
0195     int _axisMinorTickCount;
0196     bool _automaticMinorTicks;
0197     int _automaticMinorTickCount;
0198 
0199     int _axisSignificantDigits;
0200 
0201     bool _drawAxisMajorTicks;
0202     bool _drawAxisMinorTicks;
0203     bool _drawAxisMajorGridLines;
0204     bool _drawAxisMinorGridLines;
0205 
0206     QColor _axisMajorGridLineColor;
0207     QColor _axisMinorGridLineColor;
0208 
0209     Qt::PenStyle _axisMajorGridLineStyle;
0210     Qt::PenStyle _axisMinorGridLineStyle;
0211 
0212     qreal _axisMajorGridLineWidth;
0213     qreal _axisMinorGridLineWidth;
0214 
0215     PlotMarkers _axisPlotMarkers;
0216 
0217     int _labelRotation;
0218 };
0219 
0220 
0221 }
0222 
0223 #endif
0224 
0225 // vim: ts=2 sw=2 et