qcustomplot.h 146 KB

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