No Description

qcustomplot.h 135KB

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