Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033
  1. /***************************************************************************
  2. ** **
  3. ** QCustomPlot, an easy to use, modern plotting widget for Qt **
  4. ** Copyright (C) 2011, 2012, 2013 Emanuel Eichhammer **
  5. ** **
  6. ** This program is free software: you can redistribute it and/or modify **
  7. ** it under the terms of the GNU General Public License as published by **
  8. ** the Free Software Foundation, either version 3 of the License, or **
  9. ** (at your option) any later version. **
  10. ** **
  11. ** This program is distributed in the hope that it will be useful, **
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
  14. ** GNU General Public License for more details. **
  15. ** **
  16. ** You should have received a copy of the GNU General Public License **
  17. ** along with this program. If not, see http://www.gnu.org/licenses/. **
  18. ** **
  19. ****************************************************************************
  20. ** Author: Emanuel Eichhammer **
  21. ** Website/Contact: http://www.qcustomplot.com/ **
  22. ** Date: 04.11.13 **
  23. ** Version: 1.1.0 **
  24. ****************************************************************************/
  25. #ifndef QCUSTOMPLOT_H
  26. #define QCUSTOMPLOT_H
  27. #include <QObject>
  28. #include <QPointer>
  29. #include <QWidget>
  30. #include <QPainter>
  31. #include <QPaintEvent>
  32. #include <QMouseEvent>
  33. #include <QPixmap>
  34. #include <QVector>
  35. #include <QString>
  36. #include <QDateTime>
  37. #include <QMultiMap>
  38. #include <QFlags>
  39. #include <QDebug>
  40. #include <QVector2D>
  41. #include <QStack>
  42. #include <QCache>
  43. #include <QMargins>
  44. #include <qmath.h>
  45. #include <limits>
  46. #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  47. # include <qnumeric.h>
  48. # include <QPrinter>
  49. #else
  50. # include <QtNumeric>
  51. # include <QtPrintSupport>
  52. #endif
  53. class QCPPainter;
  54. class QCustomPlot;
  55. class QCPLayerable;
  56. class QCPLayoutElement;
  57. class QCPLayout;
  58. class QCPAxis;
  59. class QCPAxisRect;
  60. class QCPAbstractPlottable;
  61. class QCPGraph;
  62. class QCPAbstractItem;
  63. class QCPItemPosition;
  64. class QCPLayer;
  65. class QCPPlotTitle;
  66. class QCPLegend;
  67. class QCPAbstractLegendItem;
  68. /*! \file */
  69. // decl definitions for shared library compilation/usage:
  70. #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
  71. # define QCP_LIB_DECL Q_DECL_EXPORT
  72. #elif defined(QCUSTOMPLOT_USE_LIBRARY)
  73. # define QCP_LIB_DECL Q_DECL_IMPORT
  74. #else
  75. # define QCP_LIB_DECL
  76. #endif
  77. /*!
  78. The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
  79. */
  80. namespace QCP
  81. {
  82. /*!
  83. Defines the sides of a rectangular entity to which margins can be applied.
  84. \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
  85. */
  86. enum MarginSide { msLeft = 0x01 ///< <tt>0x01</tt> left margin
  87. ,msRight = 0x02 ///< <tt>0x02</tt> right margin
  88. ,msTop = 0x04 ///< <tt>0x04</tt> top margin
  89. ,msBottom = 0x08 ///< <tt>0x08</tt> bottom margin
  90. ,msAll = 0xFF ///< <tt>0xFF</tt> all margins
  91. ,msNone = 0x00 ///< <tt>0x00</tt> no margin
  92. };
  93. Q_DECLARE_FLAGS(MarginSides, MarginSide)
  94. /*!
  95. Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
  96. neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
  97. element how it is drawn. Typically it provides a \a setAntialiased function for this.
  98. \c AntialiasedElements is a flag of or-combined elements of this enum type.
  99. \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
  100. */
  101. enum AntialiasedElement { aeAxes = 0x0001 ///< <tt>0x0001</tt> Axis base line and tick marks
  102. ,aeGrid = 0x0002 ///< <tt>0x0002</tt> Grid lines
  103. ,aeSubGrid = 0x0004 ///< <tt>0x0004</tt> Sub grid lines
  104. ,aeLegend = 0x0008 ///< <tt>0x0008</tt> Legend box
  105. ,aeLegendItems = 0x0010 ///< <tt>0x0010</tt> Legend items
  106. ,aePlottables = 0x0020 ///< <tt>0x0020</tt> Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
  107. ,aeItems = 0x0040 ///< <tt>0x0040</tt> Main lines of items
  108. ,aeScatters = 0x0080 ///< <tt>0x0080</tt> Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
  109. ,aeErrorBars = 0x0100 ///< <tt>0x0100</tt> Error bars
  110. ,aeFills = 0x0200 ///< <tt>0x0200</tt> Borders of fills (e.g. under or between graphs)
  111. ,aeZeroLine = 0x0400 ///< <tt>0x0400</tt> Zero-lines, see \ref QCPGrid::setZeroLinePen
  112. ,aeAll = 0xFFFF ///< <tt>0xFFFF</tt> All elements
  113. ,aeNone = 0x0000 ///< <tt>0x0000</tt> No elements
  114. };
  115. Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
  116. /*!
  117. Defines plotting hints that control various aspects of the quality and speed of plotting.
  118. \see QCustomPlot::setPlottingHints
  119. */
  120. enum PlottingHint { phNone = 0x000 ///< <tt>0x000</tt> No hints are set
  121. ,phFastPolylines = 0x001 ///< <tt>0x001</tt> Graph/Curve lines are drawn with a faster method. This reduces the quality
  122. ///< especially of the line segment joins. (Only relevant for solid line pens.)
  123. ,phForceRepaint = 0x002 ///< <tt>0x002</tt> causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called. This is set by default
  124. ///< on Windows-Systems to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
  125. ,phCacheLabels = 0x004 ///< <tt>0x004</tt> axis (tick) labels will be cached as pixmaps, increasing replot performance.
  126. };
  127. Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
  128. /*!
  129. Defines the mouse interactions possible with QCustomPlot.
  130. \c Interactions is a flag of or-combined elements of this enum type.
  131. \see QCustomPlot::setInteractions
  132. */
  133. enum Interaction { iRangeDrag = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
  134. ,iRangeZoom = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
  135. ,iMultiSelect = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
  136. ,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
  137. ,iSelectAxes = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
  138. ,iSelectLegend = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
  139. ,iSelectItems = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
  140. ,iSelectOther = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, the plot title,...)
  141. };
  142. Q_DECLARE_FLAGS(Interactions, Interaction)
  143. /*! \internal
  144. Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
  145. is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
  146. compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
  147. */
  148. inline bool isInvalidData(double value)
  149. {
  150. return qIsNaN(value) || qIsInf(value);
  151. }
  152. /*! \internal
  153. \overload
  154. Checks two arguments instead of one.
  155. */
  156. inline bool isInvalidData(double value1, double value2)
  157. {
  158. return isInvalidData(value1) || isInvalidData(value2);
  159. }
  160. /*! \internal
  161. Sets the specified \a side of \a margins to \a value
  162. \see getMarginValue
  163. */
  164. inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
  165. {
  166. switch (side)
  167. {
  168. case QCP::msLeft: margins.setLeft(value); break;
  169. case QCP::msRight: margins.setRight(value); break;
  170. case QCP::msTop: margins.setTop(value); break;
  171. case QCP::msBottom: margins.setBottom(value); break;
  172. case QCP::msAll: margins = QMargins(value, value, value, value); break;
  173. default: break;
  174. }
  175. }
  176. /*! \internal
  177. Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
  178. \ref QCP::msAll, returns 0.
  179. \see setMarginValue
  180. */
  181. inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
  182. {
  183. switch (side)
  184. {
  185. case QCP::msLeft: return margins.left();
  186. case QCP::msRight: return margins.right();
  187. case QCP::msTop: return margins.top();
  188. case QCP::msBottom: return margins.bottom();
  189. default: break;
  190. }
  191. return 0;
  192. }
  193. } // end of namespace QCP
  194. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
  195. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
  196. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
  197. Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
  198. class QCP_LIB_DECL QCPScatterStyle
  199. {
  200. Q_GADGET
  201. public:
  202. /*!
  203. Defines the shape used for scatter points.
  204. On plottables/items that draw scatters, the sizes of these visualizations (with exception of
  205. \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
  206. drawn with the pen and brush specified with \ref setPen and \ref setBrush.
  207. */
  208. Q_ENUMS(ScatterShape)
  209. enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
  210. ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
  211. ,ssCross ///< \enumimage{ssCross.png} a cross
  212. ,ssPlus ///< \enumimage{ssPlus.png} a plus
  213. ,ssCircle ///< \enumimage{ssCircle.png} a circle
  214. ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
  215. ,ssSquare ///< \enumimage{ssSquare.png} a square
  216. ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
  217. ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
  218. ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
  219. ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
  220. ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
  221. ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
  222. ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
  223. ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
  224. ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
  225. ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
  226. ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
  227. };
  228. QCPScatterStyle();
  229. QCPScatterStyle(ScatterShape shape, double size=6);
  230. QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
  231. QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
  232. QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
  233. QCPScatterStyle(const QPixmap &pixmap);
  234. QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
  235. // getters:
  236. double size() const { return mSize; }
  237. ScatterShape shape() const { return mShape; }
  238. QPen pen() const { return mPen; }
  239. QBrush brush() const { return mBrush; }
  240. QPixmap pixmap() const { return mPixmap; }
  241. QPainterPath customPath() const { return mCustomPath; }
  242. // setters:
  243. void setSize(double size);
  244. void setShape(ScatterShape shape);
  245. void setPen(const QPen &pen);
  246. void setBrush(const QBrush &brush);
  247. void setPixmap(const QPixmap &pixmap);
  248. void setCustomPath(const QPainterPath &customPath);
  249. // non-property methods:
  250. bool isNone() const { return mShape == ssNone; }
  251. bool isPenDefined() const { return mPenDefined; }
  252. void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
  253. void drawShape(QCPPainter *painter, QPointF pos) const;
  254. void drawShape(QCPPainter *painter, double x, double y) const;
  255. protected:
  256. // property members:
  257. double mSize;
  258. ScatterShape mShape;
  259. QPen mPen;
  260. QBrush mBrush;
  261. QPixmap mPixmap;
  262. QPainterPath mCustomPath;
  263. // non-property members:
  264. bool mPenDefined;
  265. };
  266. Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
  267. class QCP_LIB_DECL QCPPainter : public QPainter
  268. {
  269. Q_GADGET
  270. public:
  271. /*!
  272. Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
  273. depending on whether they are wanted on the respective output device.
  274. */
  275. enum PainterMode {pmDefault = 0x00 ///< <tt>0x00</tt> Default mode for painting on screen devices
  276. ,pmVectorized = 0x01 ///< <tt>0x01</tt> Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
  277. ,pmNoCaching = 0x02 ///< <tt>0x02</tt> Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
  278. ,pmNonCosmetic = 0x04 ///< <tt>0x04</tt> Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
  279. };
  280. Q_FLAGS(PainterMode PainterModes)
  281. Q_DECLARE_FLAGS(PainterModes, PainterMode)
  282. QCPPainter();
  283. QCPPainter(QPaintDevice *device);
  284. ~QCPPainter();
  285. // getters:
  286. bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
  287. PainterModes modes() const { return mModes; }
  288. // setters:
  289. void setAntialiasing(bool enabled);
  290. void setMode(PainterMode mode, bool enabled=true);
  291. void setModes(PainterModes modes);
  292. // methods hiding non-virtual base class functions (QPainter bug workarounds):
  293. bool begin(QPaintDevice *device);
  294. void setPen(const QPen &pen);
  295. void setPen(const QColor &color);
  296. void setPen(Qt::PenStyle penStyle);
  297. void drawLine(const QLineF &line);
  298. void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
  299. void save();
  300. void restore();
  301. // non-virtual methods:
  302. void makeNonCosmetic();
  303. protected:
  304. // property members:
  305. PainterModes mModes;
  306. bool mIsAntialiasing;
  307. // non-property members:
  308. QStack<bool> mAntialiasingStack;
  309. };
  310. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
  311. class QCP_LIB_DECL QCPLayer : public QObject
  312. {
  313. Q_OBJECT
  314. /// \cond INCLUDE_QPROPERTIES
  315. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  316. Q_PROPERTY(QString name READ name)
  317. Q_PROPERTY(int index READ index)
  318. Q_PROPERTY(QList<QCPLayerable*> children READ children)
  319. /// \endcond
  320. public:
  321. QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
  322. ~QCPLayer();
  323. // getters:
  324. QCustomPlot *parentPlot() const { return mParentPlot; }
  325. QString name() const { return mName; }
  326. int index() const { return mIndex; }
  327. QList<QCPLayerable*> children() const { return mChildren; }
  328. protected:
  329. // property members:
  330. QCustomPlot *mParentPlot;
  331. QString mName;
  332. int mIndex;
  333. QList<QCPLayerable*> mChildren;
  334. // non-virtual methods:
  335. void addChild(QCPLayerable *layerable, bool prepend);
  336. void removeChild(QCPLayerable *layerable);
  337. private:
  338. Q_DISABLE_COPY(QCPLayer)
  339. friend class QCustomPlot;
  340. friend class QCPLayerable;
  341. };
  342. class QCP_LIB_DECL QCPLayerable : public QObject
  343. {
  344. Q_OBJECT
  345. /// \cond INCLUDE_QPROPERTIES
  346. Q_PROPERTY(bool visible READ visible WRITE setVisible)
  347. Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
  348. Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
  349. Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer)
  350. Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
  351. /// \endcond
  352. public:
  353. QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0);
  354. ~QCPLayerable();
  355. // getters:
  356. bool visible() const { return mVisible; }
  357. QCustomPlot *parentPlot() const { return mParentPlot; }
  358. QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
  359. QCPLayer *layer() const { return mLayer; }
  360. bool antialiased() const { return mAntialiased; }
  361. // setters:
  362. void setVisible(bool on);
  363. bool setLayer(QCPLayer *layer);
  364. bool setLayer(const QString &layerName);
  365. void setAntialiased(bool enabled);
  366. // introduced virtual methods:
  367. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  368. // non-property methods:
  369. bool realVisibility() const;
  370. protected:
  371. // property members:
  372. bool mVisible;
  373. QCustomPlot *mParentPlot;
  374. QPointer<QCPLayerable> mParentLayerable;
  375. QCPLayer *mLayer;
  376. bool mAntialiased;
  377. // introduced virtual methods:
  378. virtual void parentPlotInitialized(QCustomPlot *parentPlot);
  379. virtual QCP::Interaction selectionCategory() const;
  380. virtual QRect clipRect() const;
  381. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
  382. virtual void draw(QCPPainter *painter) = 0;
  383. // events:
  384. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  385. virtual void deselectEvent(bool *selectionStateChanged);
  386. // non-property methods:
  387. void initializeParentPlot(QCustomPlot *parentPlot);
  388. void setParentLayerable(QCPLayerable* parentLayerable);
  389. bool moveToLayer(QCPLayer *layer, bool prepend);
  390. void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
  391. private:
  392. Q_DISABLE_COPY(QCPLayerable)
  393. friend class QCustomPlot;
  394. friend class QCPAxisRect;
  395. };
  396. class QCP_LIB_DECL QCPRange
  397. {
  398. public:
  399. double lower, upper;
  400. QCPRange();
  401. QCPRange(double lower, double upper);
  402. double size() const;
  403. double center() const;
  404. void normalize();
  405. void expand(const QCPRange &otherRange);
  406. QCPRange expanded(const QCPRange &otherRange) const;
  407. QCPRange sanitizedForLogScale() const;
  408. QCPRange sanitizedForLinScale() const;
  409. bool contains(double value) const;
  410. static bool validRange(double lower, double upper);
  411. static bool validRange(const QCPRange &range);
  412. static const double minRange; //1e-280;
  413. static const double maxRange; //1e280;
  414. };
  415. Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
  416. class QCP_LIB_DECL QCPMarginGroup : public QObject
  417. {
  418. Q_OBJECT
  419. public:
  420. QCPMarginGroup(QCustomPlot *parentPlot);
  421. ~QCPMarginGroup();
  422. // non-virtual methods:
  423. QList<QCPLayoutElement*> elements(QCP::MarginSide side) const { return mChildren.value(side); }
  424. bool isEmpty() const;
  425. void clear();
  426. protected:
  427. // non-property members:
  428. QCustomPlot *mParentPlot;
  429. QHash<QCP::MarginSide, QList<QCPLayoutElement*> > mChildren;
  430. // non-virtual methods:
  431. int commonMargin(QCP::MarginSide side) const;
  432. void addChild(QCP::MarginSide side, QCPLayoutElement *element);
  433. void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
  434. private:
  435. Q_DISABLE_COPY(QCPMarginGroup)
  436. friend class QCPLayoutElement;
  437. };
  438. class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
  439. {
  440. Q_OBJECT
  441. /// \cond INCLUDE_QPROPERTIES
  442. Q_PROPERTY(QCPLayout* layout READ layout)
  443. Q_PROPERTY(QRect rect READ rect)
  444. Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
  445. Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
  446. Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
  447. Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
  448. Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
  449. /// \endcond
  450. public:
  451. explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
  452. virtual ~QCPLayoutElement();
  453. // getters:
  454. QCPLayout *layout() const { return mParentLayout; }
  455. QRect rect() const { return mRect; }
  456. QRect outerRect() const { return mOuterRect; }
  457. QMargins margins() const { return mMargins; }
  458. QMargins minimumMargins() const { return mMinimumMargins; }
  459. QCP::MarginSides autoMargins() const { return mAutoMargins; }
  460. QSize minimumSize() const { return mMinimumSize; }
  461. QSize maximumSize() const { return mMaximumSize; }
  462. QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
  463. QHash<QCP::MarginSide, QCPMarginGroup*> marginGroups() const { return mMarginGroups; }
  464. // setters:
  465. void setOuterRect(const QRect &rect);
  466. void setMargins(const QMargins &margins);
  467. void setMinimumMargins(const QMargins &margins);
  468. void setAutoMargins(QCP::MarginSides sides);
  469. void setMinimumSize(const QSize &size);
  470. void setMinimumSize(int width, int height);
  471. void setMaximumSize(const QSize &size);
  472. void setMaximumSize(int width, int height);
  473. void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
  474. // introduced virtual methods:
  475. virtual void update();
  476. virtual QSize minimumSizeHint() const;
  477. virtual QSize maximumSizeHint() const;
  478. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  479. // reimplemented virtual methods:
  480. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  481. protected:
  482. // property members:
  483. QCPLayout *mParentLayout;
  484. QSize mMinimumSize, mMaximumSize;
  485. QRect mRect, mOuterRect;
  486. QMargins mMargins, mMinimumMargins;
  487. QCP::MarginSides mAutoMargins;
  488. QHash<QCP::MarginSide, QCPMarginGroup*> mMarginGroups;
  489. // introduced virtual methods:
  490. virtual int calculateAutoMargin(QCP::MarginSide side);
  491. // events:
  492. virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
  493. virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
  494. virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
  495. virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
  496. virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
  497. // reimplemented virtual methods:
  498. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
  499. virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
  500. virtual void parentPlotInitialized(QCustomPlot *parentPlot);
  501. private:
  502. Q_DISABLE_COPY(QCPLayoutElement)
  503. friend class QCustomPlot;
  504. friend class QCPLayout;
  505. friend class QCPMarginGroup;
  506. };
  507. class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
  508. {
  509. Q_OBJECT
  510. public:
  511. explicit QCPLayout();
  512. // reimplemented virtual methods:
  513. virtual void update();
  514. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  515. // introduced virtual methods:
  516. virtual int elementCount() const = 0;
  517. virtual QCPLayoutElement* elementAt(int index) const = 0;
  518. virtual QCPLayoutElement* takeAt(int index) = 0;
  519. virtual bool take(QCPLayoutElement* element) = 0;
  520. virtual void simplify();
  521. // non-virtual methods:
  522. bool removeAt(int index);
  523. bool remove(QCPLayoutElement* element);
  524. void clear();
  525. protected:
  526. // introduced virtual methods:
  527. virtual void updateLayout();
  528. // non-virtual methods:
  529. void sizeConstraintsChanged() const;
  530. void adoptElement(QCPLayoutElement *el);
  531. void releaseElement(QCPLayoutElement *el);
  532. QVector<int> getSectionSizes(QVector<int> maxSizes, QVector<int> minSizes, QVector<double> stretchFactors, int totalSize) const;
  533. private:
  534. Q_DISABLE_COPY(QCPLayout)
  535. friend class QCPLayoutElement;
  536. };
  537. class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
  538. {
  539. Q_OBJECT
  540. /// \cond INCLUDE_QPROPERTIES
  541. Q_PROPERTY(int rowCount READ rowCount)
  542. Q_PROPERTY(int columnCount READ columnCount)
  543. Q_PROPERTY(QList<double> columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
  544. Q_PROPERTY(QList<double> rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
  545. Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
  546. Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
  547. /// \endcond
  548. public:
  549. explicit QCPLayoutGrid();
  550. virtual ~QCPLayoutGrid();
  551. // getters:
  552. int rowCount() const;
  553. int columnCount() const;
  554. QList<double> columnStretchFactors() const { return mColumnStretchFactors; }
  555. QList<double> rowStretchFactors() const { return mRowStretchFactors; }
  556. int columnSpacing() const { return mColumnSpacing; }
  557. int rowSpacing() const { return mRowSpacing; }
  558. // setters:
  559. void setColumnStretchFactor(int column, double factor);
  560. void setColumnStretchFactors(const QList<double> &factors);
  561. void setRowStretchFactor(int row, double factor);
  562. void setRowStretchFactors(const QList<double> &factors);
  563. void setColumnSpacing(int pixels);
  564. void setRowSpacing(int pixels);
  565. // reimplemented virtual methods:
  566. virtual void updateLayout();
  567. virtual int elementCount() const;
  568. virtual QCPLayoutElement* elementAt(int index) const;
  569. virtual QCPLayoutElement* takeAt(int index);
  570. virtual bool take(QCPLayoutElement* element);
  571. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  572. virtual void simplify();
  573. virtual QSize minimumSizeHint() const;
  574. virtual QSize maximumSizeHint() const;
  575. // non-virtual methods:
  576. QCPLayoutElement *element(int row, int column) const;
  577. bool addElement(int row, int column, QCPLayoutElement *element);
  578. bool hasElement(int row, int column);
  579. void expandTo(int newRowCount, int newColumnCount);
  580. void insertRow(int newIndex);
  581. void insertColumn(int newIndex);
  582. protected:
  583. // property members:
  584. QList<QList<QCPLayoutElement*> > mElements;
  585. QList<double> mColumnStretchFactors;
  586. QList<double> mRowStretchFactors;
  587. int mColumnSpacing, mRowSpacing;
  588. // non-virtual methods:
  589. void getMinimumRowColSizes(QVector<int> *minColWidths, QVector<int> *minRowHeights) const;
  590. void getMaximumRowColSizes(QVector<int> *maxColWidths, QVector<int> *maxRowHeights) const;
  591. private:
  592. Q_DISABLE_COPY(QCPLayoutGrid)
  593. };
  594. class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
  595. {
  596. Q_OBJECT
  597. public:
  598. /*!
  599. Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
  600. */
  601. enum InsetPlacement {ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
  602. ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
  603. };
  604. explicit QCPLayoutInset();
  605. virtual ~QCPLayoutInset();
  606. // getters:
  607. InsetPlacement insetPlacement(int index) const;
  608. Qt::Alignment insetAlignment(int index) const;
  609. QRectF insetRect(int index) const;
  610. // setters:
  611. void setInsetPlacement(int index, InsetPlacement placement);
  612. void setInsetAlignment(int index, Qt::Alignment alignment);
  613. void setInsetRect(int index, const QRectF &rect);
  614. // reimplemented virtual methods:
  615. virtual void updateLayout();
  616. virtual int elementCount() const;
  617. virtual QCPLayoutElement* elementAt(int index) const;
  618. virtual QCPLayoutElement* takeAt(int index);
  619. virtual bool take(QCPLayoutElement* element);
  620. virtual void simplify() {}
  621. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  622. // non-virtual methods:
  623. void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
  624. void addElement(QCPLayoutElement *element, const QRectF &rect);
  625. protected:
  626. // property members:
  627. QList<QCPLayoutElement*> mElements;
  628. QList<InsetPlacement> mInsetPlacement;
  629. QList<Qt::Alignment> mInsetAlignment;
  630. QList<QRectF> mInsetRect;
  631. private:
  632. Q_DISABLE_COPY(QCPLayoutInset)
  633. };
  634. class QCP_LIB_DECL QCPLineEnding
  635. {
  636. Q_GADGET
  637. public:
  638. /*!
  639. Defines the type of ending decoration for line-like items, e.g. an arrow.
  640. \image html QCPLineEnding.png
  641. The width and length of these decorations can be controlled with the functions \ref setWidth
  642. and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
  643. support a width, the length property is ignored.
  644. \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail
  645. */
  646. Q_ENUMS(EndingStyle)
  647. enum EndingStyle { esNone ///< No ending decoration
  648. ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
  649. ,esSpikeArrow ///< A filled arrow head with an indented back
  650. ,esLineArrow ///< A non-filled arrow head with open back
  651. ,esDisc ///< A filled circle
  652. ,esSquare ///< A filled square
  653. ,esDiamond ///< A filled diamond (45° rotated square)
  654. ,esBar ///< A bar perpendicular to the line
  655. ,esHalfBar ///< A bar perpendicular to the line sticking out to one side
  656. ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
  657. };
  658. QCPLineEnding();
  659. QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
  660. // getters:
  661. EndingStyle style() const { return mStyle; }
  662. double width() const { return mWidth; }
  663. double length() const { return mLength; }
  664. bool inverted() const { return mInverted; }
  665. // setters:
  666. void setStyle(EndingStyle style);
  667. void setWidth(double width);
  668. void setLength(double length);
  669. void setInverted(bool inverted);
  670. // non-property methods:
  671. double boundingDistance() const;
  672. double realLength() const;
  673. void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
  674. void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
  675. protected:
  676. // property members:
  677. EndingStyle mStyle;
  678. double mWidth, mLength;
  679. bool mInverted;
  680. };
  681. Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
  682. class QCP_LIB_DECL QCPGrid :public QCPLayerable
  683. {
  684. Q_OBJECT
  685. /// \cond INCLUDE_QPROPERTIES
  686. Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
  687. Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
  688. Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
  689. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  690. Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
  691. Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
  692. /// \endcond
  693. public:
  694. QCPGrid(QCPAxis *parentAxis);
  695. // getters:
  696. bool subGridVisible() const { return mSubGridVisible; }
  697. bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
  698. bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
  699. QPen pen() const { return mPen; }
  700. QPen subGridPen() const { return mSubGridPen; }
  701. QPen zeroLinePen() const { return mZeroLinePen; }
  702. // setters:
  703. void setSubGridVisible(bool visible);
  704. void setAntialiasedSubGrid(bool enabled);
  705. void setAntialiasedZeroLine(bool enabled);
  706. void setPen(const QPen &pen);
  707. void setSubGridPen(const QPen &pen);
  708. void setZeroLinePen(const QPen &pen);
  709. protected:
  710. // property members:
  711. bool mSubGridVisible;
  712. bool mAntialiasedSubGrid, mAntialiasedZeroLine;
  713. QPen mPen, mSubGridPen, mZeroLinePen;
  714. // non-property members:
  715. QCPAxis *mParentAxis;
  716. // reimplemented virtual methods:
  717. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  718. virtual void draw(QCPPainter *painter);
  719. // non-virtual methods:
  720. void drawGridLines(QCPPainter *painter) const;
  721. void drawSubGridLines(QCPPainter *painter) const;
  722. friend class QCPAxis;
  723. };
  724. class QCP_LIB_DECL QCPAxis : public QCPLayerable
  725. {
  726. Q_OBJECT
  727. /// \cond INCLUDE_QPROPERTIES
  728. Q_PROPERTY(AxisType axisType READ axisType)
  729. Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
  730. Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType)
  731. Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
  732. Q_PROPERTY(QCPRange range READ range WRITE setRange)
  733. Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
  734. Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
  735. Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
  736. Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
  737. Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
  738. Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
  739. Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
  740. Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
  741. Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
  742. Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
  743. Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
  744. Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
  745. Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
  746. Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
  747. Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
  748. Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
  749. Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
  750. Q_PROPERTY(QVector<double> tickVector READ tickVector WRITE setTickVector)
  751. Q_PROPERTY(QVector<QString> tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
  752. Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
  753. Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
  754. Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
  755. Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
  756. Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
  757. Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
  758. Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
  759. Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
  760. Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
  761. Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
  762. Q_PROPERTY(QString label READ label WRITE setLabel)
  763. Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
  764. Q_PROPERTY(int padding READ padding WRITE setPadding)
  765. Q_PROPERTY(int offset READ offset WRITE setOffset)
  766. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts)
  767. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts)
  768. Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
  769. Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
  770. Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
  771. Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
  772. Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
  773. Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
  774. Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
  775. Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
  776. Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
  777. Q_PROPERTY(QCPGrid* grid READ grid)
  778. /// \endcond
  779. public:
  780. /*!
  781. Defines at which side of the axis rect the axis will appear. This also affects how the tick
  782. marks are drawn, on which side the labels are placed etc.
  783. */
  784. enum AxisType { atLeft = 0x01 ///< <tt>0x01</tt> Axis is vertical and on the left side of the axis rect
  785. ,atRight = 0x02 ///< <tt>0x02</tt> Axis is vertical and on the right side of the axis rect
  786. ,atTop = 0x04 ///< <tt>0x04</tt> Axis is horizontal and on the top side of the axis rect
  787. ,atBottom = 0x08 ///< <tt>0x08</tt> Axis is horizontal and on the bottom side of the axis rect
  788. };
  789. Q_FLAGS(AxisType AxisTypes)
  790. Q_DECLARE_FLAGS(AxisTypes, AxisType)
  791. /*!
  792. When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
  793. coordinate of the tick is interpreted, i.e. translated into a string.
  794. \see setTickLabelType
  795. */
  796. enum LabelType { ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat)
  797. ,ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for details, see \ref setDateTimeFormat)
  798. };
  799. Q_ENUMS(LabelType)
  800. /*!
  801. Defines the scale of an axis.
  802. \see setScaleType
  803. */
  804. enum ScaleType { stLinear ///< Linear scaling
  805. ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase).
  806. };
  807. Q_ENUMS(ScaleType)
  808. /*!
  809. Defines the selectable parts of an axis.
  810. \see setSelectableParts, setSelectedParts
  811. */
  812. enum SelectablePart { spNone = 0 ///< None of the selectable parts
  813. ,spAxis = 0x001 ///< The axis backbone and tick marks
  814. ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
  815. ,spAxisLabel = 0x004 ///< The axis label
  816. };
  817. Q_FLAGS(SelectablePart SelectableParts)
  818. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  819. explicit QCPAxis(QCPAxisRect *parent, AxisType type);
  820. // getters:
  821. AxisType axisType() const { return mAxisType; }
  822. QCPAxisRect *axisRect() const { return mAxisRect; }
  823. ScaleType scaleType() const { return mScaleType; }
  824. double scaleLogBase() const { return mScaleLogBase; }
  825. const QCPRange range() const { return mRange; }
  826. bool rangeReversed() const { return mRangeReversed; }
  827. bool autoTicks() const { return mAutoTicks; }
  828. int autoTickCount() const { return mAutoTickCount; }
  829. bool autoTickLabels() const { return mAutoTickLabels; }
  830. bool autoTickStep() const { return mAutoTickStep; }
  831. bool autoSubTicks() const { return mAutoSubTicks; }
  832. bool ticks() const { return mTicks; }
  833. bool tickLabels() const { return mTickLabels; }
  834. int tickLabelPadding() const { return mTickLabelPadding; }
  835. LabelType tickLabelType() const { return mTickLabelType; }
  836. QFont tickLabelFont() const { return mTickLabelFont; }
  837. QColor tickLabelColor() const { return mTickLabelColor; }
  838. double tickLabelRotation() const { return mTickLabelRotation; }
  839. QString dateTimeFormat() const { return mDateTimeFormat; }
  840. Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
  841. QString numberFormat() const;
  842. int numberPrecision() const { return mNumberPrecision; }
  843. double tickStep() const { return mTickStep; }
  844. QVector<double> tickVector() const { return mTickVector; }
  845. QVector<QString> tickVectorLabels() const { return mTickVectorLabels; }
  846. int tickLengthIn() const { return mTickLengthIn; }
  847. int tickLengthOut() const { return mTickLengthOut; }
  848. int subTickCount() const { return mSubTickCount; }
  849. int subTickLengthIn() const { return mSubTickLengthIn; }
  850. int subTickLengthOut() const { return mSubTickLengthOut; }
  851. QPen basePen() const { return mBasePen; }
  852. QPen tickPen() const { return mTickPen; }
  853. QPen subTickPen() const { return mSubTickPen; }
  854. QFont labelFont() const { return mLabelFont; }
  855. QColor labelColor() const { return mLabelColor; }
  856. QString label() const { return mLabel; }
  857. int labelPadding() const { return mLabelPadding; }
  858. int padding() const { return mPadding; }
  859. int offset() const { return mOffset; }
  860. SelectableParts selectedParts() const { return mSelectedParts; }
  861. SelectableParts selectableParts() const { return mSelectableParts; }
  862. QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
  863. QFont selectedLabelFont() const { return mSelectedLabelFont; }
  864. QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
  865. QColor selectedLabelColor() const { return mSelectedLabelColor; }
  866. QPen selectedBasePen() const { return mSelectedBasePen; }
  867. QPen selectedTickPen() const { return mSelectedTickPen; }
  868. QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
  869. QCPLineEnding lowerEnding() const { return mLowerEnding; }
  870. QCPLineEnding upperEnding() const { return mUpperEnding; }
  871. QCPGrid *grid() const { return mGrid; }
  872. // setters:
  873. void setScaleType(ScaleType type);
  874. void setScaleLogBase(double base);
  875. Q_SLOT void setRange(const QCPRange &range);
  876. void setRange(double lower, double upper);
  877. void setRange(double position, double size, Qt::AlignmentFlag alignment);
  878. void setRangeLower(double lower);
  879. void setRangeUpper(double upper);
  880. void setRangeReversed(bool reversed);
  881. void setAutoTicks(bool on);
  882. void setAutoTickCount(int approximateCount);
  883. void setAutoTickLabels(bool on);
  884. void setAutoTickStep(bool on);
  885. void setAutoSubTicks(bool on);
  886. void setTicks(bool show);
  887. void setTickLabels(bool show);
  888. void setTickLabelPadding(int padding);
  889. void setTickLabelType(LabelType type);
  890. void setTickLabelFont(const QFont &font);
  891. void setTickLabelColor(const QColor &color);
  892. void setTickLabelRotation(double degrees);
  893. void setDateTimeFormat(const QString &format);
  894. void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
  895. void setNumberFormat(const QString &formatCode);
  896. void setNumberPrecision(int precision);
  897. void setTickStep(double step);
  898. void setTickVector(const QVector<double> &vec);
  899. void setTickVectorLabels(const QVector<QString> &vec);
  900. void setTickLength(int inside, int outside=0);
  901. void setTickLengthIn(int inside);
  902. void setTickLengthOut(int outside);
  903. void setSubTickCount(int count);
  904. void setSubTickLength(int inside, int outside=0);
  905. void setSubTickLengthIn(int inside);
  906. void setSubTickLengthOut(int outside);
  907. void setBasePen(const QPen &pen);
  908. void setTickPen(const QPen &pen);
  909. void setSubTickPen(const QPen &pen);
  910. void setLabelFont(const QFont &font);
  911. void setLabelColor(const QColor &color);
  912. void setLabel(const QString &str);
  913. void setLabelPadding(int padding);
  914. void setPadding(int padding);
  915. void setOffset(int offset);
  916. void setSelectedTickLabelFont(const QFont &font);
  917. void setSelectedLabelFont(const QFont &font);
  918. void setSelectedTickLabelColor(const QColor &color);
  919. void setSelectedLabelColor(const QColor &color);
  920. void setSelectedBasePen(const QPen &pen);
  921. void setSelectedTickPen(const QPen &pen);
  922. void setSelectedSubTickPen(const QPen &pen);
  923. Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
  924. Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
  925. void setLowerEnding(const QCPLineEnding &ending);
  926. void setUpperEnding(const QCPLineEnding &ending);
  927. // reimplemented virtual methods:
  928. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  929. // non-virtual methods:
  930. Qt::Orientation orientation() const { return mOrientation; }
  931. void moveRange(double diff);
  932. void scaleRange(double factor, double center);
  933. void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
  934. void rescale(bool onlyVisiblePlottables=false);
  935. double pixelToCoord(double value) const;
  936. double coordToPixel(double value) const;
  937. SelectablePart getPartAt(const QPointF &pos) const;
  938. QList<QCPAbstractPlottable*> plottables() const;
  939. QList<QCPGraph*> graphs() const;
  940. QList<QCPAbstractItem*> items() const;
  941. static AxisType marginSideToAxisType(QCP::MarginSide side);
  942. signals:
  943. void ticksRequest();
  944. void rangeChanged(const QCPRange &newRange);
  945. void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
  946. void selectionChanged(const QCPAxis::SelectableParts &parts);
  947. protected:
  948. struct CachedLabel
  949. {
  950. QPointF offset;
  951. QPixmap pixmap;
  952. };
  953. struct TickLabelData
  954. {
  955. QString basePart, expPart;
  956. QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
  957. QFont baseFont, expFont;
  958. };
  959. // property members:
  960. // axis base:
  961. AxisType mAxisType;
  962. QCPAxisRect *mAxisRect;
  963. int mOffset, mPadding;
  964. Qt::Orientation mOrientation;
  965. SelectableParts mSelectableParts, mSelectedParts;
  966. QPen mBasePen, mSelectedBasePen;
  967. QCPLineEnding mLowerEnding, mUpperEnding;
  968. // axis label:
  969. int mLabelPadding;
  970. QString mLabel;
  971. QFont mLabelFont, mSelectedLabelFont;
  972. QColor mLabelColor, mSelectedLabelColor;
  973. // tick labels:
  974. int mTickLabelPadding;
  975. bool mTickLabels, mAutoTickLabels;
  976. double mTickLabelRotation;
  977. LabelType mTickLabelType;
  978. QFont mTickLabelFont, mSelectedTickLabelFont;
  979. QColor mTickLabelColor, mSelectedTickLabelColor;
  980. QString mDateTimeFormat;
  981. Qt::TimeSpec mDateTimeSpec;
  982. int mNumberPrecision;
  983. char mNumberFormatChar;
  984. bool mNumberBeautifulPowers;
  985. bool mNumberMultiplyCross;
  986. // ticks and subticks:
  987. bool mTicks;
  988. double mTickStep;
  989. int mSubTickCount, mAutoTickCount;
  990. bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
  991. int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut;
  992. QPen mTickPen, mSelectedTickPen;
  993. QPen mSubTickPen, mSelectedSubTickPen;
  994. // scale and range:
  995. QCPRange mRange;
  996. bool mRangeReversed;
  997. ScaleType mScaleType;
  998. double mScaleLogBase, mScaleLogBaseLogInv;
  999. // non-property members:
  1000. QCPGrid *mGrid;
  1001. QCache<QString, CachedLabel> mLabelCache;
  1002. int mLowestVisibleTick, mHighestVisibleTick;
  1003. QChar mExponentialChar, mPositiveSignChar;
  1004. QVector<double> mTickVector;
  1005. QVector<QString> mTickVectorLabels;
  1006. QVector<double> mSubTickVector;
  1007. QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
  1008. bool mCachedMarginValid;
  1009. int mCachedMargin;
  1010. // introduced virtual methods:
  1011. virtual void setupTickVectors();
  1012. virtual void generateAutoTicks();
  1013. virtual int calculateAutoSubTickCount(double tickStep) const;
  1014. virtual int calculateMargin();
  1015. // tick label drawing/caching:
  1016. virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
  1017. virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
  1018. virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
  1019. virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
  1020. virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
  1021. // reimplemented virtual methods:
  1022. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  1023. virtual void draw(QCPPainter *painter);
  1024. virtual QCP::Interaction selectionCategory() const;
  1025. // events:
  1026. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  1027. virtual void deselectEvent(bool *selectionStateChanged);
  1028. // non-virtual methods:
  1029. void visibleTickBounds(int &lowIndex, int &highIndex) const;
  1030. double baseLog(double value) const;
  1031. double basePow(double value) const;
  1032. QPen getBasePen() const;
  1033. QPen getTickPen() const;
  1034. QPen getSubTickPen() const;
  1035. QFont getTickLabelFont() const;
  1036. QFont getLabelFont() const;
  1037. QColor getTickLabelColor() const;
  1038. QColor getLabelColor() const;
  1039. private:
  1040. Q_DISABLE_COPY(QCPAxis)
  1041. friend class QCustomPlot;
  1042. friend class QCPGrid;
  1043. friend class QCPAxisRect;
  1044. };
  1045. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
  1046. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
  1047. Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
  1048. class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
  1049. {
  1050. Q_OBJECT
  1051. /// \cond INCLUDE_QPROPERTIES
  1052. Q_PROPERTY(QString name READ name WRITE setName)
  1053. Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
  1054. Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
  1055. Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
  1056. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1057. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1058. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  1059. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  1060. Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
  1061. Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
  1062. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
  1063. Q_PROPERTY(bool selected READ selected WRITE setSelected)
  1064. /// \endcond
  1065. public:
  1066. QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
  1067. // getters:
  1068. QString name() const { return mName; }
  1069. bool antialiasedFill() const { return mAntialiasedFill; }
  1070. bool antialiasedScatters() const { return mAntialiasedScatters; }
  1071. bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
  1072. QPen pen() const { return mPen; }
  1073. QPen selectedPen() const { return mSelectedPen; }
  1074. QBrush brush() const { return mBrush; }
  1075. QBrush selectedBrush() const { return mSelectedBrush; }
  1076. QCPAxis *keyAxis() const { return mKeyAxis.data(); }
  1077. QCPAxis *valueAxis() const { return mValueAxis.data(); }
  1078. bool selectable() const { return mSelectable; }
  1079. bool selected() const { return mSelected; }
  1080. // setters:
  1081. void setName(const QString &name);
  1082. void setAntialiasedFill(bool enabled);
  1083. void setAntialiasedScatters(bool enabled);
  1084. void setAntialiasedErrorBars(bool enabled);
  1085. void setPen(const QPen &pen);
  1086. void setSelectedPen(const QPen &pen);
  1087. void setBrush(const QBrush &brush);
  1088. void setSelectedBrush(const QBrush &brush);
  1089. void setKeyAxis(QCPAxis *axis);
  1090. void setValueAxis(QCPAxis *axis);
  1091. Q_SLOT void setSelectable(bool selectable);
  1092. Q_SLOT void setSelected(bool selected);
  1093. // introduced virtual methods:
  1094. virtual void clearData() = 0;
  1095. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
  1096. virtual bool addToLegend();
  1097. virtual bool removeFromLegend() const;
  1098. // non-property methods:
  1099. void rescaleAxes(bool onlyEnlarge=false) const;
  1100. void rescaleKeyAxis(bool onlyEnlarge=false) const;
  1101. void rescaleValueAxis(bool onlyEnlarge=false) const;
  1102. signals:
  1103. void selectionChanged(bool selected);
  1104. protected:
  1105. /*!
  1106. Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange.
  1107. */
  1108. enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
  1109. ,sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers
  1110. ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
  1111. };
  1112. // property members:
  1113. QString mName;
  1114. bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
  1115. QPen mPen, mSelectedPen;
  1116. QBrush mBrush, mSelectedBrush;
  1117. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  1118. bool mSelectable, mSelected;
  1119. // reimplemented virtual methods:
  1120. virtual QRect clipRect() const;
  1121. virtual void draw(QCPPainter *painter) = 0;
  1122. virtual QCP::Interaction selectionCategory() const;
  1123. void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  1124. // events:
  1125. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  1126. virtual void deselectEvent(bool *selectionStateChanged);
  1127. // introduced virtual methods:
  1128. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
  1129. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
  1130. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const = 0;
  1131. // non-virtual methods:
  1132. void coordsToPixels(double key, double value, double &x, double &y) const;
  1133. const QPointF coordsToPixels(double key, double value) const;
  1134. void pixelsToCoords(double x, double y, double &key, double &value) const;
  1135. void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
  1136. QPen mainPen() const;
  1137. QBrush mainBrush() const;
  1138. void applyFillAntialiasingHint(QCPPainter *painter) const;
  1139. void applyScattersAntialiasingHint(QCPPainter *painter) const;
  1140. void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
  1141. double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
  1142. private:
  1143. Q_DISABLE_COPY(QCPAbstractPlottable)
  1144. friend class QCustomPlot;
  1145. friend class QCPAxis;
  1146. friend class QCPPlottableLegendItem;
  1147. };
  1148. class QCP_LIB_DECL QCPItemAnchor
  1149. {
  1150. public:
  1151. QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
  1152. virtual ~QCPItemAnchor();
  1153. // getters:
  1154. QString name() const { return mName; }
  1155. virtual QPointF pixelPoint() const;
  1156. protected:
  1157. // property members:
  1158. QString mName;
  1159. // non-property members:
  1160. QCustomPlot *mParentPlot;
  1161. QCPAbstractItem *mParentItem;
  1162. int mAnchorId;
  1163. QSet<QCPItemPosition*> mChildren;
  1164. // introduced virtual methods:
  1165. virtual QCPItemPosition *toQCPItemPosition() { return 0; }
  1166. // non-virtual methods:
  1167. void addChild(QCPItemPosition* pos); // called from pos when this anchor is set as parent
  1168. void removeChild(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
  1169. private:
  1170. Q_DISABLE_COPY(QCPItemAnchor)
  1171. friend class QCPItemPosition;
  1172. };
  1173. class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
  1174. {
  1175. public:
  1176. /*!
  1177. Defines the ways an item position can be specified. Thus it defines what the numbers passed to
  1178. \ref setCoords actually mean.
  1179. \see setType
  1180. */
  1181. enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
  1182. ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size.
  1183. ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect).
  1184. ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
  1185. };
  1186. QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
  1187. virtual ~QCPItemPosition();
  1188. // getters:
  1189. PositionType type() const { return mPositionType; }
  1190. QCPItemAnchor *parentAnchor() const { return mParentAnchor; }
  1191. double key() const { return mKey; }
  1192. double value() const { return mValue; }
  1193. QPointF coords() const { return QPointF(mKey, mValue); }
  1194. QCPAxis *keyAxis() const { return mKeyAxis.data(); }
  1195. QCPAxis *valueAxis() const { return mValueAxis.data(); }
  1196. QCPAxisRect *axisRect() const;
  1197. virtual QPointF pixelPoint() const;
  1198. // setters:
  1199. void setType(PositionType type);
  1200. bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
  1201. void setCoords(double key, double value);
  1202. void setCoords(const QPointF &coords);
  1203. void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
  1204. void setAxisRect(QCPAxisRect *axisRect);
  1205. void setPixelPoint(const QPointF &pixelPoint);
  1206. protected:
  1207. // property members:
  1208. PositionType mPositionType;
  1209. QPointer<QCPAxis> mKeyAxis, mValueAxis;
  1210. QPointer<QCPAxisRect> mAxisRect;
  1211. double mKey, mValue;
  1212. QCPItemAnchor *mParentAnchor;
  1213. // reimplemented virtual methods:
  1214. virtual QCPItemPosition *toQCPItemPosition() { return this; }
  1215. private:
  1216. Q_DISABLE_COPY(QCPItemPosition)
  1217. };
  1218. class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
  1219. {
  1220. Q_OBJECT
  1221. /// \cond INCLUDE_QPROPERTIES
  1222. Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
  1223. Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
  1224. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
  1225. Q_PROPERTY(bool selected READ selected WRITE setSelected)
  1226. /// \endcond
  1227. public:
  1228. QCPAbstractItem(QCustomPlot *parentPlot);
  1229. virtual ~QCPAbstractItem();
  1230. // getters:
  1231. bool clipToAxisRect() const { return mClipToAxisRect; }
  1232. QCPAxisRect *clipAxisRect() const;
  1233. bool selectable() const { return mSelectable; }
  1234. bool selected() const { return mSelected; }
  1235. // setters:
  1236. void setClipToAxisRect(bool clip);
  1237. void setClipAxisRect(QCPAxisRect *rect);
  1238. void setSelectable(bool selectable);
  1239. void setSelected(bool selected);
  1240. // reimplemented virtual methods:
  1241. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
  1242. // non-virtual methods:
  1243. QList<QCPItemPosition*> positions() const { return mPositions; }
  1244. QList<QCPItemAnchor*> anchors() const { return mAnchors; }
  1245. QCPItemPosition *position(const QString &name) const;
  1246. QCPItemAnchor *anchor(const QString &name) const;
  1247. bool hasAnchor(const QString &name) const;
  1248. signals:
  1249. void selectionChanged(bool selected);
  1250. protected:
  1251. // property members:
  1252. bool mClipToAxisRect;
  1253. QPointer<QCPAxisRect> mClipAxisRect;
  1254. QList<QCPItemPosition*> mPositions;
  1255. QList<QCPItemAnchor*> mAnchors;
  1256. bool mSelectable, mSelected;
  1257. // reimplemented virtual methods:
  1258. virtual QCP::Interaction selectionCategory() const;
  1259. virtual QRect clipRect() const;
  1260. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  1261. virtual void draw(QCPPainter *painter) = 0;
  1262. // events:
  1263. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  1264. virtual void deselectEvent(bool *selectionStateChanged);
  1265. // introduced virtual methods:
  1266. virtual QPointF anchorPixelPoint(int anchorId) const;
  1267. // non-virtual methods:
  1268. double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
  1269. double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
  1270. QCPItemPosition *createPosition(const QString &name);
  1271. QCPItemAnchor *createAnchor(const QString &name, int anchorId);
  1272. private:
  1273. Q_DISABLE_COPY(QCPAbstractItem)
  1274. friend class QCustomPlot;
  1275. friend class QCPItemAnchor;
  1276. };
  1277. class QCP_LIB_DECL QCustomPlot : public QWidget
  1278. {
  1279. Q_OBJECT
  1280. /// \cond INCLUDE_QPROPERTIES
  1281. Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
  1282. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  1283. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  1284. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
  1285. Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
  1286. Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
  1287. Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
  1288. Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
  1289. Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
  1290. /// \endcond
  1291. public:
  1292. /*!
  1293. Defines how a layer should be inserted relative to an other layer.
  1294. \see addLayer, moveLayer
  1295. */
  1296. enum LayerInsertMode { limBelow ///< Layer is inserted below other layer
  1297. ,limAbove ///< Layer is inserted above other layer
  1298. };
  1299. Q_ENUMS(LayerInsertMode)
  1300. explicit QCustomPlot(QWidget *parent = 0);
  1301. virtual ~QCustomPlot();
  1302. // getters:
  1303. QRect viewport() const { return mViewport; }
  1304. QPixmap background() const { return mBackgroundPixmap; }
  1305. bool backgroundScaled() const { return mBackgroundScaled; }
  1306. Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
  1307. QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
  1308. QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
  1309. QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
  1310. bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
  1311. const QCP::Interactions interactions() const { return mInteractions; }
  1312. int selectionTolerance() const { return mSelectionTolerance; }
  1313. bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
  1314. QCP::PlottingHints plottingHints() const { return mPlottingHints; }
  1315. Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
  1316. // setters:
  1317. void setViewport(const QRect &rect);
  1318. void setBackground(const QPixmap &pm);
  1319. void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
  1320. void setBackground(const QBrush &brush);
  1321. void setBackgroundScaled(bool scaled);
  1322. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  1323. void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
  1324. void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
  1325. void setNotAntialiasedElements(const QCP::AntialiasedElements &notAntialiasedElements);
  1326. void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
  1327. void setAutoAddPlottableToLegend(bool on);
  1328. void setInteractions(const QCP::Interactions &interactions);
  1329. void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
  1330. void setSelectionTolerance(int pixels);
  1331. void setNoAntialiasingOnDrag(bool enabled);
  1332. void setPlottingHints(const QCP::PlottingHints &hints);
  1333. void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
  1334. void setMultiSelectModifier(Qt::KeyboardModifier modifier);
  1335. // non-property methods:
  1336. // plottable interface:
  1337. QCPAbstractPlottable *plottable(int index);
  1338. QCPAbstractPlottable *plottable();
  1339. bool addPlottable(QCPAbstractPlottable *plottable);
  1340. bool removePlottable(QCPAbstractPlottable *plottable);
  1341. bool removePlottable(int index);
  1342. int clearPlottables();
  1343. int plottableCount() const;
  1344. QList<QCPAbstractPlottable*> selectedPlottables() const;
  1345. QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
  1346. bool hasPlottable(QCPAbstractPlottable *plottable) const;
  1347. // specialized interface for QCPGraph:
  1348. QCPGraph *graph(int index) const;
  1349. QCPGraph *graph() const;
  1350. QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
  1351. bool removeGraph(QCPGraph *graph);
  1352. bool removeGraph(int index);
  1353. int clearGraphs();
  1354. int graphCount() const;
  1355. QList<QCPGraph*> selectedGraphs() const;
  1356. // item interface:
  1357. QCPAbstractItem *item(int index) const;
  1358. QCPAbstractItem *item() const;
  1359. bool addItem(QCPAbstractItem* item);
  1360. bool removeItem(QCPAbstractItem *item);
  1361. bool removeItem(int index);
  1362. int clearItems();
  1363. int itemCount() const;
  1364. QList<QCPAbstractItem*> selectedItems() const;
  1365. QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
  1366. bool hasItem(QCPAbstractItem *item) const;
  1367. // layer interface:
  1368. QCPLayer *layer(const QString &name) const;
  1369. QCPLayer *layer(int index) const;
  1370. QCPLayer *currentLayer() const;
  1371. bool setCurrentLayer(const QString &name);
  1372. bool setCurrentLayer(QCPLayer *layer);
  1373. int layerCount() const;
  1374. bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
  1375. bool removeLayer(QCPLayer *layer);
  1376. bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
  1377. // axis rect/layout interface:
  1378. int axisRectCount() const;
  1379. QCPAxisRect* axisRect(int index=0) const;
  1380. QList<QCPAxisRect*> axisRects() const;
  1381. QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
  1382. Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
  1383. QList<QCPAxis*> selectedAxes() const;
  1384. QList<QCPLegend*> selectedLegends() const;
  1385. Q_SLOT void deselectAll();
  1386. bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0);
  1387. bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
  1388. bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
  1389. bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
  1390. bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
  1391. QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
  1392. void toPainter(QCPPainter *painter, int width=0, int height=0);
  1393. Q_SLOT void replot();
  1394. QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
  1395. QCPLegend *legend;
  1396. signals:
  1397. void mouseDoubleClick(QMouseEvent *event);
  1398. void mousePress(QMouseEvent *event);
  1399. void mouseMove(QMouseEvent *event);
  1400. void mouseRelease(QMouseEvent *event);
  1401. void mouseWheel(QWheelEvent *event);
  1402. void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
  1403. void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
  1404. void itemClick(QCPAbstractItem *item, QMouseEvent *event);
  1405. void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
  1406. void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
  1407. void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
  1408. void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
  1409. void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
  1410. void titleClick(QMouseEvent *event, QCPPlotTitle *title);
  1411. void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
  1412. void selectionChangedByUser();
  1413. void beforeReplot();
  1414. void afterReplot();
  1415. protected:
  1416. // property members:
  1417. QRect mViewport;
  1418. QCPLayoutGrid *mPlotLayout;
  1419. bool mAutoAddPlottableToLegend;
  1420. QList<QCPAbstractPlottable*> mPlottables;
  1421. QList<QCPGraph*> mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
  1422. QList<QCPAbstractItem*> mItems;
  1423. QList<QCPLayer*> mLayers;
  1424. QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
  1425. QCP::Interactions mInteractions;
  1426. int mSelectionTolerance;
  1427. bool mNoAntialiasingOnDrag;
  1428. QBrush mBackgroundBrush;
  1429. QPixmap mBackgroundPixmap;
  1430. QPixmap mScaledBackgroundPixmap;
  1431. bool mBackgroundScaled;
  1432. Qt::AspectRatioMode mBackgroundScaledMode;
  1433. QCPLayer *mCurrentLayer;
  1434. QCP::PlottingHints mPlottingHints;
  1435. Qt::KeyboardModifier mMultiSelectModifier;
  1436. // non-property members:
  1437. QPixmap mPaintBuffer;
  1438. QPoint mMousePressPos;
  1439. QCPLayoutElement *mMouseEventElement;
  1440. bool mReplotting;
  1441. // reimplemented virtual methods:
  1442. virtual QSize minimumSizeHint() const;
  1443. virtual QSize sizeHint() const;
  1444. virtual void paintEvent(QPaintEvent *event);
  1445. virtual void resizeEvent(QResizeEvent *event);
  1446. virtual void mouseDoubleClickEvent(QMouseEvent *event);
  1447. virtual void mousePressEvent(QMouseEvent *event);
  1448. virtual void mouseMoveEvent(QMouseEvent *event);
  1449. virtual void mouseReleaseEvent(QMouseEvent *event);
  1450. virtual void wheelEvent(QWheelEvent *event);
  1451. // introduced virtual methods:
  1452. virtual void draw(QCPPainter *painter);
  1453. virtual void axisRemoved(QCPAxis *axis);
  1454. virtual void legendRemoved(QCPLegend *legend);
  1455. // non-virtual methods:
  1456. void updateLayerIndices() const;
  1457. QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
  1458. void drawBackground(QCPPainter *painter);
  1459. friend class QCPLegend;
  1460. friend class QCPAxis;
  1461. friend class QCPLayer;
  1462. friend class QCPAxisRect;
  1463. };
  1464. /*! \file */
  1465. class QCP_LIB_DECL QCPData
  1466. {
  1467. public:
  1468. QCPData();
  1469. QCPData(double key, double value);
  1470. double key, value;
  1471. double keyErrorPlus, keyErrorMinus;
  1472. double valueErrorPlus, valueErrorMinus;
  1473. };
  1474. Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
  1475. /*! \typedef QCPDataMap
  1476. Container for storing QCPData items in a sorted fashion. The key of the map
  1477. is the key member of the QCPData instance.
  1478. This is the container in which QCPGraph holds its data.
  1479. \see QCPData, QCPGraph::setData
  1480. */
  1481. typedef QMap<double, QCPData> QCPDataMap;
  1482. typedef QMapIterator<double, QCPData> QCPDataMapIterator;
  1483. typedef QMutableMapIterator<double, QCPData> QCPDataMutableMapIterator;
  1484. class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
  1485. {
  1486. Q_OBJECT
  1487. /// \cond INCLUDE_QPROPERTIES
  1488. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  1489. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  1490. Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
  1491. Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
  1492. Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
  1493. Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
  1494. Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
  1495. /// \endcond
  1496. public:
  1497. /*!
  1498. Defines how the graph's line is represented visually in the plot. The line is drawn with the
  1499. current pen of the graph (\ref setPen).
  1500. \see setLineStyle
  1501. */
  1502. enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
  1503. ///< with symbols according to the scatter style, see \ref setScatterStyle)
  1504. ,lsLine ///< data points are connected by a straight line
  1505. ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point
  1506. ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point
  1507. ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
  1508. ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line
  1509. };
  1510. Q_ENUMS(LineStyle)
  1511. /*!
  1512. Defines what kind of error bars are drawn for each data point
  1513. */
  1514. enum ErrorType { etNone ///< No error bars are shown
  1515. ,etKey ///< Error bars for the key dimension of the data point are shown
  1516. ,etValue ///< Error bars for the value dimension of the data point are shown
  1517. ,etBoth ///< Error bars for both key and value dimensions of the data point are shown
  1518. };
  1519. Q_ENUMS(ErrorType)
  1520. explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
  1521. virtual ~QCPGraph();
  1522. // getters:
  1523. const QCPDataMap *data() const { return mData; }
  1524. LineStyle lineStyle() const { return mLineStyle; }
  1525. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  1526. ErrorType errorType() const { return mErrorType; }
  1527. QPen errorPen() const { return mErrorPen; }
  1528. double errorBarSize() const { return mErrorBarSize; }
  1529. bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
  1530. QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
  1531. // setters:
  1532. void setData(QCPDataMap *data, bool copy=false);
  1533. void setData(const QVector<double> &key, const QVector<double> &value);
  1534. void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError);
  1535. void setDataKeyError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus);
  1536. void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueError);
  1537. void setDataValueError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
  1538. void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyError, const QVector<double> &valueError);
  1539. void setDataBothError(const QVector<double> &key, const QVector<double> &value, const QVector<double> &keyErrorMinus, const QVector<double> &keyErrorPlus, const QVector<double> &valueErrorMinus, const QVector<double> &valueErrorPlus);
  1540. void setLineStyle(LineStyle ls);
  1541. void setScatterStyle(const QCPScatterStyle &style);
  1542. void setErrorType(ErrorType errorType);
  1543. void setErrorPen(const QPen &pen);
  1544. void setErrorBarSize(double size);
  1545. void setErrorBarSkipSymbol(bool enabled);
  1546. void setChannelFillGraph(QCPGraph *targetGraph);
  1547. // non-property methods:
  1548. void addData(const QCPDataMap &dataMap);
  1549. void addData(const QCPData &data);
  1550. void addData(double key, double value);
  1551. void addData(const QVector<double> &keys, const QVector<double> &values);
  1552. void removeDataBefore(double key);
  1553. void removeDataAfter(double key);
  1554. void removeData(double fromKey, double toKey);
  1555. void removeData(double key);
  1556. // reimplemented virtual methods:
  1557. virtual void clearData();
  1558. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1559. using QCPAbstractPlottable::rescaleAxes;
  1560. using QCPAbstractPlottable::rescaleKeyAxis;
  1561. using QCPAbstractPlottable::rescaleValueAxis;
  1562. void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
  1563. void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
  1564. void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
  1565. protected:
  1566. // property members:
  1567. QCPDataMap *mData;
  1568. QPen mErrorPen;
  1569. LineStyle mLineStyle;
  1570. QCPScatterStyle mScatterStyle;
  1571. ErrorType mErrorType;
  1572. double mErrorBarSize;
  1573. bool mErrorBarSkipSymbol;
  1574. QPointer<QCPGraph> mChannelFillGraph;
  1575. // reimplemented virtual methods:
  1576. virtual void draw(QCPPainter *painter);
  1577. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
  1578. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1579. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1580. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
  1581. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
  1582. // introduced virtual methods:
  1583. virtual void drawFill(QCPPainter *painter, QVector<QPointF> *lineData) const;
  1584. virtual void drawScatterPlot(QCPPainter *painter, QVector<QCPData> *pointData) const;
  1585. virtual void drawLinePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
  1586. virtual void drawImpulsePlot(QCPPainter *painter, QVector<QPointF> *lineData) const;
  1587. // non-virtual methods:
  1588. void getPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1589. void getScatterPlotData(QVector<QCPData> *pointData) const;
  1590. void getLinePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1591. void getStepLeftPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1592. void getStepRightPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1593. void getStepCenterPlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1594. void getImpulsePlotData(QVector<QPointF> *lineData, QVector<QCPData> *pointData) const;
  1595. void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
  1596. void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper, int &count) const;
  1597. void addFillBasePoints(QVector<QPointF> *lineData) const;
  1598. void removeFillBasePoints(QVector<QPointF> *lineData) const;
  1599. QPointF lowerFillBasePoint(double lowerKey) const;
  1600. QPointF upperFillBasePoint(double upperKey) const;
  1601. const QPolygonF getChannelFillPolygon(const QVector<QPointF> *lineData) const;
  1602. int findIndexBelowX(const QVector<QPointF> *data, double x) const;
  1603. int findIndexAboveX(const QVector<QPointF> *data, double x) const;
  1604. int findIndexBelowY(const QVector<QPointF> *data, double y) const;
  1605. int findIndexAboveY(const QVector<QPointF> *data, double y) const;
  1606. double pointDistance(const QPointF &pixelPoint) const;
  1607. friend class QCustomPlot;
  1608. friend class QCPLegend;
  1609. };
  1610. /*! \file */
  1611. class QCP_LIB_DECL QCPCurveData
  1612. {
  1613. public:
  1614. QCPCurveData();
  1615. QCPCurveData(double t, double key, double value);
  1616. double t, key, value;
  1617. };
  1618. Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
  1619. /*! \typedef QCPCurveDataMap
  1620. Container for storing QCPCurveData items in a sorted fashion. The key of the map
  1621. is the t member of the QCPCurveData instance.
  1622. This is the container in which QCPCurve holds its data.
  1623. \see QCPCurveData, QCPCurve::setData
  1624. */
  1625. typedef QMap<double, QCPCurveData> QCPCurveDataMap;
  1626. typedef QMapIterator<double, QCPCurveData> QCPCurveDataMapIterator;
  1627. typedef QMutableMapIterator<double, QCPCurveData> QCPCurveDataMutableMapIterator;
  1628. class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
  1629. {
  1630. Q_OBJECT
  1631. /// \cond INCLUDE_QPROPERTIES
  1632. Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
  1633. Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
  1634. /// \endcond
  1635. public:
  1636. /*!
  1637. Defines how the curve's line is represented visually in the plot. The line is drawn with the
  1638. current pen of the curve (\ref setPen).
  1639. \see setLineStyle
  1640. */
  1641. enum LineStyle { lsNone, ///< No line is drawn between data points (e.g. only scatters)
  1642. lsLine ///< Data points are connected with a straight line
  1643. };
  1644. explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
  1645. virtual ~QCPCurve();
  1646. // getters:
  1647. QCPCurveDataMap *data() const { return mData; }
  1648. QCPScatterStyle scatterStyle() const { return mScatterStyle; }
  1649. LineStyle lineStyle() const { return mLineStyle; }
  1650. // setters:
  1651. void setData(QCPCurveDataMap *data, bool copy=false);
  1652. void setData(const QVector<double> &t, const QVector<double> &key, const QVector<double> &value);
  1653. void setData(const QVector<double> &key, const QVector<double> &value);
  1654. void setScatterStyle(const QCPScatterStyle &style);
  1655. void setLineStyle(LineStyle style);
  1656. // non-property methods:
  1657. void addData(const QCPCurveDataMap &dataMap);
  1658. void addData(const QCPCurveData &data);
  1659. void addData(double t, double key, double value);
  1660. void addData(double key, double value);
  1661. void addData(const QVector<double> &ts, const QVector<double> &keys, const QVector<double> &values);
  1662. void removeDataBefore(double t);
  1663. void removeDataAfter(double t);
  1664. void removeData(double fromt, double tot);
  1665. void removeData(double t);
  1666. // reimplemented virtual methods:
  1667. virtual void clearData();
  1668. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1669. protected:
  1670. // property members:
  1671. QCPCurveDataMap *mData;
  1672. QCPScatterStyle mScatterStyle;
  1673. LineStyle mLineStyle;
  1674. // reimplemented virtual methods:
  1675. virtual void draw(QCPPainter *painter);
  1676. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
  1677. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1678. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1679. // introduced virtual methods:
  1680. virtual void drawScatterPlot(QCPPainter *painter, const QVector<QPointF> *pointData) const;
  1681. // non-virtual methods:
  1682. void getCurveData(QVector<QPointF> *lineData) const;
  1683. double pointDistance(const QPointF &pixelPoint) const;
  1684. QPointF outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const;
  1685. friend class QCustomPlot;
  1686. friend class QCPLegend;
  1687. };
  1688. /*! \file */
  1689. class QCP_LIB_DECL QCPBarData
  1690. {
  1691. public:
  1692. QCPBarData();
  1693. QCPBarData(double key, double value);
  1694. double key, value;
  1695. };
  1696. Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
  1697. /*! \typedef QCPBarDataMap
  1698. Container for storing QCPBarData items in a sorted fashion. The key of the map
  1699. is the key member of the QCPBarData instance.
  1700. This is the container in which QCPBars holds its data.
  1701. \see QCPBarData, QCPBars::setData
  1702. */
  1703. typedef QMap<double, QCPBarData> QCPBarDataMap;
  1704. typedef QMapIterator<double, QCPBarData> QCPBarDataMapIterator;
  1705. typedef QMutableMapIterator<double, QCPBarData> QCPBarDataMutableMapIterator;
  1706. class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
  1707. {
  1708. Q_OBJECT
  1709. /// \cond INCLUDE_QPROPERTIES
  1710. Q_PROPERTY(double width READ width WRITE setWidth)
  1711. Q_PROPERTY(QCPBars* barBelow READ barBelow)
  1712. Q_PROPERTY(QCPBars* barAbove READ barAbove)
  1713. /// \endcond
  1714. public:
  1715. explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
  1716. virtual ~QCPBars();
  1717. // getters:
  1718. double width() const { return mWidth; }
  1719. QCPBars *barBelow() const { return mBarBelow.data(); }
  1720. QCPBars *barAbove() const { return mBarAbove.data(); }
  1721. QCPBarDataMap *data() const { return mData; }
  1722. // setters:
  1723. void setWidth(double width);
  1724. void setData(QCPBarDataMap *data, bool copy=false);
  1725. void setData(const QVector<double> &key, const QVector<double> &value);
  1726. // non-property methods:
  1727. void moveBelow(QCPBars *bars);
  1728. void moveAbove(QCPBars *bars);
  1729. void addData(const QCPBarDataMap &dataMap);
  1730. void addData(const QCPBarData &data);
  1731. void addData(double key, double value);
  1732. void addData(const QVector<double> &keys, const QVector<double> &values);
  1733. void removeDataBefore(double key);
  1734. void removeDataAfter(double key);
  1735. void removeData(double fromKey, double toKey);
  1736. void removeData(double key);
  1737. // reimplemented virtual methods:
  1738. virtual void clearData();
  1739. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1740. protected:
  1741. // property members:
  1742. QCPBarDataMap *mData;
  1743. double mWidth;
  1744. QPointer<QCPBars> mBarBelow, mBarAbove;
  1745. // reimplemented virtual methods:
  1746. virtual void draw(QCPPainter *painter);
  1747. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
  1748. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1749. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1750. // non-virtual methods:
  1751. QPolygonF getBarPolygon(double key, double value) const;
  1752. double getBaseValue(double key, bool positive) const;
  1753. static void connectBars(QCPBars* lower, QCPBars* upper);
  1754. friend class QCustomPlot;
  1755. friend class QCPLegend;
  1756. };
  1757. /*! \file */
  1758. class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
  1759. {
  1760. Q_OBJECT
  1761. /// \cond INCLUDE_QPROPERTIES
  1762. Q_PROPERTY(double key READ key WRITE setKey)
  1763. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  1764. Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
  1765. Q_PROPERTY(double median READ median WRITE setMedian)
  1766. Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
  1767. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  1768. Q_PROPERTY(QVector<double> outliers READ outliers WRITE setOutliers)
  1769. Q_PROPERTY(double width READ width WRITE setWidth)
  1770. Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
  1771. Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
  1772. Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
  1773. Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
  1774. Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
  1775. /// \endcond
  1776. public:
  1777. explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
  1778. // getters:
  1779. double key() const { return mKey; }
  1780. double minimum() const { return mMinimum; }
  1781. double lowerQuartile() const { return mLowerQuartile; }
  1782. double median() const { return mMedian; }
  1783. double upperQuartile() const { return mUpperQuartile; }
  1784. double maximum() const { return mMaximum; }
  1785. QVector<double> outliers() const { return mOutliers; }
  1786. double width() const { return mWidth; }
  1787. double whiskerWidth() const { return mWhiskerWidth; }
  1788. QPen whiskerPen() const { return mWhiskerPen; }
  1789. QPen whiskerBarPen() const { return mWhiskerBarPen; }
  1790. QPen medianPen() const { return mMedianPen; }
  1791. QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
  1792. // setters:
  1793. void setKey(double key);
  1794. void setMinimum(double value);
  1795. void setLowerQuartile(double value);
  1796. void setMedian(double value);
  1797. void setUpperQuartile(double value);
  1798. void setMaximum(double value);
  1799. void setOutliers(const QVector<double> &values);
  1800. void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
  1801. void setWidth(double width);
  1802. void setWhiskerWidth(double width);
  1803. void setWhiskerPen(const QPen &pen);
  1804. void setWhiskerBarPen(const QPen &pen);
  1805. void setMedianPen(const QPen &pen);
  1806. void setOutlierStyle(const QCPScatterStyle &style);
  1807. // non-property methods:
  1808. virtual void clearData();
  1809. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1810. protected:
  1811. // property members:
  1812. QVector<double> mOutliers;
  1813. double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
  1814. double mWidth;
  1815. double mWhiskerWidth;
  1816. QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
  1817. QCPScatterStyle mOutlierStyle;
  1818. // reimplemented virtual methods:
  1819. virtual void draw(QCPPainter *painter);
  1820. virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
  1821. virtual QCPRange getKeyRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1822. virtual QCPRange getValueRange(bool &validRange, SignDomain inSignDomain=sdBoth) const;
  1823. // introduced virtual methods:
  1824. virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
  1825. virtual void drawMedian(QCPPainter *painter) const;
  1826. virtual void drawWhiskers(QCPPainter *painter) const;
  1827. virtual void drawOutliers(QCPPainter *painter) const;
  1828. friend class QCustomPlot;
  1829. friend class QCPLegend;
  1830. };
  1831. class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
  1832. {
  1833. Q_OBJECT
  1834. /// \cond INCLUDE_QPROPERTIES
  1835. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1836. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1837. /// \endcond
  1838. public:
  1839. QCPItemStraightLine(QCustomPlot *parentPlot);
  1840. virtual ~QCPItemStraightLine();
  1841. // getters:
  1842. QPen pen() const { return mPen; }
  1843. QPen selectedPen() const { return mSelectedPen; }
  1844. // setters;
  1845. void setPen(const QPen &pen);
  1846. void setSelectedPen(const QPen &pen);
  1847. // reimplemented virtual methods:
  1848. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1849. QCPItemPosition * const point1;
  1850. QCPItemPosition * const point2;
  1851. protected:
  1852. // property members:
  1853. QPen mPen, mSelectedPen;
  1854. // reimplemented virtual methods:
  1855. virtual void draw(QCPPainter *painter);
  1856. // non-virtual methods:
  1857. double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
  1858. QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
  1859. QPen mainPen() const;
  1860. };
  1861. class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
  1862. {
  1863. Q_OBJECT
  1864. /// \cond INCLUDE_QPROPERTIES
  1865. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1866. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1867. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  1868. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  1869. /// \endcond
  1870. public:
  1871. QCPItemLine(QCustomPlot *parentPlot);
  1872. virtual ~QCPItemLine();
  1873. // getters:
  1874. QPen pen() const { return mPen; }
  1875. QPen selectedPen() const { return mSelectedPen; }
  1876. QCPLineEnding head() const { return mHead; }
  1877. QCPLineEnding tail() const { return mTail; }
  1878. // setters;
  1879. void setPen(const QPen &pen);
  1880. void setSelectedPen(const QPen &pen);
  1881. void setHead(const QCPLineEnding &head);
  1882. void setTail(const QCPLineEnding &tail);
  1883. // reimplemented virtual methods:
  1884. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1885. QCPItemPosition * const start;
  1886. QCPItemPosition * const end;
  1887. protected:
  1888. // property members:
  1889. QPen mPen, mSelectedPen;
  1890. QCPLineEnding mHead, mTail;
  1891. // reimplemented virtual methods:
  1892. virtual void draw(QCPPainter *painter);
  1893. // non-virtual methods:
  1894. QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
  1895. QPen mainPen() const;
  1896. };
  1897. class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
  1898. {
  1899. Q_OBJECT
  1900. /// \cond INCLUDE_QPROPERTIES
  1901. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1902. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1903. Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
  1904. Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
  1905. /// \endcond
  1906. public:
  1907. QCPItemCurve(QCustomPlot *parentPlot);
  1908. virtual ~QCPItemCurve();
  1909. // getters:
  1910. QPen pen() const { return mPen; }
  1911. QPen selectedPen() const { return mSelectedPen; }
  1912. QCPLineEnding head() const { return mHead; }
  1913. QCPLineEnding tail() const { return mTail; }
  1914. // setters;
  1915. void setPen(const QPen &pen);
  1916. void setSelectedPen(const QPen &pen);
  1917. void setHead(const QCPLineEnding &head);
  1918. void setTail(const QCPLineEnding &tail);
  1919. // reimplemented virtual methods:
  1920. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1921. QCPItemPosition * const start;
  1922. QCPItemPosition * const startDir;
  1923. QCPItemPosition * const endDir;
  1924. QCPItemPosition * const end;
  1925. protected:
  1926. // property members:
  1927. QPen mPen, mSelectedPen;
  1928. QCPLineEnding mHead, mTail;
  1929. // reimplemented virtual methods:
  1930. virtual void draw(QCPPainter *painter);
  1931. // non-virtual methods:
  1932. QPen mainPen() const;
  1933. };
  1934. class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
  1935. {
  1936. Q_OBJECT
  1937. /// \cond INCLUDE_QPROPERTIES
  1938. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1939. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1940. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  1941. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  1942. /// \endcond
  1943. public:
  1944. QCPItemRect(QCustomPlot *parentPlot);
  1945. virtual ~QCPItemRect();
  1946. // getters:
  1947. QPen pen() const { return mPen; }
  1948. QPen selectedPen() const { return mSelectedPen; }
  1949. QBrush brush() const { return mBrush; }
  1950. QBrush selectedBrush() const { return mSelectedBrush; }
  1951. // setters;
  1952. void setPen(const QPen &pen);
  1953. void setSelectedPen(const QPen &pen);
  1954. void setBrush(const QBrush &brush);
  1955. void setSelectedBrush(const QBrush &brush);
  1956. // reimplemented virtual methods:
  1957. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  1958. QCPItemPosition * const topLeft;
  1959. QCPItemPosition * const bottomRight;
  1960. QCPItemAnchor * const top;
  1961. QCPItemAnchor * const topRight;
  1962. QCPItemAnchor * const right;
  1963. QCPItemAnchor * const bottom;
  1964. QCPItemAnchor * const bottomLeft;
  1965. QCPItemAnchor * const left;
  1966. protected:
  1967. enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
  1968. // property members:
  1969. QPen mPen, mSelectedPen;
  1970. QBrush mBrush, mSelectedBrush;
  1971. // reimplemented virtual methods:
  1972. virtual void draw(QCPPainter *painter);
  1973. virtual QPointF anchorPixelPoint(int anchorId) const;
  1974. // non-virtual methods:
  1975. QPen mainPen() const;
  1976. QBrush mainBrush() const;
  1977. };
  1978. class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
  1979. {
  1980. Q_OBJECT
  1981. /// \cond INCLUDE_QPROPERTIES
  1982. Q_PROPERTY(QColor color READ color WRITE setColor)
  1983. Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
  1984. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  1985. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  1986. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  1987. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  1988. Q_PROPERTY(QFont font READ font WRITE setFont)
  1989. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  1990. Q_PROPERTY(QString text READ text WRITE setText)
  1991. Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
  1992. Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
  1993. Q_PROPERTY(double rotation READ rotation WRITE setRotation)
  1994. Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
  1995. /// \endcond
  1996. public:
  1997. QCPItemText(QCustomPlot *parentPlot);
  1998. virtual ~QCPItemText();
  1999. // getters:
  2000. QColor color() const { return mColor; }
  2001. QColor selectedColor() const { return mSelectedColor; }
  2002. QPen pen() const { return mPen; }
  2003. QPen selectedPen() const { return mSelectedPen; }
  2004. QBrush brush() const { return mBrush; }
  2005. QBrush selectedBrush() const { return mSelectedBrush; }
  2006. QFont font() const { return mFont; }
  2007. QFont selectedFont() const { return mSelectedFont; }
  2008. QString text() const { return mText; }
  2009. Qt::Alignment positionAlignment() const { return mPositionAlignment; }
  2010. Qt::Alignment textAlignment() const { return mTextAlignment; }
  2011. double rotation() const { return mRotation; }
  2012. QMargins padding() const { return mPadding; }
  2013. // setters;
  2014. void setColor(const QColor &color);
  2015. void setSelectedColor(const QColor &color);
  2016. void setPen(const QPen &pen);
  2017. void setSelectedPen(const QPen &pen);
  2018. void setBrush(const QBrush &brush);
  2019. void setSelectedBrush(const QBrush &brush);
  2020. void setFont(const QFont &font);
  2021. void setSelectedFont(const QFont &font);
  2022. void setText(const QString &text);
  2023. void setPositionAlignment(Qt::Alignment alignment);
  2024. void setTextAlignment(Qt::Alignment alignment);
  2025. void setRotation(double degrees);
  2026. void setPadding(const QMargins &padding);
  2027. // reimplemented virtual methods:
  2028. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2029. QCPItemPosition * const position;
  2030. QCPItemAnchor * const topLeft;
  2031. QCPItemAnchor * const top;
  2032. QCPItemAnchor * const topRight;
  2033. QCPItemAnchor * const right;
  2034. QCPItemAnchor * const bottomRight;
  2035. QCPItemAnchor * const bottom;
  2036. QCPItemAnchor * const bottomLeft;
  2037. QCPItemAnchor * const left;
  2038. protected:
  2039. enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
  2040. // property members:
  2041. QColor mColor, mSelectedColor;
  2042. QPen mPen, mSelectedPen;
  2043. QBrush mBrush, mSelectedBrush;
  2044. QFont mFont, mSelectedFont;
  2045. QString mText;
  2046. Qt::Alignment mPositionAlignment;
  2047. Qt::Alignment mTextAlignment;
  2048. double mRotation;
  2049. QMargins mPadding;
  2050. // reimplemented virtual methods:
  2051. virtual void draw(QCPPainter *painter);
  2052. virtual QPointF anchorPixelPoint(int anchorId) const;
  2053. // non-virtual methods:
  2054. QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
  2055. QFont mainFont() const;
  2056. QColor mainColor() const;
  2057. QPen mainPen() const;
  2058. QBrush mainBrush() const;
  2059. };
  2060. class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
  2061. {
  2062. Q_OBJECT
  2063. /// \cond INCLUDE_QPROPERTIES
  2064. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  2065. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  2066. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  2067. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  2068. /// \endcond
  2069. public:
  2070. QCPItemEllipse(QCustomPlot *parentPlot);
  2071. virtual ~QCPItemEllipse();
  2072. // getters:
  2073. QPen pen() const { return mPen; }
  2074. QPen selectedPen() const { return mSelectedPen; }
  2075. QBrush brush() const { return mBrush; }
  2076. QBrush selectedBrush() const { return mSelectedBrush; }
  2077. // setters;
  2078. void setPen(const QPen &pen);
  2079. void setSelectedPen(const QPen &pen);
  2080. void setBrush(const QBrush &brush);
  2081. void setSelectedBrush(const QBrush &brush);
  2082. // reimplemented virtual methods:
  2083. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2084. QCPItemPosition * const topLeft;
  2085. QCPItemPosition * const bottomRight;
  2086. QCPItemAnchor * const topLeftRim;
  2087. QCPItemAnchor * const top;
  2088. QCPItemAnchor * const topRightRim;
  2089. QCPItemAnchor * const right;
  2090. QCPItemAnchor * const bottomRightRim;
  2091. QCPItemAnchor * const bottom;
  2092. QCPItemAnchor * const bottomLeftRim;
  2093. QCPItemAnchor * const left;
  2094. QCPItemAnchor * const center;
  2095. protected:
  2096. enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
  2097. // property members:
  2098. QPen mPen, mSelectedPen;
  2099. QBrush mBrush, mSelectedBrush;
  2100. // reimplemented virtual methods:
  2101. virtual void draw(QCPPainter *painter);
  2102. virtual QPointF anchorPixelPoint(int anchorId) const;
  2103. // non-virtual methods:
  2104. QPen mainPen() const;
  2105. QBrush mainBrush() const;
  2106. };
  2107. class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
  2108. {
  2109. Q_OBJECT
  2110. /// \cond INCLUDE_QPROPERTIES
  2111. Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
  2112. Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
  2113. Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
  2114. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  2115. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  2116. /// \endcond
  2117. public:
  2118. QCPItemPixmap(QCustomPlot *parentPlot);
  2119. virtual ~QCPItemPixmap();
  2120. // getters:
  2121. QPixmap pixmap() const { return mPixmap; }
  2122. bool scaled() const { return mScaled; }
  2123. Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
  2124. QPen pen() const { return mPen; }
  2125. QPen selectedPen() const { return mSelectedPen; }
  2126. // setters;
  2127. void setPixmap(const QPixmap &pixmap);
  2128. void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
  2129. void setPen(const QPen &pen);
  2130. void setSelectedPen(const QPen &pen);
  2131. // reimplemented virtual methods:
  2132. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2133. QCPItemPosition * const topLeft;
  2134. QCPItemPosition * const bottomRight;
  2135. QCPItemAnchor * const top;
  2136. QCPItemAnchor * const topRight;
  2137. QCPItemAnchor * const right;
  2138. QCPItemAnchor * const bottom;
  2139. QCPItemAnchor * const bottomLeft;
  2140. QCPItemAnchor * const left;
  2141. protected:
  2142. enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
  2143. // property members:
  2144. QPixmap mPixmap;
  2145. QPixmap mScaledPixmap;
  2146. bool mScaled;
  2147. Qt::AspectRatioMode mAspectRatioMode;
  2148. QPen mPen, mSelectedPen;
  2149. // reimplemented virtual methods:
  2150. virtual void draw(QCPPainter *painter);
  2151. virtual QPointF anchorPixelPoint(int anchorId) const;
  2152. // non-virtual methods:
  2153. void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
  2154. QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
  2155. QPen mainPen() const;
  2156. };
  2157. class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
  2158. {
  2159. Q_OBJECT
  2160. /// \cond INCLUDE_QPROPERTIES
  2161. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  2162. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  2163. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  2164. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  2165. Q_PROPERTY(double size READ size WRITE setSize)
  2166. Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
  2167. Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
  2168. Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
  2169. Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
  2170. /// \endcond
  2171. public:
  2172. /*!
  2173. The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
  2174. \see setStyle
  2175. */
  2176. enum TracerStyle { tsNone ///< The tracer is not visible
  2177. ,tsPlus ///< A plus shaped crosshair with limited size
  2178. ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
  2179. ,tsCircle ///< A circle
  2180. ,tsSquare ///< A square
  2181. };
  2182. Q_ENUMS(TracerStyle)
  2183. QCPItemTracer(QCustomPlot *parentPlot);
  2184. virtual ~QCPItemTracer();
  2185. // getters:
  2186. QPen pen() const { return mPen; }
  2187. QPen selectedPen() const { return mSelectedPen; }
  2188. QBrush brush() const { return mBrush; }
  2189. QBrush selectedBrush() const { return mSelectedBrush; }
  2190. double size() const { return mSize; }
  2191. TracerStyle style() const { return mStyle; }
  2192. QCPGraph *graph() const { return mGraph; }
  2193. double graphKey() const { return mGraphKey; }
  2194. bool interpolating() const { return mInterpolating; }
  2195. // setters;
  2196. void setPen(const QPen &pen);
  2197. void setSelectedPen(const QPen &pen);
  2198. void setBrush(const QBrush &brush);
  2199. void setSelectedBrush(const QBrush &brush);
  2200. void setSize(double size);
  2201. void setStyle(TracerStyle style);
  2202. void setGraph(QCPGraph *graph);
  2203. void setGraphKey(double key);
  2204. void setInterpolating(bool enabled);
  2205. // reimplemented virtual methods:
  2206. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2207. // non-virtual methods:
  2208. void updatePosition();
  2209. QCPItemPosition * const position;
  2210. protected:
  2211. // property members:
  2212. QPen mPen, mSelectedPen;
  2213. QBrush mBrush, mSelectedBrush;
  2214. double mSize;
  2215. TracerStyle mStyle;
  2216. QCPGraph *mGraph;
  2217. double mGraphKey;
  2218. bool mInterpolating;
  2219. // reimplemented virtual methods:
  2220. virtual void draw(QCPPainter *painter);
  2221. // non-virtual methods:
  2222. QPen mainPen() const;
  2223. QBrush mainBrush() const;
  2224. };
  2225. class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
  2226. {
  2227. Q_OBJECT
  2228. /// \cond INCLUDE_QPROPERTIES
  2229. Q_PROPERTY(QPen pen READ pen WRITE setPen)
  2230. Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
  2231. Q_PROPERTY(double length READ length WRITE setLength)
  2232. Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
  2233. /// \endcond
  2234. public:
  2235. enum BracketStyle { bsSquare ///< A brace with angled edges
  2236. ,bsRound ///< A brace with round edges
  2237. ,bsCurly ///< A curly brace
  2238. ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
  2239. };
  2240. QCPItemBracket(QCustomPlot *parentPlot);
  2241. virtual ~QCPItemBracket();
  2242. // getters:
  2243. QPen pen() const { return mPen; }
  2244. QPen selectedPen() const { return mSelectedPen; }
  2245. double length() const { return mLength; }
  2246. BracketStyle style() const { return mStyle; }
  2247. // setters;
  2248. void setPen(const QPen &pen);
  2249. void setSelectedPen(const QPen &pen);
  2250. void setLength(double length);
  2251. void setStyle(BracketStyle style);
  2252. // reimplemented virtual methods:
  2253. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2254. QCPItemPosition * const left;
  2255. QCPItemPosition * const right;
  2256. QCPItemAnchor * const center;
  2257. protected:
  2258. // property members:
  2259. enum AnchorIndex {aiCenter};
  2260. QPen mPen, mSelectedPen;
  2261. double mLength;
  2262. BracketStyle mStyle;
  2263. // reimplemented virtual methods:
  2264. virtual void draw(QCPPainter *painter);
  2265. virtual QPointF anchorPixelPoint(int anchorId) const;
  2266. // non-virtual methods:
  2267. QPen mainPen() const;
  2268. };
  2269. class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
  2270. {
  2271. Q_OBJECT
  2272. /// \cond INCLUDE_QPROPERTIES
  2273. Q_PROPERTY(QPixmap background READ background WRITE setBackground)
  2274. Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
  2275. Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
  2276. Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
  2277. Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
  2278. /// \endcond
  2279. public:
  2280. explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
  2281. virtual ~QCPAxisRect();
  2282. // getters:
  2283. QPixmap background() const { return mBackgroundPixmap; }
  2284. bool backgroundScaled() const { return mBackgroundScaled; }
  2285. Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
  2286. Qt::Orientations rangeDrag() const { return mRangeDrag; }
  2287. Qt::Orientations rangeZoom() const { return mRangeZoom; }
  2288. QCPAxis *rangeDragAxis(Qt::Orientation orientation);
  2289. QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
  2290. double rangeZoomFactor(Qt::Orientation orientation);
  2291. // setters:
  2292. void setBackground(const QPixmap &pm);
  2293. void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
  2294. void setBackground(const QBrush &brush);
  2295. void setBackgroundScaled(bool scaled);
  2296. void setBackgroundScaledMode(Qt::AspectRatioMode mode);
  2297. void setRangeDrag(Qt::Orientations orientations);
  2298. void setRangeZoom(Qt::Orientations orientations);
  2299. void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
  2300. void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
  2301. void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
  2302. void setRangeZoomFactor(double factor);
  2303. // non-property methods:
  2304. int axisCount(QCPAxis::AxisType type) const;
  2305. QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
  2306. QList<QCPAxis*> axes(QCPAxis::AxisTypes types) const;
  2307. QList<QCPAxis*> axes() const;
  2308. QCPAxis *addAxis(QCPAxis::AxisType type);
  2309. QList<QCPAxis*> addAxes(QCPAxis::AxisTypes types);
  2310. bool removeAxis(QCPAxis *axis);
  2311. QCPLayoutInset *insetLayout() const { return mInsetLayout; }
  2312. void setupFullAxesBox(bool connectRanges=false);
  2313. QList<QCPAbstractPlottable*> plottables() const;
  2314. QList<QCPGraph*> graphs() const;
  2315. QList<QCPAbstractItem*> items() const;
  2316. // read-only interface imitating a QRect:
  2317. int left() const { return mRect.left(); }
  2318. int right() const { return mRect.right(); }
  2319. int top() const { return mRect.top(); }
  2320. int bottom() const { return mRect.bottom(); }
  2321. int width() const { return mRect.width(); }
  2322. int height() const { return mRect.height(); }
  2323. QSize size() const { return mRect.size(); }
  2324. QPoint topLeft() const { return mRect.topLeft(); }
  2325. QPoint topRight() const { return mRect.topRight(); }
  2326. QPoint bottomLeft() const { return mRect.bottomLeft(); }
  2327. QPoint bottomRight() const { return mRect.bottomRight(); }
  2328. QPoint center() const { return mRect.center(); }
  2329. // reimplemented virtual methods:
  2330. virtual void update();
  2331. virtual QList<QCPLayoutElement*> elements(bool recursive) const;
  2332. protected:
  2333. // property members:
  2334. QBrush mBackgroundBrush;
  2335. QPixmap mBackgroundPixmap;
  2336. QPixmap mScaledBackgroundPixmap;
  2337. bool mBackgroundScaled;
  2338. Qt::AspectRatioMode mBackgroundScaledMode;
  2339. QCPLayoutInset *mInsetLayout;
  2340. Qt::Orientations mRangeDrag, mRangeZoom;
  2341. QPointer<QCPAxis> mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
  2342. double mRangeZoomFactorHorz, mRangeZoomFactorVert;
  2343. // non-property members:
  2344. QCPRange mDragStartHorzRange, mDragStartVertRange;
  2345. QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
  2346. QPoint mDragStart;
  2347. bool mDragging;
  2348. QHash<QCPAxis::AxisType, QList<QCPAxis*> > mAxes;
  2349. // reimplemented virtual methods:
  2350. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  2351. virtual void draw(QCPPainter *painter);
  2352. virtual int calculateAutoMargin(QCP::MarginSide side);
  2353. // events:
  2354. virtual void mousePressEvent(QMouseEvent *event);
  2355. virtual void mouseMoveEvent(QMouseEvent *event);
  2356. virtual void mouseReleaseEvent(QMouseEvent *event);
  2357. virtual void wheelEvent(QWheelEvent *event);
  2358. // non-property methods:
  2359. void drawBackground(QCPPainter *painter);
  2360. void updateAxesOffset(QCPAxis::AxisType type);
  2361. private:
  2362. Q_DISABLE_COPY(QCPAxisRect)
  2363. friend class QCustomPlot;
  2364. };
  2365. class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
  2366. {
  2367. Q_OBJECT
  2368. /// \cond INCLUDE_QPROPERTIES
  2369. Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
  2370. Q_PROPERTY(QFont font READ font WRITE setFont)
  2371. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2372. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2373. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2374. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
  2375. Q_PROPERTY(bool selected READ selected WRITE setSelected)
  2376. /// \endcond
  2377. public:
  2378. explicit QCPAbstractLegendItem(QCPLegend *parent);
  2379. // getters:
  2380. QCPLegend *parentLegend() const { return mParentLegend; }
  2381. QFont font() const { return mFont; }
  2382. QColor textColor() const { return mTextColor; }
  2383. QFont selectedFont() const { return mSelectedFont; }
  2384. QColor selectedTextColor() const { return mSelectedTextColor; }
  2385. bool selectable() const { return mSelectable; }
  2386. bool selected() const { return mSelected; }
  2387. // setters:
  2388. void setFont(const QFont &font);
  2389. void setTextColor(const QColor &color);
  2390. void setSelectedFont(const QFont &font);
  2391. void setSelectedTextColor(const QColor &color);
  2392. void setSelectable(bool selectable);
  2393. void setSelected(bool selected);
  2394. // reimplemented virtual methods:
  2395. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2396. signals:
  2397. void selectionChanged(bool selected);
  2398. protected:
  2399. // property members:
  2400. QCPLegend *mParentLegend;
  2401. QFont mFont;
  2402. QColor mTextColor;
  2403. QFont mSelectedFont;
  2404. QColor mSelectedTextColor;
  2405. bool mSelectable, mSelected;
  2406. // reimplemented virtual methods:
  2407. virtual QCP::Interaction selectionCategory() const;
  2408. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  2409. virtual QRect clipRect() const;
  2410. virtual void draw(QCPPainter *painter) = 0;
  2411. // events:
  2412. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  2413. virtual void deselectEvent(bool *selectionStateChanged);
  2414. private:
  2415. Q_DISABLE_COPY(QCPAbstractLegendItem)
  2416. friend class QCPLegend;
  2417. };
  2418. class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
  2419. {
  2420. Q_OBJECT
  2421. public:
  2422. QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
  2423. // getters:
  2424. QCPAbstractPlottable *plottable() { return mPlottable; }
  2425. protected:
  2426. // property members:
  2427. QCPAbstractPlottable *mPlottable;
  2428. // reimplemented virtual methods:
  2429. virtual void draw(QCPPainter *painter);
  2430. virtual QSize minimumSizeHint() const;
  2431. // non-virtual methods:
  2432. QPen getIconBorderPen() const;
  2433. QColor getTextColor() const;
  2434. QFont getFont() const;
  2435. };
  2436. class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
  2437. {
  2438. Q_OBJECT
  2439. /// \cond INCLUDE_QPROPERTIES
  2440. Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
  2441. Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
  2442. Q_PROPERTY(QFont font READ font WRITE setFont)
  2443. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2444. Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
  2445. Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
  2446. Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
  2447. Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts)
  2448. Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts)
  2449. Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
  2450. Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
  2451. Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
  2452. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2453. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2454. /// \endcond
  2455. public:
  2456. /*!
  2457. Defines the selectable parts of a legend
  2458. \see setSelectedParts, setSelectableParts
  2459. */
  2460. enum SelectablePart { spNone = 0x000 ///< <tt>0x000</tt> None
  2461. ,spLegendBox = 0x001 ///< <tt>0x001</tt> The legend box (frame)
  2462. ,spItems = 0x002 ///< <tt>0x002</tt> Legend items individually (see \ref selectedItems)
  2463. };
  2464. Q_FLAGS(SelectablePart SelectableParts)
  2465. Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
  2466. explicit QCPLegend();
  2467. virtual ~QCPLegend();
  2468. // getters:
  2469. QPen borderPen() const { return mBorderPen; }
  2470. QBrush brush() const { return mBrush; }
  2471. QFont font() const { return mFont; }
  2472. QColor textColor() const { return mTextColor; }
  2473. QSize iconSize() const { return mIconSize; }
  2474. int iconTextPadding() const { return mIconTextPadding; }
  2475. QPen iconBorderPen() const { return mIconBorderPen; }
  2476. SelectableParts selectableParts() const { return mSelectableParts; }
  2477. SelectableParts selectedParts() const;
  2478. QPen selectedBorderPen() const { return mSelectedBorderPen; }
  2479. QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
  2480. QBrush selectedBrush() const { return mSelectedBrush; }
  2481. QFont selectedFont() const { return mSelectedFont; }
  2482. QColor selectedTextColor() const { return mSelectedTextColor; }
  2483. // setters:
  2484. void setBorderPen(const QPen &pen);
  2485. void setBrush(const QBrush &brush);
  2486. void setFont(const QFont &font);
  2487. void setTextColor(const QColor &color);
  2488. void setIconSize(const QSize &size);
  2489. void setIconSize(int width, int height);
  2490. void setIconTextPadding(int padding);
  2491. void setIconBorderPen(const QPen &pen);
  2492. void setSelectableParts(const SelectableParts &selectableParts);
  2493. void setSelectedParts(const SelectableParts &selectedParts);
  2494. void setSelectedBorderPen(const QPen &pen);
  2495. void setSelectedIconBorderPen(const QPen &pen);
  2496. void setSelectedBrush(const QBrush &brush);
  2497. void setSelectedFont(const QFont &font);
  2498. void setSelectedTextColor(const QColor &color);
  2499. // reimplemented virtual methods:
  2500. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2501. // non-virtual methods:
  2502. QCPAbstractLegendItem *item(int index) const;
  2503. QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
  2504. int itemCount() const;
  2505. bool hasItem(QCPAbstractLegendItem *item) const;
  2506. bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
  2507. bool addItem(QCPAbstractLegendItem *item);
  2508. bool removeItem(int index);
  2509. bool removeItem(QCPAbstractLegendItem *item);
  2510. void clearItems();
  2511. QList<QCPAbstractLegendItem*> selectedItems() const;
  2512. signals:
  2513. void selectionChanged(QCPLegend::SelectableParts selection);
  2514. protected:
  2515. // property members:
  2516. QPen mBorderPen, mIconBorderPen;
  2517. QBrush mBrush;
  2518. QFont mFont;
  2519. QColor mTextColor;
  2520. QSize mIconSize;
  2521. int mIconTextPadding;
  2522. SelectableParts mSelectedParts, mSelectableParts;
  2523. QPen mSelectedBorderPen, mSelectedIconBorderPen;
  2524. QBrush mSelectedBrush;
  2525. QFont mSelectedFont;
  2526. QColor mSelectedTextColor;
  2527. // reimplemented virtual methods:
  2528. virtual void parentPlotInitialized(QCustomPlot *parentPlot);
  2529. virtual QCP::Interaction selectionCategory() const;
  2530. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  2531. virtual void draw(QCPPainter *painter);
  2532. // events:
  2533. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  2534. virtual void deselectEvent(bool *selectionStateChanged);
  2535. // non-virtual methods:
  2536. QPen getBorderPen() const;
  2537. QBrush getBrush() const;
  2538. private:
  2539. Q_DISABLE_COPY(QCPLegend)
  2540. friend class QCustomPlot;
  2541. friend class QCPAbstractLegendItem;
  2542. };
  2543. Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
  2544. Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
  2545. class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
  2546. {
  2547. Q_OBJECT
  2548. /// \cond INCLUDE_QPROPERTIES
  2549. Q_PROPERTY(QString text READ text WRITE setText)
  2550. Q_PROPERTY(QFont font READ font WRITE setFont)
  2551. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
  2552. Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
  2553. Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
  2554. Q_PROPERTY(bool selectable READ selectable WRITE setSelectable)
  2555. Q_PROPERTY(bool selected READ selected WRITE setSelected)
  2556. /// \endcond
  2557. public:
  2558. explicit QCPPlotTitle(QCustomPlot *parentPlot);
  2559. explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
  2560. // getters:
  2561. QString text() const { return mText; }
  2562. QFont font() const { return mFont; }
  2563. QColor textColor() const { return mTextColor; }
  2564. QFont selectedFont() const { return mSelectedFont; }
  2565. QColor selectedTextColor() const { return mSelectedTextColor; }
  2566. bool selectable() const { return mSelectable; }
  2567. bool selected() const { return mSelected; }
  2568. // setters:
  2569. void setText(const QString &text);
  2570. void setFont(const QFont &font);
  2571. void setTextColor(const QColor &color);
  2572. void setSelectedFont(const QFont &font);
  2573. void setSelectedTextColor(const QColor &color);
  2574. void setSelectable(bool selectable);
  2575. void setSelected(bool selected);
  2576. // reimplemented virtual methods:
  2577. virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
  2578. signals:
  2579. void selectionChanged(bool selected);
  2580. protected:
  2581. // property members:
  2582. QString mText;
  2583. QFont mFont;
  2584. QColor mTextColor;
  2585. QFont mSelectedFont;
  2586. QColor mSelectedTextColor;
  2587. QRect mTextBoundingRect;
  2588. bool mSelectable, mSelected;
  2589. // reimplemented virtual methods:
  2590. virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
  2591. virtual void draw(QCPPainter *painter);
  2592. virtual QSize minimumSizeHint() const;
  2593. virtual QSize maximumSizeHint() const;
  2594. // events:
  2595. virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
  2596. virtual void deselectEvent(bool *selectionStateChanged);
  2597. // non-virtual methods:
  2598. QFont mainFont() const;
  2599. QColor mainTextColor() const;
  2600. private:
  2601. Q_DISABLE_COPY(QCPPlotTitle)
  2602. };
  2603. #endif // QCUSTOMPLOT_H