No Description

qcustomplot.h 135KB

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