From d0933f43c9850d43f6b1cd76f020f7466dc7bdfb Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 13 Feb 2021 04:08:43 +0000 Subject: [PATCH] Add cmake and clang format and linter --- .cmake-format.py | 115 + .pre-commit-config.yaml | 30 + CMakeLists.txt | 321 +- app/CMakeLists.txt | 153 +- app/external/CMakeLists.txt | 8 +- app/external/qcustomplot/CMakeLists.txt | 24 +- app/external/qcustomplot/qcustomplot.cpp | 18123 +++++++++++---------- app/external/qcustomplot/qcustomplot.h | 5996 +++---- cmake/FindFFmpeg.cmake | 190 +- examples/CMakeLists.txt | 10 +- examples/modules/CMakeLists.txt | 23 +- lib/CMakeLists.txt | 91 +- lib/tests/CMakeLists.txt | 13 +- modules/CMakeLists.txt | 102 +- modules/tests/CMakeLists.txt | 24 +- tools/CMakeLists.txt | 25 +- 16 files changed, 13060 insertions(+), 12188 deletions(-) create mode 100644 .cmake-format.py create mode 100644 .pre-commit-config.yaml diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 0000000..72b6ba7 --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,115 @@ +# ---------------------------------- +# Options affecting listfile parsing +# ---------------------------------- +with section("parse"): + + # Specify structure for custom cmake functions + additional_commands = { 'foo': { 'flags': ['BAR', 'BAZ'], + 'kwargs': {'DEPENDS': '*', 'HEADERS': '*', 'SOURCES': '*'}}} + + ## Override configurations per-command where available + #override_spec = {} + + # Specify variable tags. + vartags = [] + + # Specify property tags. + proptags = [] + +# ----------------------------- +# Options affecting formatting. +# ----------------------------- +with section("format"): + + # How wide to allow formatted cmake files + line_width = 150 + + # How many spaces to tab for indent + tab_size = 2 + + max_pargs_hwrap = 8 + + ## If true, lines are indented using tab characters (utf-8 0x09) instead of + ## space characters (utf-8 0x20). In cases where the layout would + ## require a fractional tab character, the behavior of the fractional + ## indentation is governed by + #use_tabchars = False + + # Format command names consistently as 'lower' or 'upper' case + command_case = 'upper' + + # Format keywords consistently as 'lower' or 'upper' case + keyword_case = 'upper' + + +# ---------------------------- +# Options affecting the linter +# ---------------------------- +with section("lint"): + + # a list of lint codes to disable + disabled_codes = ["C0103"] + + # regular expression pattern describing valid function names + function_pattern = '[0-9a-z_]+' + + # regular expression pattern describing valid macro names + macro_pattern = '[0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # (cache) scope + global_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with global + # scope (but internal semantic) + internal_var_pattern = '_[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for variables with local + # scope + local_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for privatedirectory + # variables + private_var_pattern = '_[0-9a-z_]+' + + # regular expression pattern describing valid names for public directory + # variables + public_var_pattern = '[A-Z][0-9A-Z_]+' + + # regular expression pattern describing valid names for function/macro + # arguments and loop variables. + argument_var_pattern = '[a-z][a-z0-9_]+' + + # regular expression pattern describing valid names for keywords used in + # functions or macros + keyword_pattern = '[A-Z][0-9A-Z_]+' + + # In the heuristic for C0201, how many conditionals to match within a loop in + # before considering the loop a parser. + max_conditionals_custom_parser = 2 + + # Require at least this many newlines between statements + min_statement_spacing = 1 + + # Require no more than this many newlines between statements + max_statement_spacing = 2 + max_returns = 6 + max_branches = 12 + max_arguments = 5 + max_localvars = 15 + max_statements = 50 + +# ------------------------------- +# Options affecting file encoding +# ------------------------------- +with section("encode"): + + # If true, emit the unicode byte-order mark (BOM) at the start of the file + emit_byteorder_mark = False + + # Specify the encoding of the input file. Defaults to utf-8 + input_encoding = 'utf-8' + + # Specify the encoding of the output file. Defaults to utf-8. Note that cmake + # only claims to support utf-8 so be careful when using anything else + output_encoding = 'utf-8' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ab00faf --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +fail_fast: false + +repos: + - repo: local + hooks: + - id: cmake-configure + name: Cmake Configure + entry: cmake -B build + pass_filenames: false + language: system + - id: cmake-build + name: Cmake Build + entry: cmake --build build + pass_filenames: false + language: system + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.10 + hooks: + - id: cmake-format + - id: cmake-lint + + - repo: https://github.com/pocc/pre-commit-hooks + rev: python + hooks: + - id: clang-format + args: [--style=file, -i] + - id: clang-tidy + args: [-p=build] + args: [-checks=clang-diagnostic-return-type] diff --git a/CMakeLists.txt b/CMakeLists.txt index a084979..7ec21f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,241 +1,254 @@ -### -### CMakeLists for calyp -### +# +# CMakeLists for calyp +# -cmake_minimum_required( VERSION 3.2.0 ) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2.0) -###################################################################################### +# #################################################################################################################################################### # CMake functions -###################################################################################### -SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) -INCLUDE( cmake/ModulesFct.cmake ) +# #################################################################################################################################################### +SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +INCLUDE(cmake/ModulesFct.cmake) INCLUDE(FeatureSummary) INCLUDE(GNUInstallDirs) -###################################################################################### +# #################################################################################################################################################### # Project Definition -###################################################################################### +# #################################################################################################################################################### -SET( PROJECT_NAME "calyp" CACHE INTERNAL "" FORCE ) -SET( PROJECT_LIBRARY "Calyp" CACHE INTERNAL "" FORCE ) +SET(PROJECT_NAME + "calyp" + CACHE INTERNAL "" FORCE) +SET(PROJECT_LIBRARY + "Calyp" + CACHE INTERNAL "" FORCE) +PROJECT(${PROJECT_NAME}) +SET(CALYP_VERSION_MAJOR "1") +SET(CALYP_VERSION_MINOR "1") +SET(CALYP_VERSION_PATCH "0") +SET(CALYP_VERSION + "${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}" + CACHE INTERNAL "" FORCE) -PROJECT( ${PROJECT_NAME} ) -SET( CALYP_VERSION_MAJOR "1" ) -SET( CALYP_VERSION_MINOR "1" ) -SET( CALYP_VERSION_PATCH "0" ) -SET( CALYP_VERSION "${CALYP_VERSION_MAJOR}.${CALYP_VERSION_MINOR}.${CALYP_VERSION_PATCH}" CACHE INTERNAL "" FORCE ) - -###################################################################################### +# #################################################################################################################################################### # Variables -###################################################################################### +# #################################################################################################################################################### -OPTION( BUILD_APP "Build GUI Application" ON ) -OPTION( BUILD_TOOLS "Build Command Line Application" ON ) -OPTION( BUILD_EXAMPLES "Build Examples" OFF ) -OPTION( BUILD_DOC "Build Documentation" OFF ) -OPTION( BUILD_TESTS "Build Google Tests" OFF ) +OPTION(BUILD_APP "Build GUI Application" ON) +OPTION(BUILD_TOOLS "Build Command Line Application" ON) +OPTION(BUILD_EXAMPLES "Build Examples" OFF) +OPTION(BUILD_DOC "Build Documentation" OFF) +OPTION(BUILD_TESTS "Build Google Tests" OFF) -OPTION( USE_FERVOR "Add Fervor support" OFF ) +OPTION(USE_FERVOR "Add Fervor support" OFF) -OPTION( USE_DYNLOAD "Use dynamic load of modules" ON ) -OPTION( USE_SSE "Build with SSE support" OFF ) -OPTION( USE_WERROR "Warnings as errors" OFF ) -OPTION( USE_STATIC "Use static libs" OFF ) +OPTION(USE_DYNLOAD "Use dynamic load of modules" ON) +OPTION(USE_SSE "Build with SSE support" OFF) +OPTION(USE_WERROR "Warnings as errors" OFF) +OPTION(USE_STATIC "Use static libs" OFF) - -###################################################################################### +# #################################################################################################################################################### # Release configuration -###################################################################################### +# #################################################################################################################################################### # To be switched on when releasing. OPTION(RELEASE_BUILD "Remove Git revision from program version (use for stable releases)" ON) # Get current version. -set(CALYP_VERSION_STRING "${CALYP_VERSION}") -if(NOT RELEASE_BUILD AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) +SET(CALYP_VERSION_STRING "${CALYP_VERSION}") +IF(NOT RELEASE_BUILD AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) # Probably a Git workspace; determine the revision. FIND_PACKAGE(Git QUIET) - if(GIT_FOUND) - exec_program(${GIT_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR} + IF(GIT_FOUND) + EXEC_PROGRAM( + ${GIT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} ARGS "describe --tags" OUTPUT_VARIABLE CALYP_GIT_REVISION - RETURN_VALUE TAG_RESULT - ) + RETURN_VALUE TAG_RESULT) # git describe --tags failed; maybe the repository was checked with depth=1. - if(NOT ${TAG_RESULT} EQUAL 0) - exec_program(${GIT_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR} + IF(NOT ${TAG_RESULT} EQUAL 0) + EXEC_PROGRAM( + ${GIT_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} ARGS "describe --always" - OUTPUT_VARIABLE CALYP_GIT_REVISION - ) - endif() - message(STATUS "Calyp Git revision: ${CALYP_GIT_REVISION}") - set(CALYP_VERSION_STRING "${CALYP_VERSION} (rev. ${CALYP_GIT_REVISION})") - else() - message(STATUS "Calyp Git revision could not be determined") - endif() -endif() + OUTPUT_VARIABLE CALYP_GIT_REVISION) + ENDIF() + MESSAGE(STATUS "Calyp Git revision: ${CALYP_GIT_REVISION}") + SET(CALYP_VERSION_STRING "${CALYP_VERSION} (rev. ${CALYP_GIT_REVISION})") + ELSE() + MESSAGE(STATUS "Calyp Git revision could not be determined") + ENDIF() +ENDIF() -SET(UPDATE_CHANNEL "stable" CACHE STRING "Update channel" ) +SET(UPDATE_CHANNEL + "stable" + CACHE STRING "Update channel") # CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/CalypUpdate.xml.in ${CMAKE_CURRENT_BINARY_DIR}/CalypUpdate-${UPDATE_CHANNEL}.xml ) - -###################################################################################### +# #################################################################################################################################################### # Dependencies -###################################################################################### +# #################################################################################################################################################### -IF( BUILD_DOC ) +IF(BUILD_DOC) FIND_PACKAGE(Doxygen) - SET( BUILD_DOC ${Doxygen_FOUND} ) + SET(BUILD_DOC ${Doxygen_FOUND}) ENDIF() -SET_PACKAGE_PROPERTIES(Doxygen PROPERTIES URL "http://www.doxygen.org/" DESCRIPTION "Doxygen" TYPE OPTIONAL) +SET_PACKAGE_PROPERTIES( + Doxygen PROPERTIES + URL "http://www.doxygen.org/" + DESCRIPTION "Doxygen" + TYPE OPTIONAL) - -IF( BUILD_TESTS ) +IF(BUILD_TESTS) FIND_PACKAGE(GTest) - SET( BUILD_DOC ${GTEST_FOUND} ) - IF( GTEST_FOUND ) + SET(BUILD_DOC ${GTEST_FOUND}) + IF(GTEST_FOUND) ENABLE_TESTING() INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) ENDIF() - SET( CALYP_TEST_DATA_DIR "CALYP_TEST_DATA_DIR" CACHE PATH "Location of video information for testing") + SET(CALYP_TEST_DATA_DIR + "CALYP_TEST_DATA_DIR" + CACHE PATH "Location of video information for testing") ENDIF() -OPTION( USE_OPENCV "Add OpenCV support" ON ) -IF( USE_OPENCV ) +OPTION(USE_OPENCV "Add OpenCV support" ON) +IF(USE_OPENCV) - FIND_PACKAGE( OpenCV COMPONENTS core highgui imgproc video ) - IF( ${OpenCV_FOUND} ) - SET(USE_OPENCV TRUE ) - LIST(APPEND OPENCV_MODULES core highgui imgproc video ) - FIND_PACKAGE( OpenCV COMPONENTS videoio photo ) - IF( ${OPENCV_VIDEOIO_FOUND} ) - LIST(APPEND OPENCV_MODULES videoio ) + FIND_PACKAGE(OpenCV COMPONENTS core highgui imgproc video) + IF(${OpenCV_FOUND}) + SET(USE_OPENCV TRUE) + LIST(APPEND OPENCV_MODULES core highgui imgproc video) + FIND_PACKAGE(OpenCV COMPONENTS videoio photo) + IF(${OPENCV_VIDEOIO_FOUND}) + LIST(APPEND OPENCV_MODULES videoio) ENDIF() - IF( ${OPENCV_PHOTO_FOUND} ) - LIST(APPEND OPENCV_MODULES photo ) + IF(${OPENCV_PHOTO_FOUND}) + LIST(APPEND OPENCV_MODULES photo) ENDIF() ELSE() - SET(USE_OPENCV FALSE ) + SET(USE_OPENCV FALSE) ENDIF() ENDIF() -SET_PACKAGE_PROPERTIES(OpenCV PROPERTIES URL "http://opencv.willowgarage.com" DESCRIPTION "OpenCV library support in CalypFrame" TYPE OPTIONAL) +SET_PACKAGE_PROPERTIES( + OpenCV PROPERTIES + URL "http://opencv.willowgarage.com" + DESCRIPTION "OpenCV library support in CalypFrame" + TYPE OPTIONAL) -OPTION( USE_FFMPEG "Add FFMPEG support" ON ) -IF( USE_FFMPEG ) - FIND_PACKAGE( FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE ) - IF( "${AVCODEC_VERSION}" VERSION_LESS "56.0.0" ) - SET(FFMPEG_FOUND FALSE ) - SET(FFmpeg_FOUND FALSE ) +OPTION(USE_FFMPEG "Add FFMPEG support" ON) +IF(USE_FFMPEG) + FIND_PACKAGE(FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE) + IF("${AVCODEC_VERSION}" VERSION_LESS "56.0.0") + SET(FFMPEG_FOUND FALSE) + SET(FFmpeg_FOUND FALSE) ENDIF() SET(USE_FFMPEG ${FFMPEG_FOUND}) ENDIF() -SET_PACKAGE_PROPERTIES(FFmpeg PROPERTIES URL "http://ffmpeg.org/" DESCRIPTION "Libav library support in CalypStream" TYPE OPTIONAL) +SET_PACKAGE_PROPERTIES( + FFmpeg PROPERTIES + URL "http://ffmpeg.org/" + DESCRIPTION "Libav library support in CalypStream" + TYPE OPTIONAL) -IF( WIN32 ) - SET( USE_STATIC ON ) - INCLUDE( cmake/Win32.cmake ) +IF(WIN32) + SET(USE_STATIC ON) + INCLUDE(cmake/Win32.cmake) ENDIF() - -###################################################################################### +# #################################################################################################################################################### # CMake Defin1itions -###################################################################################### +# #################################################################################################################################################### -SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ) +SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) INCLUDE(FeatureSummary) # must go before the project command -SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE) +SET(CMAKE_CONFIGURATION_TYPES + "Debug;Release" + CACHE STRING "Configs" FORCE) IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8") - SET_PROPERTY( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES} ) + SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES}) ENDIF() -SET( CMAKE_CXX_FLAGS "" ) +SET(CMAKE_CXX_FLAGS "") -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) -###################################################################################### +# #################################################################################################################################################### # Compiler options -###################################################################################### +# #################################################################################################################################################### SET(CMAKE_CXX_STANDARD 14) -if(CMAKE_COMPILER_IS_GNUCXX) - ADD_DEFINITIONS(-std=gnu++0x) -endif() - -IF (NOT CMAKE_BUILD_TYPE ) - MESSAGE(STATUS "No build type selected, default to Release") - SET(CMAKE_BUILD_TYPE "Release") +IF(CMAKE_COMPILER_IS_GNUCXX) + ADD_DEFINITIONS(-std=gnu++0x) ENDIF() -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) - -ADD_DEFINITIONS(-DQT_NO_CAST_TO_ASCII - #-DQT_NO_CAST_FROM_ASCII - -DQT_NO_URL_CAST_FROM_STRING - -DQT_NO_CAST_FROM_BYTEARRAY - #-DQT_NO_SIGNALS_SLOTS_KEYWORDS - #-DQT_USE_QSTRINGBUILDER - ) - -# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") -# endif() - -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op" ) - endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" ) -endif() - -IF( USE_WERROR ) - SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror" ) +IF(NOT CMAKE_BUILD_TYPE) + MESSAGE(STATUS "No build type selected, default to Release") + SET(CMAKE_BUILD_TYPE "Release") ENDIF() -SET( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0" ) -SET( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" ) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +ADD_DEFINITIONS( + -DQT_NO_CAST_TO_ASCII + # -DQT_NO_CAST_FROM_ASCII + -DQT_NO_URL_CAST_FROM_STRING + -DQT_NO_CAST_FROM_BYTEARRAY + # -DQT_NO_SIGNALS_SLOTS_KEYWORDS -DQT_USE_QSTRINGBUILDER +) -###################################################################################### +# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") endif() + +IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + IF(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op") + ENDIF() + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") +ENDIF() + +IF(USE_WERROR) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") +ENDIF() + +SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") +SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") + +# #################################################################################################################################################### # Configure targets -###################################################################################### +# #################################################################################################################################################### -ADD_FEATURE_INFO(CalypApp BUILD_APP "Build Graphical interface") -ADD_FEATURE_INFO(CalypTools BUILD_TOOLS "Build Command line tool" ) -ADD_FEATURE_INFO(DynLoad USE_DYNLOAD "Support for dynamic module load" ) -ADD_FEATURE_INFO(SSE USE_SSE "SSE instructions support" ) -ADD_FEATURE_INFO(WErrors USE_WERROR "Warnings as errors" ) +ADD_FEATURE_INFO(CalypApp BUILD_APP "Build Graphical interface") +ADD_FEATURE_INFO(CalypTools BUILD_TOOLS "Build Command line tool") +ADD_FEATURE_INFO(DynLoad USE_DYNLOAD "Support for dynamic module load") +ADD_FEATURE_INFO(SSE USE_SSE "SSE instructions support") +ADD_FEATURE_INFO(WErrors USE_WERROR "Warnings as errors") -ADD_SUBDIRECTORY( lib ) -ADD_SUBDIRECTORY( modules ) +ADD_SUBDIRECTORY(lib) +ADD_SUBDIRECTORY(modules) -IF( ${BUILD_TOOLS} ) - ADD_SUBDIRECTORY( tools ) +IF(${BUILD_TOOLS}) + ADD_SUBDIRECTORY(tools) ENDIF() -IF( ${BUILD_APP} ) - ADD_SUBDIRECTORY( app ) +IF(${BUILD_APP}) + ADD_SUBDIRECTORY(app) ENDIF() -IF( ${BUILD_EXAMPLES} ) - ADD_SUBDIRECTORY( examples ) +IF(${BUILD_EXAMPLES}) + ADD_SUBDIRECTORY(examples) ENDIF() +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) -CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h ) - -###################################################################################### +# #################################################################################################################################################### # Final information dump -###################################################################################### +# #################################################################################################################################################### MESSAGE("") -MESSAGE( STATUS "${PROJECT_NAME} INFORMATION" ) -MESSAGE( STATUS "Version: " "${CALYP_VERSION_STRING}" ) -MESSAGE( STATUS "Configuration:" ) -MESSAGE( STATUS " Static libs: " "${USE_STATIC}" ) -MESSAGE( STATUS " Build type: " "${CMAKE_BUILD_TYPE}" ) -MESSAGE( STATUS " Build flags: " "${CMAKE_CXX_FLAGS}" ) +MESSAGE(STATUS "${PROJECT_NAME} INFORMATION") +MESSAGE(STATUS "Version: " "${CALYP_VERSION_STRING}") +MESSAGE(STATUS "Configuration:") +MESSAGE(STATUS " Static libs: " "${USE_STATIC}") +MESSAGE(STATUS " Build type: " "${CMAKE_BUILD_TYPE}") +MESSAGE(STATUS " Build flags: " "${CMAKE_CXX_FLAGS}") FEATURE_SUMMARY(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index ba73bda..fcaa70a 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,148 +1,147 @@ -### -### CMakeLists for calyp app component -### +# +# CMakeLists for calyp app component +# -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external - ${CMAKE_CURRENT_SOURCE_DIR}/dialog - ${CMAKE_CURRENT_SOURCE_DIR}/docks - ${CMAKE_CURRENT_SOURCE_DIR}/widgets ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external ${CMAKE_CURRENT_SOURCE_DIR}/dialog + ${CMAKE_CURRENT_SOURCE_DIR}/docks ${CMAKE_CURRENT_SOURCE_DIR}/widgets) -OPTION( USE_QTDBUS "Build with QtDBus" ON ) -OPTION( USE_FERVOR "Add Fervor support" OFF ) +OPTION(USE_QTDBUS "Build with QtDBus" ON) +OPTION(USE_FERVOR "Add Fervor support" OFF) -ADD_SUBDIRECTORY( external ) +ADD_SUBDIRECTORY(external) -FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets Concurrent ) -LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Concurrent ) -LIST(APPEND QT_MODULES Core Gui Widgets Concurrent ) +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets Concurrent) +LIST(APPEND QT_LINKER_LIBS Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Concurrent) +LIST(APPEND QT_MODULES Core Gui Widgets Concurrent) -IF( USE_QTDBUS ) - FIND_PACKAGE( Qt5DBus ) - SET_PACKAGE_PROPERTIES(Qt5DBus PROPERTIES DESCRIPTION "Support for Qt5 DBus messages between instances" TYPE OPTIONAL ) - IF( ${Qt5DBus_FOUND} ) - SET( USE_QTDBUS ${Qt5DBus_FOUND} ) # TODO: fix this stupid variable - SET( USE_QTDBUS ${Qt5DBus_FOUND} PARENT_SCOPE) - LIST(APPEND QT_LINKER_LIBS Qt5::DBus ) - LIST(APPEND QT_MODULES DBus ) +IF(USE_QTDBUS) + FIND_PACKAGE(Qt5DBus) + SET_PACKAGE_PROPERTIES( + Qt5DBus PROPERTIES + DESCRIPTION "Support for Qt5 DBus messages between instances" + TYPE OPTIONAL) + IF(${Qt5DBus_FOUND}) + SET(USE_QTDBUS ${Qt5DBus_FOUND}) # TODO: fix this stupid variable + SET(USE_QTDBUS + ${Qt5DBus_FOUND} + PARENT_SCOPE) + LIST(APPEND QT_LINKER_LIBS Qt5::DBus) + LIST(APPEND QT_MODULES DBus) ENDIF() ENDIF() -set(Calyp_App_SRCS -# Main +SET(Calyp_App_SRCS + # Main main.cpp MainWindow.cpp -# Module SubWindow + # Module SubWindow SubWindowHandle.cpp MdiSubWindow.cpp SubWindowAbstract.cpp -# Module Video + # Module Video VideoHandle.cpp VideoSubWindow.cpp ViewArea.cpp GridManager.cpp -# Module Quality + # Module Quality QualityHandle.cpp PlotSubWindow.cpp external/qcustomplot/qcustomplot.cpp -# Module Plugins + # Module Plugins ModulesHandle.cpp CalypAppModuleIf.cpp -# Dialogs + # Dialogs dialog/AboutDialog.cpp dialog/ConfigureFormatDialog.cpp dialog/SubWindowSelectorDialog.cpp dialog/ProgressBar.cpp dialog/SeekStreamDialog.cpp dialog/ModulesHandleOptDialog.cpp -# Widgets + # Widgets widgets/HistogramWidget.cpp widgets/FrameNumberWidget.cpp -# Docks + # Docks docks/FramePropertiesDock.cpp docks/ModuleHandleDock.cpp - docks/QualityMeasurementSidebar.cpp -) + docks/QualityMeasurementSidebar.cpp) -IF( USE_QTDBUS ) - LIST( APPEND Calyp_App_SRCS DBusAppAdaptor.cpp ) +IF(USE_QTDBUS) + LIST(APPEND Calyp_App_SRCS DBusAppAdaptor.cpp) ENDIF() +SET(Calyp_App_UI "") -set(Calyp_App_UI "" ) +SET(Calyp_App_RCC resources/${PROJECT_NAME}.qrc) -set(Calyp_App_RCC - resources/${PROJECT_NAME}.qrc -) +IF(USE_FERVOR) + SET(FERVOR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/fervor) -IF( USE_FERVOR ) + IF(EXISTS ${FERVOR_DIR}) - SET( FERVOR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/fervor ) + SET(FERVOR_APP_NAME ${PROJECT_NAME}) + SET(FERVOR_APP_VERSION ${CALYP_VERSION_STRING}) - IF(EXISTS ${FERVOR_DIR} ) + ADD_SUBDIRECTORY(${FERVOR_DIR}) - SET( FERVOR_APP_NAME ${PROJECT_NAME} ) - SET( FERVOR_APP_VERSION ${CALYP_VERSION_STRING} ) + INCLUDE_DIRECTORIES(${FERVOR_DIR}) - ADD_SUBDIRECTORY( ${FERVOR_DIR} ) + LIST(APPEND APP_LINKER_LIBS Fervor) - INCLUDE_DIRECTORIES( ${FERVOR_DIR} ) + FIND_PACKAGE(Qt5 REQUIRED Network WebKit WebKitWidgets) - LIST(APPEND APP_LINKER_LIBS Fervor ) + LIST(APPEND QT_LINKER_LIBS Qt5::Network Qt5::WebKit Qt5::WebKitWidgets) + LIST(APPEND QT_MODULES Network WebKit WebKitWidgets) - FIND_PACKAGE( Qt5 REQUIRED Network WebKit WebKitWidgets ) - - LIST(APPEND QT_LINKER_LIBS Qt5::Network Qt5::WebKit Qt5::WebKitWidgets ) - LIST(APPEND QT_MODULES Network WebKit WebKitWidgets ) - -# LIST(APPEND APP_LINKER_LIBS ${FERVOR_DEPENDENCIES} ) - INCLUDE_DIRECTORIES( ${FERVOR_INCLUDE_DIRS} ) + # LIST(APPEND APP_LINKER_LIBS ${FERVOR_DEPENDENCIES} ) + INCLUDE_DIRECTORIES(${FERVOR_INCLUDE_DIRS}) SET(QT_USE_QTNETWORK true) SET(QT_USE_QTWEBKIT true) ELSE() - MESSAGE( "Fervor lib source code is not find in ${FERVOR_DIR}... Disabling it!" ) - SET( USE_FERVOR False ) + MESSAGE("Fervor lib source code is not find in ${FERVOR_DIR}... Disabling it!") + SET(USE_FERVOR False) ENDIF() ENDIF() -SET_PACKAGE_PROPERTIES(Fervor PROPERTIES URL "https://github.com/pypt/fervor" DESCRIPTION "Fervor lib includes check for updates feature" TYPE OPTIONAL ) +SET_PACKAGE_PROPERTIES( + Fervor PROPERTIES + URL "https://github.com/pypt/fervor" + DESCRIPTION "Fervor lib includes check for updates feature" + TYPE OPTIONAL) ADD_FEATURE_INFO(Fervor USE_FERVOR "Fervor lib includes check for updates feature.") -QT5_WRAP_UI( Calyp_App_UI_Wrap ${Calyp_App_UI} ) -QT5_ADD_RESOURCES( Calyp_App_RCC ${Calyp_App_RCC} ) +QT5_WRAP_UI(Calyp_App_UI_Wrap ${Calyp_App_UI}) +QT5_ADD_RESOURCES(Calyp_App_RCC ${Calyp_App_RCC}) # Instruct CMake to run moc automatically when needed. -SET( CMAKE_AUTOMOC ON ) +SET(CMAKE_AUTOMOC ON) # Windows application icon -IF( WIN32 ) - set(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj) - IF( MSVC ) - add_custom_command(OUTPUT ${WINDOWS_RES_FILE} +IF(WIN32) + SET(WINDOWS_RES_FILE ${CMAKE_CURRENT_BINARY_DIR}/resources.obj) + IF(MSVC) + ADD_CUSTOM_COMMAND( + OUTPUT ${WINDOWS_RES_FILE} COMMAND rc.exe /fo ${WINDOWS_RES_FILE} ${PROJECT_NAME}.rc WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources - ) + COMMENT "Add icon on windows platform") ELSE() - add_custom_command(OUTPUT ${WINDOWS_RES_FILE} + ADD_CUSTOM_COMMAND( + OUTPUT ${WINDOWS_RES_FILE} COMMAND windres.exe ${PROJECT_NAME}.rc ${WINDOWS_RES_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources - ) + COMMENT "Add icon on windows platform") ENDIF() ENDIF() - -ADD_EXECUTABLE( ${PROJECT_NAME} ${Calyp_App_SRCS} ${HEADERS_MOC_FILES} ${Calyp_App_UI_Wrap} ${Calyp_App_RCC} ${WINDOWS_RES_FILE} ) -TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${PROJECT_LIBRARY} CalypModules ${APP_LINKER_LIBS} ${QT_LINKER_LIBS} QCustomPlotLib ) +ADD_EXECUTABLE(${PROJECT_NAME} ${Calyp_App_SRCS} ${HEADERS_MOC_FILES} ${Calyp_App_UI_Wrap} ${Calyp_App_RCC} ${WINDOWS_RES_FILE}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PROJECT_LIBRARY} CalypModules ${APP_LINKER_LIBS} ${QT_LINKER_LIBS} QCustomPlotLib) # QT5_USE_MODULES( ${PROJECT_NAME} ${QT_MODULES} ) -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin ) -INSTALL(FILES resources/calyp.desktop DESTINATION share/applications ) -INSTALL(FILES resources/calyp.png DESTINATION share/pixmaps ) -INSTALL(FILES resources/calyp.xml DESTINATION share/mime/packages ) - - - +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +INSTALL(FILES resources/calyp.desktop DESTINATION share/applications) +INSTALL(FILES resources/calyp.png DESTINATION share/pixmaps) +INSTALL(FILES resources/calyp.xml DESTINATION share/mime/packages) diff --git a/app/external/CMakeLists.txt b/app/external/CMakeLists.txt index 9e28baf..1c50543 100644 --- a/app/external/CMakeLists.txt +++ b/app/external/CMakeLists.txt @@ -1,5 +1,5 @@ -### -### CMakeLists for calyp external components -### +# +# CMakeLists for calyp external components +# -ADD_SUBDIRECTORY( qcustomplot ) +ADD_SUBDIRECTORY(qcustomplot) diff --git a/app/external/qcustomplot/CMakeLists.txt b/app/external/qcustomplot/CMakeLists.txt index a44396d..ff308d3 100644 --- a/app/external/qcustomplot/CMakeLists.txt +++ b/app/external/qcustomplot/CMakeLists.txt @@ -1,20 +1,12 @@ -### -### CMakeLists for qcustomplot -### +# +# CMakeLists for qcustomplot +# -FIND_PACKAGE( Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport ) +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport) -set(qcustomplot_SRCS - qcustomplot.cpp - qcustomplot.h -) +SET(qcustomplot_SRCS qcustomplot.cpp qcustomplot.h) -ADD_LIBRARY( QCustomPlotLib STATIC ${qcustomplot_SRCS} ) -TARGET_LINK_LIBRARIES( QCustomPlotLib - Qt5::Core - Qt5::Gui - Qt5::Widgets - Qt5::PrintSupport -) +ADD_LIBRARY(QCustomPlotLib STATIC ${qcustomplot_SRCS}) +TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport) -TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC . ) +TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .) diff --git a/app/external/qcustomplot/qcustomplot.cpp b/app/external/qcustomplot/qcustomplot.cpp index 51722e2..0fc5751 100644 --- a/app/external/qcustomplot/qcustomplot.cpp +++ b/app/external/qcustomplot/qcustomplot.cpp @@ -25,7 +25,6 @@ #include "qcustomplot.h" - /* including file 'src/vector2d.cpp', size 7340 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -108,9 +107,8 @@ /*! Creates a QCPVector2D object and initializes the x and y coordinates to 0. */ -QCPVector2D::QCPVector2D() : - mX(0), - mY(0) +QCPVector2D::QCPVector2D() + : mX( 0 ), mY( 0 ) { } @@ -118,9 +116,8 @@ QCPVector2D::QCPVector2D() : Creates a QCPVector2D object and initializes the \a x and \a y coordinates with the specified values. */ -QCPVector2D::QCPVector2D(double x, double y) : - mX(x), - mY(y) +QCPVector2D::QCPVector2D( double x, double y ) + : mX( x ), mY( y ) { } @@ -128,9 +125,8 @@ QCPVector2D::QCPVector2D(double x, double y) : Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of the specified \a point. */ -QCPVector2D::QCPVector2D(const QPoint &point) : - mX(point.x()), - mY(point.y()) +QCPVector2D::QCPVector2D( const QPoint& point ) + : mX( point.x() ), mY( point.y() ) { } @@ -138,9 +134,8 @@ QCPVector2D::QCPVector2D(const QPoint &point) : Creates a QCPVector2D object and initializes the x and y coordinates respective coordinates of the specified \a point. */ -QCPVector2D::QCPVector2D(const QPointF &point) : - mX(point.x()), - mY(point.y()) +QCPVector2D::QCPVector2D( const QPointF& point ) + : mX( point.x() ), mY( point.y() ) { } @@ -163,7 +158,7 @@ void QCPVector2D::normalize() */ QCPVector2D QCPVector2D::normalized() const { - QCPVector2D result(mX, mY); + QCPVector2D result( mX, mY ); result.normalize(); return result; } @@ -175,21 +170,22 @@ QCPVector2D QCPVector2D::normalized() const \see distanceToStraightLine */ -double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const +double QCPVector2D::distanceSquaredToLine( const QCPVector2D& start, const QCPVector2D& end ) const { - QCPVector2D v(end-start); + QCPVector2D v( end - start ); double vLengthSqr = v.lengthSquared(); - if (!qFuzzyIsNull(vLengthSqr)) + if( !qFuzzyIsNull( vLengthSqr ) ) { - double mu = v.dot(*this-start)/vLengthSqr; - if (mu < 0) - return (*this-start).lengthSquared(); - else if (mu > 1) - return (*this-end).lengthSquared(); + double mu = v.dot( *this - start ) / vLengthSqr; + if( mu < 0 ) + return ( *this - start ).lengthSquared(); + else if( mu > 1 ) + return ( *this - end ).lengthSquared(); else - return ((start + mu*v)-*this).lengthSquared(); - } else - return (*this-start).lengthSquared(); + return ( ( start + mu * v ) - *this ).lengthSquared(); + } + else + return ( *this - start ).lengthSquared(); } /*! \overload @@ -199,9 +195,9 @@ double QCPVector2D::distanceSquaredToLine(const QCPVector2D &start, const QCPVec \see distanceToStraightLine */ -double QCPVector2D::distanceSquaredToLine(const QLineF &line) const +double QCPVector2D::distanceSquaredToLine( const QLineF& line ) const { - return distanceSquaredToLine(QCPVector2D(line.p1()), QCPVector2D(line.p2())); + return distanceSquaredToLine( QCPVector2D( line.p1() ), QCPVector2D( line.p2() ) ); } /*! @@ -210,16 +206,16 @@ double QCPVector2D::distanceSquaredToLine(const QLineF &line) const \see distanceSquaredToLine */ -double QCPVector2D::distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const +double QCPVector2D::distanceToStraightLine( const QCPVector2D& base, const QCPVector2D& direction ) const { - return qAbs((*this-base).dot(direction.perpendicular()))/direction.length(); + return qAbs( ( *this - base ).dot( direction.perpendicular() ) ) / direction.length(); } /*! Scales this vector by the given \a factor, i.e. the x and y components are multiplied by \a factor. */ -QCPVector2D &QCPVector2D::operator*=(double factor) +QCPVector2D& QCPVector2D::operator*=( double factor ) { mX *= factor; mY *= factor; @@ -230,7 +226,7 @@ QCPVector2D &QCPVector2D::operator*=(double factor) Scales this vector by the given \a divisor, i.e. the x and y components are divided by \a divisor. */ -QCPVector2D &QCPVector2D::operator/=(double divisor) +QCPVector2D& QCPVector2D::operator/=( double divisor ) { mX /= divisor; mY /= divisor; @@ -240,7 +236,7 @@ QCPVector2D &QCPVector2D::operator/=(double divisor) /*! Adds the given \a vector to this vector component-wise. */ -QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) +QCPVector2D& QCPVector2D::operator+=( const QCPVector2D& vector ) { mX += vector.mX; mY += vector.mY; @@ -250,7 +246,7 @@ QCPVector2D &QCPVector2D::operator+=(const QCPVector2D &vector) /*! subtracts the given \a vector from this vector component-wise. */ -QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) +QCPVector2D& QCPVector2D::operator-=( const QCPVector2D& vector ) { mX -= vector.mX; mY -= vector.mY; @@ -258,7 +254,6 @@ QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) } /* end of 'src/vector2d.cpp' */ - /* including file 'src/painter.cpp', size 8670 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -282,10 +277,8 @@ QCPVector2D &QCPVector2D::operator-=(const QCPVector2D &vector) /*! Creates a new QCPPainter instance and sets default values */ -QCPPainter::QCPPainter() : - QPainter(), - mModes(pmDefault), - mIsAntialiasing(false) +QCPPainter::QCPPainter() + : QPainter(), mModes( pmDefault ), mIsAntialiasing( false ) { // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and // a call to begin() will follow @@ -297,14 +290,12 @@ QCPPainter::QCPPainter() : Like \ref begin, this method sets QPainter::NonCosmeticDefaultPen in Qt versions before Qt5. */ -QCPPainter::QCPPainter(QPaintDevice *device) : - QPainter(device), - mModes(pmDefault), - mIsAntialiasing(false) +QCPPainter::QCPPainter( QPaintDevice* device ) + : QPainter( device ), mModes( pmDefault ), mIsAntialiasing( false ) { -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (isActive()) - setRenderHint(QPainter::NonCosmeticDefaultPen); +#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if( isActive() ) + setRenderHint( QPainter::NonCosmeticDefaultPen ); #endif } @@ -314,10 +305,10 @@ QCPPainter::QCPPainter(QPaintDevice *device) : \note this function hides the non-virtual base class implementation. */ -void QCPPainter::setPen(const QPen &pen) +void QCPPainter::setPen( const QPen& pen ) { - QPainter::setPen(pen); - if (mModes.testFlag(pmNonCosmetic)) + QPainter::setPen( pen ); + if( mModes.testFlag( pmNonCosmetic ) ) makeNonCosmetic(); } @@ -328,10 +319,10 @@ void QCPPainter::setPen(const QPen &pen) \note this function hides the non-virtual base class implementation. */ -void QCPPainter::setPen(const QColor &color) +void QCPPainter::setPen( const QColor& color ) { - QPainter::setPen(color); - if (mModes.testFlag(pmNonCosmetic)) + QPainter::setPen( color ); + if( mModes.testFlag( pmNonCosmetic ) ) makeNonCosmetic(); } @@ -342,10 +333,10 @@ void QCPPainter::setPen(const QColor &color) \note this function hides the non-virtual base class implementation. */ -void QCPPainter::setPen(Qt::PenStyle penStyle) +void QCPPainter::setPen( Qt::PenStyle penStyle ) { - QPainter::setPen(penStyle); - if (mModes.testFlag(pmNonCosmetic)) + QPainter::setPen( penStyle ); + if( mModes.testFlag( pmNonCosmetic ) ) makeNonCosmetic(); } @@ -357,12 +348,12 @@ void QCPPainter::setPen(Qt::PenStyle penStyle) \note this function hides the non-virtual base class implementation. */ -void QCPPainter::drawLine(const QLineF &line) +void QCPPainter::drawLine( const QLineF& line ) { - if (mIsAntialiasing || mModes.testFlag(pmVectorized)) - QPainter::drawLine(line); + if( mIsAntialiasing || mModes.testFlag( pmVectorized ) ) + QPainter::drawLine( line ); else - QPainter::drawLine(line.toLine()); + QPainter::drawLine( line.toLine() ); } /*! @@ -371,18 +362,18 @@ void QCPPainter::drawLine(const QLineF &line) antialiased and non-antialiased painting (Since Qt < 5.0 uses slightly different coordinate systems for AA/Non-AA painting). */ -void QCPPainter::setAntialiasing(bool enabled) +void QCPPainter::setAntialiasing( bool enabled ) { - setRenderHint(QPainter::Antialiasing, enabled); - if (mIsAntialiasing != enabled) + setRenderHint( QPainter::Antialiasing, enabled ); + if( mIsAntialiasing != enabled ) { mIsAntialiasing = enabled; - if (!mModes.testFlag(pmVectorized)) // antialiasing half-pixel shift only needed for rasterized outputs + if( !mModes.testFlag( pmVectorized ) ) // antialiasing half-pixel shift only needed for rasterized outputs { - if (mIsAntialiasing) - translate(0.5, 0.5); + if( mIsAntialiasing ) + translate( 0.5, 0.5 ); else - translate(-0.5, -0.5); + translate( -0.5, -0.5 ); } } } @@ -391,7 +382,7 @@ void QCPPainter::setAntialiasing(bool enabled) Sets the mode of the painter. This controls whether the painter shall adjust its fixes/workarounds optimized for certain output devices. */ -void QCPPainter::setModes(QCPPainter::PainterModes modes) +void QCPPainter::setModes( QCPPainter::PainterModes modes ) { mModes = modes; } @@ -407,12 +398,12 @@ void QCPPainter::setModes(QCPPainter::PainterModes modes) \note this function hides the non-virtual base class implementation. */ -bool QCPPainter::begin(QPaintDevice *device) +bool QCPPainter::begin( QPaintDevice* device ) { - bool result = QPainter::begin(device); -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. - if (result) - setRenderHint(QPainter::NonCosmeticDefaultPen); + bool result = QPainter::begin( device ); +#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) // before Qt5, default pens used to be cosmetic if NonCosmeticDefaultPen flag isn't set. So we set it to get consistency across Qt versions. + if( result ) + setRenderHint( QPainter::NonCosmeticDefaultPen ); #endif return result; } @@ -422,11 +413,11 @@ bool QCPPainter::begin(QPaintDevice *device) Sets the mode of the painter. This controls whether the painter shall adjust its fixes/workarounds optimized for certain output devices. */ -void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) +void QCPPainter::setMode( QCPPainter::PainterMode mode, bool enabled ) { - if (!enabled && mModes.testFlag(mode)) + if( !enabled && mModes.testFlag( mode ) ) mModes &= ~mode; - else if (enabled && !mModes.testFlag(mode)) + else if( enabled && !mModes.testFlag( mode ) ) mModes |= mode; } @@ -440,7 +431,7 @@ void QCPPainter::setMode(QCPPainter::PainterMode mode, bool enabled) */ void QCPPainter::save() { - mAntialiasingStack.push(mIsAntialiasing); + mAntialiasingStack.push( mIsAntialiasing ); QPainter::save(); } @@ -454,7 +445,7 @@ void QCPPainter::save() */ void QCPPainter::restore() { - if (!mAntialiasingStack.isEmpty()) + if( !mAntialiasingStack.isEmpty() ) mIsAntialiasing = mAntialiasingStack.pop(); else qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; @@ -467,16 +458,15 @@ void QCPPainter::restore() */ void QCPPainter::makeNonCosmetic() { - if (qFuzzyIsNull(pen().widthF())) + if( qFuzzyIsNull( pen().widthF() ) ) { QPen p = pen(); - p.setWidth(1); - QPainter::setPen(p); + p.setWidth( 1 ); + QPainter::setPen( p ); } } /* end of 'src/painter.cpp' */ - /* including file 'src/paintbuffer.cpp', size 18502 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -567,10 +557,8 @@ void QCPPainter::makeNonCosmetic() Subclasses must call their \ref reallocateBuffer implementation in their respective constructors. */ -QCPAbstractPaintBuffer::QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio) : - mSize(size), - mDevicePixelRatio(devicePixelRatio), - mInvalidated(true) +QCPAbstractPaintBuffer::QCPAbstractPaintBuffer( const QSize& size, double devicePixelRatio ) + : mSize( size ), mDevicePixelRatio( devicePixelRatio ), mInvalidated( true ) { } @@ -586,9 +574,9 @@ QCPAbstractPaintBuffer::~QCPAbstractPaintBuffer() If \a size is already the current buffer size, this method does nothing. */ -void QCPAbstractPaintBuffer::setSize(const QSize &size) +void QCPAbstractPaintBuffer::setSize( const QSize& size ) { - if (mSize != size) + if( mSize != size ) { mSize = size; reallocateBuffer(); @@ -610,7 +598,7 @@ void QCPAbstractPaintBuffer::setSize(const QSize &size) Under normal circumstances, it is not necessary to manually call this method. */ -void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) +void QCPAbstractPaintBuffer::setInvalidated( bool invalidated ) { mInvalidated = invalidated; } @@ -624,9 +612,9 @@ void QCPAbstractPaintBuffer::setInvalidated(bool invalidated) \note This method is only available for Qt versions 5.4 and higher. */ -void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) +void QCPAbstractPaintBuffer::setDevicePixelRatio( double ratio ) { - if (!qFuzzyCompare(ratio, mDevicePixelRatio)) + if( !qFuzzyCompare( ratio, mDevicePixelRatio ) ) { #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED mDevicePixelRatio = ratio; @@ -653,8 +641,8 @@ void QCPAbstractPaintBuffer::setDevicePixelRatio(double ratio) Creates a pixmap paint buffer instancen with the specified \a size and \a devicePixelRatio, if applicable. */ -QCPPaintBufferPixmap::QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio) : - QCPAbstractPaintBuffer(size, devicePixelRatio) +QCPPaintBufferPixmap::QCPPaintBufferPixmap( const QSize& size, double devicePixelRatio ) + : QCPAbstractPaintBuffer( size, devicePixelRatio ) { QCPPaintBufferPixmap::reallocateBuffer(); } @@ -664,49 +652,49 @@ QCPPaintBufferPixmap::~QCPPaintBufferPixmap() } /* inherits documentation from base class */ -QCPPainter *QCPPaintBufferPixmap::startPainting() +QCPPainter* QCPPaintBufferPixmap::startPainting() { - QCPPainter *result = new QCPPainter(&mBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); + QCPPainter* result = new QCPPainter( &mBuffer ); + result->setRenderHint( QPainter::HighQualityAntialiasing ); return result; } /* inherits documentation from base class */ -void QCPPaintBufferPixmap::draw(QCPPainter *painter) const +void QCPPaintBufferPixmap::draw( QCPPainter* painter ) const { - if (painter && painter->isActive()) - painter->drawPixmap(0, 0, mBuffer); + if( painter && painter->isActive() ) + painter->drawPixmap( 0, 0, mBuffer ); else qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; } /* inherits documentation from base class */ -void QCPPaintBufferPixmap::clear(const QColor &color) +void QCPPaintBufferPixmap::clear( const QColor& color ) { - mBuffer.fill(color); + mBuffer.fill( color ); } /* inherits documentation from base class */ void QCPPaintBufferPixmap::reallocateBuffer() { setInvalidated(); - if (!qFuzzyCompare(1.0, mDevicePixelRatio)) + if( !qFuzzyCompare( 1.0, mDevicePixelRatio ) ) { #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mBuffer = QPixmap(mSize*mDevicePixelRatio); - mBuffer.setDevicePixelRatio(mDevicePixelRatio); + mBuffer = QPixmap( mSize * mDevicePixelRatio ); + mBuffer.setDevicePixelRatio( mDevicePixelRatio ); #else qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; mDevicePixelRatio = 1.0; - mBuffer = QPixmap(mSize); + mBuffer = QPixmap( mSize ); #endif - } else + } + else { - mBuffer = QPixmap(mSize); + mBuffer = QPixmap( mSize ); } } - #ifdef QCP_OPENGL_PBUFFER //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPaintBufferGlPbuffer @@ -731,76 +719,74 @@ void QCPPaintBufferPixmap::reallocateBuffer() result in higher quality antialiasing. If the specified \a multisamples value exceeds the capability of the graphics hardware, the highest supported multisampling is used. */ -QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlPBuffer(0), - mMultisamples(qMax(0, multisamples)) +QCPPaintBufferGlPbuffer::QCPPaintBufferGlPbuffer( const QSize& size, double devicePixelRatio, int multisamples ) + : QCPAbstractPaintBuffer( size, devicePixelRatio ), mGlPBuffer( 0 ), mMultisamples( qMax( 0, multisamples ) ) { QCPPaintBufferGlPbuffer::reallocateBuffer(); } QCPPaintBufferGlPbuffer::~QCPPaintBufferGlPbuffer() { - if (mGlPBuffer) + if( mGlPBuffer ) delete mGlPBuffer; } /* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlPbuffer::startPainting() +QCPPainter* QCPPaintBufferGlPbuffer::startPainting() { - if (!mGlPBuffer->isValid()) + if( !mGlPBuffer->isValid() ) { qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; return 0; } - - QCPPainter *result = new QCPPainter(mGlPBuffer); - result->setRenderHint(QPainter::HighQualityAntialiasing); + + QCPPainter* result = new QCPPainter( mGlPBuffer ); + result->setRenderHint( QPainter::HighQualityAntialiasing ); return result; } /* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::draw(QCPPainter *painter) const +void QCPPaintBufferGlPbuffer::draw( QCPPainter* painter ) const { - if (!painter || !painter->isActive()) + if( !painter || !painter->isActive() ) { qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; return; } - if (!mGlPBuffer->isValid()) + if( !mGlPBuffer->isValid() ) { qDebug() << Q_FUNC_INFO << "OpenGL pbuffer isn't valid, reallocateBuffer was not called?"; return; } - painter->drawImage(0, 0, mGlPBuffer->toImage()); + painter->drawImage( 0, 0, mGlPBuffer->toImage() ); } /* inherits documentation from base class */ -void QCPPaintBufferGlPbuffer::clear(const QColor &color) +void QCPPaintBufferGlPbuffer::clear( const QColor& color ) { - if (mGlPBuffer->isValid()) + if( mGlPBuffer->isValid() ) { mGlPBuffer->makeCurrent(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor( color.redF(), color.greenF(), color.blueF(), color.alphaF() ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mGlPBuffer->doneCurrent(); - } else + } + else qDebug() << Q_FUNC_INFO << "OpenGL pbuffer invalid or context not current"; } /* inherits documentation from base class */ void QCPPaintBufferGlPbuffer::reallocateBuffer() { - if (mGlPBuffer) + if( mGlPBuffer ) delete mGlPBuffer; - - QGLFormat format; - format.setAlpha(true); - format.setSamples(mMultisamples); - mGlPBuffer = new QGLPixelBuffer(mSize, format); -} -#endif // QCP_OPENGL_PBUFFER + QGLFormat format; + format.setAlpha( true ); + format.setSamples( mMultisamples ); + mGlPBuffer = new QGLPixelBuffer( mSize, format ); +} +#endif // QCP_OPENGL_PBUFFER #ifdef QCP_OPENGL_FBO //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -827,87 +813,84 @@ void QCPPaintBufferGlPbuffer::reallocateBuffer() QCustomPlot::setupOpenGl and the context and paint device are managed by the parent QCustomPlot instance. */ -QCPPaintBufferGlFbo::QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice) : - QCPAbstractPaintBuffer(size, devicePixelRatio), - mGlContext(glContext), - mGlPaintDevice(glPaintDevice), - mGlFrameBuffer(0) +QCPPaintBufferGlFbo::QCPPaintBufferGlFbo( const QSize& size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice ) + : QCPAbstractPaintBuffer( size, devicePixelRatio ), mGlContext( glContext ), mGlPaintDevice( glPaintDevice ), mGlFrameBuffer( 0 ) { QCPPaintBufferGlFbo::reallocateBuffer(); } QCPPaintBufferGlFbo::~QCPPaintBufferGlFbo() { - if (mGlFrameBuffer) + if( mGlFrameBuffer ) delete mGlFrameBuffer; } /* inherits documentation from base class */ -QCPPainter *QCPPaintBufferGlFbo::startPainting() +QCPPainter* QCPPaintBufferGlFbo::startPainting() { - if (mGlPaintDevice.isNull()) + if( mGlPaintDevice.isNull() ) { qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; return 0; } - if (!mGlFrameBuffer) + if( !mGlFrameBuffer ) { qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; return 0; } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + + if( QOpenGLContext::currentContext() != mGlContext.data() ) + mGlContext.data()->makeCurrent( mGlContext.data()->surface() ); mGlFrameBuffer->bind(); - QCPPainter *result = new QCPPainter(mGlPaintDevice.data()); - result->setRenderHint(QPainter::HighQualityAntialiasing); + QCPPainter* result = new QCPPainter( mGlPaintDevice.data() ); + result->setRenderHint( QPainter::HighQualityAntialiasing ); return result; } /* inherits documentation from base class */ void QCPPaintBufferGlFbo::donePainting() { - if (mGlFrameBuffer && mGlFrameBuffer->isBound()) + if( mGlFrameBuffer && mGlFrameBuffer->isBound() ) mGlFrameBuffer->release(); else qDebug() << Q_FUNC_INFO << "Either OpenGL frame buffer not valid or was not bound"; } /* inherits documentation from base class */ -void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const +void QCPPaintBufferGlFbo::draw( QCPPainter* painter ) const { - if (!painter || !painter->isActive()) + if( !painter || !painter->isActive() ) { qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed"; return; } - if (!mGlFrameBuffer) + if( !mGlFrameBuffer ) { qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; return; } - painter->drawImage(0, 0, mGlFrameBuffer->toImage()); + painter->drawImage( 0, 0, mGlFrameBuffer->toImage() ); } /* inherits documentation from base class */ -void QCPPaintBufferGlFbo::clear(const QColor &color) +void QCPPaintBufferGlFbo::clear( const QColor& color ) { - if (mGlContext.isNull()) + if( mGlContext.isNull() ) { qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; return; } - if (!mGlFrameBuffer) + if( !mGlFrameBuffer ) { qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?"; return; } - - if (QOpenGLContext::currentContext() != mGlContext.data()) - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + + if( QOpenGLContext::currentContext() != mGlContext.data() ) + mGlContext.data()->makeCurrent( mGlContext.data()->surface() ); mGlFrameBuffer->bind(); - glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor( color.redF(), color.greenF(), color.blueF(), color.alphaF() ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); mGlFrameBuffer->release(); } @@ -915,41 +898,40 @@ void QCPPaintBufferGlFbo::clear(const QColor &color) void QCPPaintBufferGlFbo::reallocateBuffer() { // release and delete possibly existing framebuffer: - if (mGlFrameBuffer) + if( mGlFrameBuffer ) { - if (mGlFrameBuffer->isBound()) + if( mGlFrameBuffer->isBound() ) mGlFrameBuffer->release(); delete mGlFrameBuffer; mGlFrameBuffer = 0; } - - if (mGlContext.isNull()) + + if( mGlContext.isNull() ) { qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; return; } - if (mGlPaintDevice.isNull()) + if( mGlPaintDevice.isNull() ) { qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; return; } - + // create new fbo with appropriate size: - mGlContext.data()->makeCurrent(mGlContext.data()->surface()); + mGlContext.data()->makeCurrent( mGlContext.data()->surface() ); QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples(mGlContext.data()->format().samples()); - frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); - mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); - if (mGlPaintDevice.data()->size() != mSize*mDevicePixelRatio) - mGlPaintDevice.data()->setSize(mSize*mDevicePixelRatio); + frameBufferFormat.setSamples( mGlContext.data()->format().samples() ); + frameBufferFormat.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil ); + mGlFrameBuffer = new QOpenGLFramebufferObject( mSize * mDevicePixelRatio, frameBufferFormat ); + if( mGlPaintDevice.data()->size() != mSize * mDevicePixelRatio ) + mGlPaintDevice.data()->setSize( mSize * mDevicePixelRatio ); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mGlPaintDevice.data()->setDevicePixelRatio(mDevicePixelRatio); + mGlPaintDevice.data()->setDevicePixelRatio( mDevicePixelRatio ); #endif } -#endif // QCP_OPENGL_FBO +#endif // QCP_OPENGL_FBO /* end of 'src/paintbuffer.cpp' */ - /* including file 'src/layer.cpp', size 37304 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1039,13 +1021,10 @@ void QCPPaintBufferGlFbo::reallocateBuffer() \warning It is not checked that \a layerName is actually a unique layer name in \a parentPlot. This check is only performed by \ref QCustomPlot::addLayer. */ -QCPLayer::QCPLayer(QCustomPlot *parentPlot, const QString &layerName) : - QObject(parentPlot), - mParentPlot(parentPlot), - mName(layerName), - mIndex(-1), // will be set to a proper value by the QCustomPlot layer creation function - mVisible(true), - mMode(lmLogical) +QCPLayer::QCPLayer( QCustomPlot* parentPlot, const QString& layerName ) + : QObject( parentPlot ), mParentPlot( parentPlot ), mName( layerName ), mIndex( -1 ), // will be set to a proper value by the QCustomPlot layer creation function + mVisible( true ) + , mMode( lmLogical ) { // Note: no need to make sure layerName is unique, because layer // management is done with QCustomPlot functions. @@ -1057,11 +1036,11 @@ QCPLayer::~QCPLayer() // then invalid layer once they get deleted/moved themselves. This only happens when layers are deleted // directly, like in the QCustomPlot destructor. (The regular layer removal procedure for the user is to // call QCustomPlot::removeLayer, which moves all layerables off this layer before deleting it.) - - while (!mChildren.isEmpty()) - mChildren.last()->setLayer(0); // removes itself from mChildren via removeChild() - - if (mParentPlot->currentLayer() == this) + + while( !mChildren.isEmpty() ) + mChildren.last()->setLayer( 0 ); // removes itself from mChildren via removeChild() + + if( mParentPlot->currentLayer() == this ) qDebug() << Q_FUNC_INFO << "The parent plot's mCurrentLayer will be a dangling pointer. Should have been set to a valid layer or 0 beforehand."; } @@ -1073,7 +1052,7 @@ QCPLayer::~QCPLayer() QCPLayerable::setVisible), but the \ref QCPLayerable::realVisibility of each layerable takes the visibility of the parent layer into account. */ -void QCPLayer::setVisible(bool visible) +void QCPLayer::setVisible( bool visible ) { mVisible = visible; } @@ -1099,12 +1078,12 @@ void QCPLayer::setVisible(bool visible) \see replot */ -void QCPLayer::setMode(QCPLayer::LayerMode mode) +void QCPLayer::setMode( QCPLayer::LayerMode mode ) { - if (mMode != mode) + if( mMode != mode ) { mMode = mode; - if (!mPaintBuffer.isNull()) + if( !mPaintBuffer.isNull() ) mPaintBuffer.data()->setInvalidated(); } } @@ -1115,16 +1094,16 @@ void QCPLayer::setMode(QCPLayer::LayerMode mode) \see replot, drawToPaintBuffer */ -void QCPLayer::draw(QCPPainter *painter) +void QCPLayer::draw( QCPPainter* painter ) { - foreach (QCPLayerable *child, mChildren) + foreach( QCPLayerable* child, mChildren ) { - if (child->realVisibility()) + if( child->realVisibility() ) { painter->save(); - painter->setClipRect(child->clipRect().translated(0, -1)); - child->applyDefaultAntialiasingHint(painter); - child->draw(painter); + painter->setClipRect( child->clipRect().translated( 0, -1 ) ); + child->applyDefaultAntialiasingHint( painter ); + child->draw( painter ); painter->restore(); } } @@ -1140,19 +1119,21 @@ void QCPLayer::draw(QCPPainter *painter) */ void QCPLayer::drawToPaintBuffer() { - if (!mPaintBuffer.isNull()) + if( !mPaintBuffer.isNull() ) { - if (QCPPainter *painter = mPaintBuffer.data()->startPainting()) + if( QCPPainter* painter = mPaintBuffer.data()->startPainting() ) { - if (painter->isActive()) - draw(painter); + if( painter->isActive() ) + draw( painter ); else qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; delete painter; mPaintBuffer.data()->donePainting(); - } else + } + else qDebug() << Q_FUNC_INFO << "paint buffer returned zero painter"; - } else + } + else qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; } @@ -1171,17 +1152,19 @@ void QCPLayer::drawToPaintBuffer() */ void QCPLayer::replot() { - if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) + if( mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers() ) { - if (!mPaintBuffer.isNull()) + if( !mPaintBuffer.isNull() ) { - mPaintBuffer.data()->clear(Qt::transparent); + mPaintBuffer.data()->clear( Qt::transparent ); drawToPaintBuffer(); - mPaintBuffer.data()->setInvalidated(false); + mPaintBuffer.data()->setInvalidated( false ); mParentPlot->update(); - } else + } + else qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } else if (mMode == lmLogical) + } + else if( mMode == lmLogical ) mParentPlot->replot(); } @@ -1195,18 +1178,19 @@ void QCPLayer::replot() \see removeChild */ -void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) +void QCPLayer::addChild( QCPLayerable* layerable, bool prepend ) { - if (!mChildren.contains(layerable)) + if( !mChildren.contains( layerable ) ) { - if (prepend) - mChildren.prepend(layerable); + if( prepend ) + mChildren.prepend( layerable ); else - mChildren.append(layerable); - if (!mPaintBuffer.isNull()) + mChildren.append( layerable ); + if( !mPaintBuffer.isNull() ) mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast(layerable); + } + else + qDebug() << Q_FUNC_INFO << "layerable is already child of this layer" << reinterpret_cast( layerable ); } /*! \internal @@ -1218,17 +1202,17 @@ void QCPLayer::addChild(QCPLayerable *layerable, bool prepend) \see addChild */ -void QCPLayer::removeChild(QCPLayerable *layerable) +void QCPLayer::removeChild( QCPLayerable* layerable ) { - if (mChildren.removeOne(layerable)) + if( mChildren.removeOne( layerable ) ) { - if (!mPaintBuffer.isNull()) + if( !mPaintBuffer.isNull() ) mPaintBuffer.data()->setInvalidated(); - } else - qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast(layerable); + } + else + qDebug() << Q_FUNC_INFO << "layerable is not child of this layer" << reinterpret_cast( layerable ); } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayerable //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1336,28 +1320,23 @@ void QCPLayer::removeChild(QCPLayerable *layerable) plot does. It is not uncommon to set the QObject-parent to something else in the constructors of QCPLayerable subclasses, to guarantee a working destruction hierarchy. */ -QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : - QObject(plot), - mVisible(true), - mParentPlot(plot), - mParentLayerable(parentLayerable), - mLayer(0), - mAntialiased(true) +QCPLayerable::QCPLayerable( QCustomPlot* plot, QString targetLayer, QCPLayerable* parentLayerable ) + : QObject( plot ), mVisible( true ), mParentPlot( plot ), mParentLayerable( parentLayerable ), mLayer( 0 ), mAntialiased( true ) { - if (mParentPlot) + if( mParentPlot ) { - if (targetLayer.isEmpty()) - setLayer(mParentPlot->currentLayer()); - else if (!setLayer(targetLayer)) + if( targetLayer.isEmpty() ) + setLayer( mParentPlot->currentLayer() ); + else if( !setLayer( targetLayer ) ) qDebug() << Q_FUNC_INFO << "setting QCPlayerable initial layer to" << targetLayer << "failed."; } } QCPLayerable::~QCPLayerable() { - if (mLayer) + if( mLayer ) { - mLayer->removeChild(this); + mLayer->removeChild( this ); mLayer = 0; } } @@ -1367,7 +1346,7 @@ QCPLayerable::~QCPLayerable() on the QCustomPlot surface, and user interaction with it (e.g. click and selection) is not possible. */ -void QCPLayerable::setVisible(bool on) +void QCPLayerable::setVisible( bool on ) { mVisible = on; } @@ -1381,9 +1360,9 @@ void QCPLayerable::setVisible(bool on) Returns true if the layer of this layerable was successfully changed to \a layer. */ -bool QCPLayerable::setLayer(QCPLayer *layer) +bool QCPLayerable::setLayer( QCPLayer* layer ) { - return moveToLayer(layer, false); + return moveToLayer( layer, false ); } /*! \overload @@ -1391,17 +1370,18 @@ bool QCPLayerable::setLayer(QCPLayer *layer) Returns true on success, i.e. if \a layerName is a valid layer name. */ -bool QCPLayerable::setLayer(const QString &layerName) +bool QCPLayerable::setLayer( const QString& layerName ) { - if (!mParentPlot) + if( !mParentPlot ) { qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; return false; } - if (QCPLayer *layer = mParentPlot->layer(layerName)) + if( QCPLayer* layer = mParentPlot->layer( layerName ) ) { - return setLayer(layer); - } else + return setLayer( layer ); + } + else { qDebug() << Q_FUNC_INFO << "there is no layer with name" << layerName; return false; @@ -1414,7 +1394,7 @@ bool QCPLayerable::setLayer(const QString &layerName) Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements. */ -void QCPLayerable::setAntialiased(bool enabled) +void QCPLayerable::setAntialiased( bool enabled ) { mAntialiased = enabled; } @@ -1431,7 +1411,7 @@ void QCPLayerable::setAntialiased(bool enabled) */ bool QCPLayerable::realVisibility() const { - return mVisible && (!mLayer || mLayer->visible()) && (!mParentLayerable || mParentLayerable.data()->realVisibility()); + return mVisible && ( !mLayer || mLayer->visible() ) && ( !mParentLayerable || mParentLayerable.data()->realVisibility() ); } /*! @@ -1472,11 +1452,11 @@ bool QCPLayerable::realVisibility() const \see selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions, QCPAbstractPlottable1D::selectTestRect */ -double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPLayerable::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(pos) - Q_UNUSED(onlySelectable) - Q_UNUSED(details) + Q_UNUSED( pos ) + Q_UNUSED( onlySelectable ) + Q_UNUSED( details ) return -1.0; } @@ -1497,19 +1477,19 @@ double QCPLayerable::selectTest(const QPointF &pos, bool onlySelectable, QVarian so they can react accordingly (e.g. also initialize the parent plot of child layerables, like QCPLayout does). */ -void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) +void QCPLayerable::initializeParentPlot( QCustomPlot* parentPlot ) { - if (mParentPlot) + if( mParentPlot ) { qDebug() << Q_FUNC_INFO << "called with mParentPlot already initialized"; return; } - - if (!parentPlot) + + if( !parentPlot ) qDebug() << Q_FUNC_INFO << "called with parentPlot zero"; - + mParentPlot = parentPlot; - parentPlotInitialized(mParentPlot); + parentPlotInitialized( mParentPlot ); } /*! \internal @@ -1523,7 +1503,7 @@ void QCPLayerable::initializeParentPlot(QCustomPlot *parentPlot) \see realVisibility */ -void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) +void QCPLayerable::setParentLayerable( QCPLayerable* parentLayerable ) { mParentLayerable = parentLayerable; } @@ -1536,27 +1516,27 @@ void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) Returns true on success, i.e. if \a layer is a valid layer. */ -bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) +bool QCPLayerable::moveToLayer( QCPLayer* layer, bool prepend ) { - if (layer && !mParentPlot) + if( layer && !mParentPlot ) { qDebug() << Q_FUNC_INFO << "no parent QCustomPlot set"; return false; } - if (layer && layer->parentPlot() != mParentPlot) + if( layer && layer->parentPlot() != mParentPlot ) { qDebug() << Q_FUNC_INFO << "layer" << layer->name() << "is not in same QCustomPlot as this layerable"; return false; } - - QCPLayer *oldLayer = mLayer; - if (mLayer) - mLayer->removeChild(this); + + QCPLayer* oldLayer = mLayer; + if( mLayer ) + mLayer->removeChild( this ); mLayer = layer; - if (mLayer) - mLayer->addChild(this, prepend); - if (mLayer != oldLayer) - emit layerChanged(mLayer); + if( mLayer ) + mLayer->addChild( this, prepend ); + if( mLayer != oldLayer ) + emit layerChanged( mLayer ); return true; } @@ -1567,14 +1547,14 @@ bool QCPLayerable::moveToLayer(QCPLayer *layer, bool prepend) QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is controlled via \a overrideElement. */ -void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const +void QCPLayerable::applyAntialiasingHint( QCPPainter* painter, bool localAntialiased, QCP::AntialiasedElement overrideElement ) const { - if (mParentPlot && mParentPlot->notAntialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(false); - else if (mParentPlot && mParentPlot->antialiasedElements().testFlag(overrideElement)) - painter->setAntialiasing(true); + if( mParentPlot && mParentPlot->notAntialiasedElements().testFlag( overrideElement ) ) + painter->setAntialiasing( false ); + else if( mParentPlot && mParentPlot->antialiasedElements().testFlag( overrideElement ) ) + painter->setAntialiasing( true ); else - painter->setAntialiasing(localAntialiased); + painter->setAntialiasing( localAntialiased ); } /*! \internal @@ -1593,9 +1573,9 @@ void QCPLayerable::applyAntialiasingHint(QCPPainter *painter, bool localAntialia \see initializeParentPlot */ -void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) +void QCPLayerable::parentPlotInitialized( QCustomPlot* parentPlot ) { - Q_UNUSED(parentPlot) + Q_UNUSED( parentPlot ) } /*! \internal @@ -1625,7 +1605,7 @@ QCP::Interaction QCPLayerable::selectionCategory() const */ QRect QCPLayerable::clipRect() const { - if (mParentPlot) + if( mParentPlot ) return mParentPlot->viewport(); else return QRect(); @@ -1659,12 +1639,12 @@ QRect QCPLayerable::clipRect() const \see selectTest, deselectEvent */ -void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPLayerable::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - Q_UNUSED(additive) - Q_UNUSED(details) - Q_UNUSED(selectionStateChanged) + Q_UNUSED( event ) + Q_UNUSED( additive ) + Q_UNUSED( details ) + Q_UNUSED( selectionStateChanged ) } /*! \internal @@ -1679,9 +1659,9 @@ void QCPLayerable::selectEvent(QMouseEvent *event, bool additive, const QVariant \see selectTest, selectEvent */ -void QCPLayerable::deselectEvent(bool *selectionStateChanged) +void QCPLayerable::deselectEvent( bool* selectionStateChanged ) { - Q_UNUSED(selectionStateChanged) + Q_UNUSED( selectionStateChanged ) } /*! @@ -1709,9 +1689,9 @@ void QCPLayerable::deselectEvent(bool *selectionStateChanged) \see mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent */ -void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) +void QCPLayerable::mousePressEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) + Q_UNUSED( details ) event->ignore(); } @@ -1727,9 +1707,9 @@ void QCPLayerable::mousePressEvent(QMouseEvent *event, const QVariant &details) \see mousePressEvent, mouseReleaseEvent, mouseDoubleClickEvent, wheelEvent */ -void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +void QCPLayerable::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) { - Q_UNUSED(startPos) + Q_UNUSED( startPos ) event->ignore(); } @@ -1745,9 +1725,9 @@ void QCPLayerable::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) \see mousePressEvent, mouseMoveEvent, mouseDoubleClickEvent, wheelEvent */ -void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +void QCPLayerable::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) { - Q_UNUSED(startPos) + Q_UNUSED( startPos ) event->ignore(); } @@ -1777,9 +1757,9 @@ void QCPLayerable::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, wheelEvent */ -void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +void QCPLayerable::mouseDoubleClickEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) + Q_UNUSED( details ) event->ignore(); } @@ -1800,13 +1780,12 @@ void QCPLayerable::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &det \see mousePressEvent, mouseMoveEvent, mouseReleaseEvent, mouseDoubleClickEvent */ -void QCPLayerable::wheelEvent(QWheelEvent *event) +void QCPLayerable::wheelEvent( QWheelEvent* event ) { event->ignore(); } /* end of 'src/layer.cpp' */ - /* including file 'src/axis/range.cpp', size 12221 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1896,9 +1875,8 @@ const double QCPRange::maxRange = 1e250; /*! Constructs a range with \a lower and \a upper set to zero. */ -QCPRange::QCPRange() : - lower(0), - upper(0) +QCPRange::QCPRange() + : lower( 0 ), upper( 0 ) { } @@ -1909,9 +1887,8 @@ QCPRange::QCPRange() : The resulting range will be normalized (see \ref normalize), so if \a lower is not numerically smaller than \a upper, they will be swapped. */ -QCPRange::QCPRange(double lower, double upper) : - lower(lower), - upper(upper) +QCPRange::QCPRange( double lower, double upper ) + : lower( lower ), upper( upper ) { normalize(); } @@ -1928,11 +1905,11 @@ QCPRange::QCPRange(double lower, double upper) : \see expanded */ -void QCPRange::expand(const QCPRange &otherRange) +void QCPRange::expand( const QCPRange& otherRange ) { - if (lower > otherRange.lower || qIsNaN(lower)) + if( lower > otherRange.lower || qIsNaN( lower ) ) lower = otherRange.lower; - if (upper < otherRange.upper || qIsNaN(upper)) + if( upper < otherRange.upper || qIsNaN( upper ) ) upper = otherRange.upper; } @@ -1948,15 +1925,14 @@ void QCPRange::expand(const QCPRange &otherRange) \see expand */ -void QCPRange::expand(double includeCoord) +void QCPRange::expand( double includeCoord ) { - if (lower > includeCoord || qIsNaN(lower)) + if( lower > includeCoord || qIsNaN( lower ) ) lower = includeCoord; - if (upper < includeCoord || qIsNaN(upper)) + if( upper < includeCoord || qIsNaN( upper ) ) upper = includeCoord; } - /*! \overload Returns an expanded range that contains this and \a otherRange. It is assumed that both this @@ -1967,10 +1943,10 @@ void QCPRange::expand(double includeCoord) \see expand */ -QCPRange QCPRange::expanded(const QCPRange &otherRange) const +QCPRange QCPRange::expanded( const QCPRange& otherRange ) const { QCPRange result = *this; - result.expand(otherRange); + result.expand( otherRange ); return result; } @@ -1984,10 +1960,10 @@ QCPRange QCPRange::expanded(const QCPRange &otherRange) const \see expand */ -QCPRange QCPRange::expanded(double includeCoord) const +QCPRange QCPRange::expanded( double includeCoord ) const { QCPRange result = *this; - result.expand(includeCoord); + result.expand( includeCoord ); return result; } @@ -1999,26 +1975,27 @@ QCPRange QCPRange::expanded(double includeCoord) const QCPRange::maxRange. If it shall only be bounded at the upper side, set \a lowerBound to -\ref QCPRange::maxRange. */ -QCPRange QCPRange::bounded(double lowerBound, double upperBound) const +QCPRange QCPRange::bounded( double lowerBound, double upperBound ) const { - if (lowerBound > upperBound) - qSwap(lowerBound, upperBound); - - QCPRange result(lower, upper); - if (result.lower < lowerBound) + if( lowerBound > upperBound ) + qSwap( lowerBound, upperBound ); + + QCPRange result( lower, upper ); + if( result.lower < lowerBound ) { result.lower = lowerBound; result.upper = lowerBound + size(); - if (result.upper > upperBound || qFuzzyCompare(size(), upperBound-lowerBound)) + if( result.upper > upperBound || qFuzzyCompare( size(), upperBound - lowerBound ) ) result.upper = upperBound; - } else if (result.upper > upperBound) + } + else if( result.upper > upperBound ) { result.upper = upperBound; result.lower = upperBound - size(); - if (result.lower < lowerBound || qFuzzyCompare(size(), upperBound-lowerBound)) + if( result.lower < lowerBound || qFuzzyCompare( size(), upperBound - lowerBound ) ) result.lower = lowerBound; } - + return result; } @@ -2037,42 +2014,44 @@ QCPRange QCPRange::bounded(double lowerBound, double upperBound) const QCPRange QCPRange::sanitizedForLogScale() const { double rangeFac = 1e-3; - QCPRange sanitizedRange(lower, upper); + QCPRange sanitizedRange( lower, upper ); sanitizedRange.normalize(); // can't have range spanning negative and positive values in log plot, so change range to fix it //if (qFuzzyCompare(sanitizedRange.lower+1, 1) && !qFuzzyCompare(sanitizedRange.upper+1, 1)) - if (sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0) + if( sanitizedRange.lower == 0.0 && sanitizedRange.upper != 0.0 ) { // case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) + if( rangeFac < sanitizedRange.upper * rangeFac ) sanitizedRange.lower = rangeFac; else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; - } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) - else if (sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0) + sanitizedRange.lower = sanitizedRange.upper * rangeFac; + } //else if (!qFuzzyCompare(lower+1, 1) && qFuzzyCompare(upper+1, 1)) + else if( sanitizedRange.lower != 0.0 && sanitizedRange.upper == 0.0 ) { // case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) + if( -rangeFac > sanitizedRange.lower * rangeFac ) sanitizedRange.upper = -rangeFac; else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else if (sanitizedRange.lower < 0 && sanitizedRange.upper > 0) + sanitizedRange.upper = sanitizedRange.lower * rangeFac; + } + else if( sanitizedRange.lower < 0 && sanitizedRange.upper > 0 ) { // find out whether negative or positive interval is wider to decide which sign domain will be chosen - if (-sanitizedRange.lower > sanitizedRange.upper) + if( -sanitizedRange.lower > sanitizedRange.upper ) { // negative is wider, do same as in case upper is 0 - if (-rangeFac > sanitizedRange.lower*rangeFac) + if( -rangeFac > sanitizedRange.lower * rangeFac ) sanitizedRange.upper = -rangeFac; else - sanitizedRange.upper = sanitizedRange.lower*rangeFac; - } else + sanitizedRange.upper = sanitizedRange.lower * rangeFac; + } + else { // positive is wider, do same as in case lower is 0 - if (rangeFac < sanitizedRange.upper*rangeFac) + if( rangeFac < sanitizedRange.upper * rangeFac ) sanitizedRange.lower = rangeFac; else - sanitizedRange.lower = sanitizedRange.upper*rangeFac; + sanitizedRange.lower = sanitizedRange.upper * rangeFac; } } // due to normalization, case lower>0 && upper<0 should never occur, because that implies upper -maxRange && - upper < maxRange && - qAbs(lower-upper) > minRange && - qAbs(lower-upper) < maxRange && - !(lower > 0 && qIsInf(upper/lower)) && - !(upper < 0 && qIsInf(lower/upper))); + return ( lower > -maxRange && + upper < maxRange && + qAbs( lower - upper ) > minRange && + qAbs( lower - upper ) < maxRange && + !( lower > 0 && qIsInf( upper / lower ) ) && + !( upper < 0 && qIsInf( lower / upper ) ) ); } /*! @@ -2117,18 +2096,17 @@ bool QCPRange::validRange(double lower, double upper) \li range size above minRange \li range size below maxRange */ -bool QCPRange::validRange(const QCPRange &range) +bool QCPRange::validRange( const QCPRange& range ) { - return (range.lower > -maxRange && - range.upper < maxRange && - qAbs(range.lower-range.upper) > minRange && - qAbs(range.lower-range.upper) < maxRange && - !(range.lower > 0 && qIsInf(range.upper/range.lower)) && - !(range.upper < 0 && qIsInf(range.lower/range.upper))); + return ( range.lower > -maxRange && + range.upper < maxRange && + qAbs( range.lower - range.upper ) > minRange && + qAbs( range.lower - range.upper ) < maxRange && + !( range.lower > 0 && qIsInf( range.upper / range.lower ) ) && + !( range.upper < 0 && qIsInf( range.lower / range.upper ) ) ); } /* end of 'src/axis/range.cpp' */ - /* including file 'src/selection.cpp', size 21941 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -2227,9 +2205,8 @@ bool QCPRange::validRange(const QCPRange &range) /*! Creates an empty QCPDataRange, with begin and end set to 0. */ -QCPDataRange::QCPDataRange() : - mBegin(0), - mEnd(0) +QCPDataRange::QCPDataRange() + : mBegin( 0 ), mEnd( 0 ) { } @@ -2238,9 +2215,8 @@ QCPDataRange::QCPDataRange() : No checks or corrections are made to ensure the resulting range is valid (\ref isValid). */ -QCPDataRange::QCPDataRange(int begin, int end) : - mBegin(begin), - mEnd(end) +QCPDataRange::QCPDataRange( int begin, int end ) + : mBegin( begin ), mEnd( end ) { } @@ -2253,15 +2229,15 @@ QCPDataRange::QCPDataRange(int begin, int end) : to the respective boundary side of \a other, at which this range is residing. (\ref intersection would just return a range with begin and end set to 0.) */ -QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const +QCPDataRange QCPDataRange::bounded( const QCPDataRange& other ) const { - QCPDataRange result(intersection(other)); - if (result.isEmpty()) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value + QCPDataRange result( intersection( other ) ); + if( result.isEmpty() ) // no intersection, preserve respective bounding side of otherRange as both begin and end of return value { - if (mEnd <= other.mBegin) - result = QCPDataRange(other.mBegin, other.mBegin); + if( mEnd <= other.mBegin ) + result = QCPDataRange( other.mBegin, other.mBegin ); else - result = QCPDataRange(other.mEnd, other.mEnd); + result = QCPDataRange( other.mEnd, other.mEnd ); } return result; } @@ -2269,9 +2245,9 @@ QCPDataRange QCPDataRange::bounded(const QCPDataRange &other) const /*! Returns a data range that contains both this data range as well as \a other. */ -QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const +QCPDataRange QCPDataRange::expanded( const QCPDataRange& other ) const { - return QCPDataRange(qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)); + return QCPDataRange( qMin( mBegin, other.mBegin ), qMax( mEnd, other.mEnd ) ); } /*! @@ -2284,10 +2260,10 @@ QCPDataRange QCPDataRange::expanded(const QCPDataRange &other) const \see QCPDataSelection::intersection */ -QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const +QCPDataRange QCPDataRange::intersection( const QCPDataRange& other ) const { - QCPDataRange result(qMax(mBegin, other.mBegin), qMin(mEnd, other.mEnd)); - if (result.isValid()) + QCPDataRange result( qMax( mBegin, other.mBegin ), qMin( mEnd, other.mEnd ) ); + if( result.isValid() ) return result; else return QCPDataRange(); @@ -2298,10 +2274,10 @@ QCPDataRange QCPDataRange::intersection(const QCPDataRange &other) const \see intersection, contains */ -bool QCPDataRange::intersects(const QCPDataRange &other) const +bool QCPDataRange::intersects( const QCPDataRange& other ) const { - return !( (mBegin > other.mBegin && mBegin >= other.mEnd) || - (mEnd <= other.mBegin && mEnd < other.mEnd) ); + return !( ( mBegin > other.mBegin && mBegin >= other.mEnd ) || + ( mEnd <= other.mBegin && mEnd < other.mEnd ) ); } /*! @@ -2309,13 +2285,11 @@ bool QCPDataRange::intersects(const QCPDataRange &other) const \see intersects */ -bool QCPDataRange::contains(const QCPDataRange &other) const +bool QCPDataRange::contains( const QCPDataRange& other ) const { return mBegin <= other.mBegin && mEnd >= other.mEnd; } - - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPDataSelection //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2392,9 +2366,9 @@ QCPDataSelection::QCPDataSelection() /*! Creates a QCPDataSelection containing the provided \a range. */ -QCPDataSelection::QCPDataSelection(const QCPDataRange &range) +QCPDataSelection::QCPDataSelection( const QCPDataRange& range ) { - mDataRanges.append(range); + mDataRanges.append( range ); } /*! @@ -2404,13 +2378,13 @@ QCPDataSelection::QCPDataSelection(const QCPDataRange &range) Note that both data selections must be in simplified state (the usual state of the selection, see \ref simplify) for this operator to return correct results. */ -bool QCPDataSelection::operator==(const QCPDataSelection &other) const +bool QCPDataSelection::operator==( const QCPDataSelection& other ) const { - if (mDataRanges.size() != other.mDataRanges.size()) + if( mDataRanges.size() != other.mDataRanges.size() ) return false; - for (int i=0; i= other.end()) - break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this - - if (thisEnd > other.begin()) // ranges which don't fulfill this are entirely before other and can be ignored + const int thisBegin = mDataRanges.at( i ).begin(); + const int thisEnd = mDataRanges.at( i ).end(); + if( thisBegin >= other.end() ) + break; // since data ranges are sorted after the simplify() call, no ranges which contain other will come after this + + if( thisEnd > other.begin() ) // ranges which don't fulfill this are entirely before other and can be ignored { - if (thisBegin >= other.begin()) // range leading segment is encompassed + if( thisBegin >= other.begin() ) // range leading segment is encompassed { - if (thisEnd <= other.end()) // range fully encompassed, remove completely + if( thisEnd <= other.end() ) // range fully encompassed, remove completely { - mDataRanges.removeAt(i); + mDataRanges.removeAt( i ); continue; - } else // only leading segment is encompassed, trim accordingly - mDataRanges[i].setBegin(other.end()); - } else // leading segment is not encompassed + } + else // only leading segment is encompassed, trim accordingly + mDataRanges[i].setBegin( other.end() ); + } + else // leading segment is not encompassed { - if (thisEnd <= other.end()) // only trailing segment is encompassed, trim accordingly + if( thisEnd <= other.end() ) // only trailing segment is encompassed, trim accordingly { - mDataRanges[i].setEnd(other.begin()); - } else // other lies inside this range, so split range + mDataRanges[i].setEnd( other.begin() ); + } + else // other lies inside this range, so split range { - mDataRanges[i].setEnd(other.begin()); - mDataRanges.insert(i+1, QCPDataRange(other.end(), thisEnd)); - break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here + mDataRanges[i].setEnd( other.begin() ); + mDataRanges.insert( i + 1, QCPDataRange( other.end(), thisEnd ) ); + break; // since data ranges are sorted (and don't overlap) after simplify() call, we're done here } } } ++i; } - + return *this; } @@ -2501,8 +2478,8 @@ QCPDataSelection &QCPDataSelection::operator-=(const QCPDataRange &other) int QCPDataSelection::dataPointCount() const { int result = 0; - for (int i=0; i= 0 && index < mDataRanges.size()) + if( index >= 0 && index < mDataRanges.size() ) { - return mDataRanges.at(index); - } else + return mDataRanges.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of range:" << index; return QCPDataRange(); @@ -2532,10 +2510,10 @@ QCPDataRange QCPDataSelection::dataRange(int index) const */ QCPDataRange QCPDataSelection::span() const { - if (isEmpty()) + if( isEmpty() ) return QCPDataRange(); else - return QCPDataRange(mDataRanges.first().begin(), mDataRanges.last().end()); + return QCPDataRange( mDataRanges.first().begin(), mDataRanges.last().end() ); } /*! @@ -2544,10 +2522,10 @@ QCPDataRange QCPDataSelection::span() const performance if adding a very large amount of data ranges successively. In this case, make sure to call \ref simplify manually, after the operation. */ -void QCPDataSelection::addDataRange(const QCPDataRange &dataRange, bool simplify) +void QCPDataSelection::addDataRange( const QCPDataRange& dataRange, bool simplify ) { - mDataRanges.append(dataRange); - if (simplify) + mDataRanges.append( dataRange ); + if( simplify ) this->simplify(); } @@ -2573,26 +2551,27 @@ void QCPDataSelection::clear() void QCPDataSelection::simplify() { // remove any empty ranges: - for (int i=mDataRanges.size()-1; i>=0; --i) + for( int i = mDataRanges.size() - 1; i >= 0; --i ) { - if (mDataRanges.at(i).isEmpty()) - mDataRanges.removeAt(i); + if( mDataRanges.at( i ).isEmpty() ) + mDataRanges.removeAt( i ); } - if (mDataRanges.isEmpty()) + if( mDataRanges.isEmpty() ) return; - + // sort ranges by starting value, ascending: - std::sort(mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin); - + std::sort( mDataRanges.begin(), mDataRanges.end(), lessThanDataRangeBegin ); + // join overlapping/contiguous ranges: int i = 1; - while (i < mDataRanges.size()) + while( i < mDataRanges.size() ) { - if (mDataRanges.at(i-1).end() >= mDataRanges.at(i).begin()) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list + if( mDataRanges.at( i - 1 ).end() >= mDataRanges.at( i ).begin() ) // range i overlaps/joins with i-1, so expand range i-1 appropriately and remove range i from list { - mDataRanges[i-1].setEnd(qMax(mDataRanges.at(i-1).end(), mDataRanges.at(i).end())); - mDataRanges.removeAt(i); - } else + mDataRanges[i - 1].setEnd( qMax( mDataRanges.at( i - 1 ).end(), mDataRanges.at( i ).end() ) ); + mDataRanges.removeAt( i ); + } + else ++i; } } @@ -2607,44 +2586,39 @@ void QCPDataSelection::simplify() \see QCP::SelectionType */ -void QCPDataSelection::enforceType(QCP::SelectionType type) +void QCPDataSelection::enforceType( QCP::SelectionType type ) { simplify(); - switch (type) + switch( type ) { - case QCP::stNone: + case QCP::stNone: { + mDataRanges.clear(); + break; + } + case QCP::stWhole: { + // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) + break; + } + case QCP::stSingleData: { + // reduce all data ranges to the single first data point: + if( !mDataRanges.isEmpty() ) { - mDataRanges.clear(); - break; - } - case QCP::stWhole: - { - // whole selection isn't defined by data range, so don't change anything (is handled in plottable methods) - break; - } - case QCP::stSingleData: - { - // reduce all data ranges to the single first data point: - if (!mDataRanges.isEmpty()) - { - if (mDataRanges.size() > 1) - mDataRanges = QList() << mDataRanges.first(); - if (mDataRanges.first().length() > 1) - mDataRanges.first().setEnd(mDataRanges.first().begin()+1); - } - break; - } - case QCP::stDataRange: - { - if (!isEmpty()) - mDataRanges = QList() << span(); - break; - } - case QCP::stMultipleDataRanges: - { - // this is the selection type that allows all concievable combinations of ranges, so do nothing - break; + if( mDataRanges.size() > 1 ) + mDataRanges = QList() << mDataRanges.first(); + if( mDataRanges.first().length() > 1 ) + mDataRanges.first().setEnd( mDataRanges.first().begin() + 1 ); } + break; + } + case QCP::stDataRange: { + if( !isEmpty() ) + mDataRanges = QList() << span(); + break; + } + case QCP::stMultipleDataRanges: { + // this is the selection type that allows all concievable combinations of ranges, so do nothing + break; + } } } @@ -2654,20 +2628,21 @@ void QCPDataSelection::enforceType(QCP::SelectionType type) \see QCPDataRange::contains */ -bool QCPDataSelection::contains(const QCPDataSelection &other) const +bool QCPDataSelection::contains( const QCPDataSelection& other ) const { - if (other.isEmpty()) return false; - + if( other.isEmpty() ) + return false; + int otherIndex = 0; int thisIndex = 0; - while (thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size()) + while( thisIndex < mDataRanges.size() && otherIndex < other.mDataRanges.size() ) { - if (mDataRanges.at(thisIndex).contains(other.mDataRanges.at(otherIndex))) + if( mDataRanges.at( thisIndex ).contains( other.mDataRanges.at( otherIndex ) ) ) ++otherIndex; else ++thisIndex; } - return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this + return thisIndex < mDataRanges.size(); // if thisIndex ran all the way to the end to find a containing range for the current otherIndex, other is not contained in this } /*! @@ -2678,11 +2653,11 @@ bool QCPDataSelection::contains(const QCPDataSelection &other) const using \ref QCPDataContainer::dataRange as \a other. One can then safely iterate over the returned data selection without exceeding the data container's bounds. */ -QCPDataSelection QCPDataSelection::intersection(const QCPDataRange &other) const +QCPDataSelection QCPDataSelection::intersection( const QCPDataRange& other ) const { QCPDataSelection result; - for (int i=0; iorientation() == Qt::Horizontal) - return QCPRange(axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())); + if( axis->orientation() == Qt::Horizontal ) + return QCPRange( axis->pixelToCoord( mRect.left() ), axis->pixelToCoord( mRect.left() + mRect.width() ) ); else - return QCPRange(axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())); - } else + return QCPRange( axis->pixelToCoord( mRect.top() + mRect.height() ), axis->pixelToCoord( mRect.top() ) ); + } + else { qDebug() << Q_FUNC_INFO << "called with axis zero"; return QCPRange(); @@ -2853,7 +2825,7 @@ QCPRange QCPSelectionRect::range(const QCPAxis *axis) const \see setBrush */ -void QCPSelectionRect::setPen(const QPen &pen) +void QCPSelectionRect::setPen( const QPen& pen ) { mPen = pen; } @@ -2864,7 +2836,7 @@ void QCPSelectionRect::setPen(const QPen &pen) \see setPen */ -void QCPSelectionRect::setBrush(const QBrush &brush) +void QCPSelectionRect::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -2875,10 +2847,10 @@ void QCPSelectionRect::setBrush(const QBrush &brush) */ void QCPSelectionRect::cancel() { - if (mActive) + if( mActive ) { mActive = false; - emit canceled(mRect, 0); + emit canceled( mRect, 0 ); } } @@ -2888,11 +2860,11 @@ void QCPSelectionRect::cancel() The default implementation sets the selection rect to active, initializes the selection rect geometry and emits the \ref started signal. */ -void QCPSelectionRect::startSelection(QMouseEvent *event) +void QCPSelectionRect::startSelection( QMouseEvent* event ) { mActive = true; - mRect = QRect(event->pos(), event->pos()); - emit started(event); + mRect = QRect( event->pos(), event->pos() ); + emit started( event ); } /*! \internal @@ -2901,10 +2873,10 @@ void QCPSelectionRect::startSelection(QMouseEvent *event) to update its geometry. The default implementation updates the rect and emits the \ref changed signal. */ -void QCPSelectionRect::moveSelection(QMouseEvent *event) +void QCPSelectionRect::moveSelection( QMouseEvent* event ) { - mRect.setBottomRight(event->pos()); - emit changed(mRect, event); + mRect.setBottomRight( event->pos() ); + emit changed( mRect, event ); layer()->replot(); } @@ -2914,11 +2886,11 @@ void QCPSelectionRect::moveSelection(QMouseEvent *event) finished by the user releasing the mouse button. The default implementation deactivates the selection rect and emits the \ref accepted signal. */ -void QCPSelectionRect::endSelection(QMouseEvent *event) +void QCPSelectionRect::endSelection( QMouseEvent* event ) { - mRect.setBottomRight(event->pos()); + mRect.setBottomRight( event->pos() ); mActive = false; - emit accepted(mRect, event); + emit accepted( mRect, event ); } /*! \internal @@ -2927,19 +2899,19 @@ void QCPSelectionRect::endSelection(QMouseEvent *event) rect interaction is active. The default implementation allows to \ref cancel the interaction by hitting the escape key. */ -void QCPSelectionRect::keyPressEvent(QKeyEvent *event) +void QCPSelectionRect::keyPressEvent( QKeyEvent* event ) { - if (event->key() == Qt::Key_Escape && mActive) + if( event->key() == Qt::Key_Escape && mActive ) { mActive = false; - emit canceled(mRect, event); + emit canceled( mRect, event ); } } /* inherits documentation from base class */ -void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPSelectionRect::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); + applyAntialiasingHint( painter, mAntialiased, QCP::aeOther ); } /*! \internal @@ -2948,18 +2920,17 @@ void QCPSelectionRect::applyDefaultAntialiasingHint(QCPPainter *painter) const \seebaseclassmethod */ -void QCPSelectionRect::draw(QCPPainter *painter) +void QCPSelectionRect::draw( QCPPainter* painter ) { - if (mActive) + if( mActive ) { - painter->setPen(mPen); - painter->setBrush(mBrush); - painter->drawRect(mRect); + painter->setPen( mPen ); + painter->setBrush( mBrush ); + painter->drawRect( mRect ); } } /* end of 'src/selectionrect.cpp' */ - /* including file 'src/layout.cpp', size 79139 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -3011,14 +2982,13 @@ void QCPSelectionRect::draw(QCPPainter *painter) /*! Creates a new QCPMarginGroup instance in \a parentPlot. */ -QCPMarginGroup::QCPMarginGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot) +QCPMarginGroup::QCPMarginGroup( QCustomPlot* parentPlot ) + : QObject( parentPlot ), mParentPlot( parentPlot ) { - mChildren.insert(QCP::msLeft, QList()); - mChildren.insert(QCP::msRight, QList()); - mChildren.insert(QCP::msTop, QList()); - mChildren.insert(QCP::msBottom, QList()); + mChildren.insert( QCP::msLeft, QList() ); + mChildren.insert( QCP::msRight, QList() ); + mChildren.insert( QCP::msTop, QList() ); + mChildren.insert( QCP::msBottom, QList() ); } QCPMarginGroup::~QCPMarginGroup() @@ -3032,11 +3002,11 @@ QCPMarginGroup::~QCPMarginGroup() */ bool QCPMarginGroup::isEmpty() const { - QHashIterator > it(mChildren); - while (it.hasNext()) + QHashIterator > it( mChildren ); + while( it.hasNext() ) { it.next(); - if (!it.value().isEmpty()) + if( !it.value().isEmpty() ) return false; } return true; @@ -3049,13 +3019,13 @@ bool QCPMarginGroup::isEmpty() const void QCPMarginGroup::clear() { // make all children remove themselves from this margin group: - QHashIterator > it(mChildren); - while (it.hasNext()) + QHashIterator > it( mChildren ); + while( it.hasNext() ) { it.next(); const QList elements = it.value(); - for (int i=elements.size()-1; i>=0; --i) - elements.at(i)->setMarginGroup(it.key(), 0); // removes itself from mChildren via removeChild + for( int i = elements.size() - 1; i >= 0; --i ) + elements.at( i )->setMarginGroup( it.key(), 0 ); // removes itself from mChildren via removeChild } } @@ -3069,17 +3039,17 @@ void QCPMarginGroup::clear() group, and choosing the largest returned value. (QCPLayoutElement::minimumMargins is taken into account, too.) */ -int QCPMarginGroup::commonMargin(QCP::MarginSide side) const +int QCPMarginGroup::commonMargin( QCP::MarginSide side ) const { // query all automatic margins of the layout elements in this margin group side and find maximum: int result = 0; - const QList elements = mChildren.value(side); - for (int i=0; i elements = mChildren.value( side ); + for( int i = 0; i < elements.size(); ++i ) { - if (!elements.at(i)->autoMargins().testFlag(side)) + if( !elements.at( i )->autoMargins().testFlag( side ) ) continue; - int m = qMax(elements.at(i)->calculateAutoMargin(side), QCP::getMarginValue(elements.at(i)->minimumMargins(), side)); - if (m > result) + int m = qMax( elements.at( i )->calculateAutoMargin( side ), QCP::getMarginValue( elements.at( i )->minimumMargins(), side ) ); + if( m > result ) result = m; } return result; @@ -3091,12 +3061,12 @@ int QCPMarginGroup::commonMargin(QCP::MarginSide side) const This function does not modify the margin group property of \a element. */ -void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) +void QCPMarginGroup::addChild( QCP::MarginSide side, QCPLayoutElement* element ) { - if (!mChildren[side].contains(element)) - mChildren[side].append(element); + if( !mChildren[side].contains( element ) ) + mChildren[side].append( element ); else - qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast(element); + qDebug() << Q_FUNC_INFO << "element is already child of this margin group side" << reinterpret_cast( element ); } /*! \internal @@ -3105,13 +3075,12 @@ void QCPMarginGroup::addChild(QCP::MarginSide side, QCPLayoutElement *element) This function does not modify the margin group property of \a element. */ -void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element) +void QCPMarginGroup::removeChild( QCP::MarginSide side, QCPLayoutElement* element ) { - if (!mChildren[side].removeOne(element)) - qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast(element); + if( !mChildren[side].removeOne( element ) ) + qDebug() << Q_FUNC_INFO << "element is not child of this margin group side" << reinterpret_cast( element ); } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayoutElement //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3178,26 +3147,26 @@ void QCPMarginGroup::removeChild(QCP::MarginSide side, QCPLayoutElement *element /*! Creates an instance of QCPLayoutElement and sets default values. */ -QCPLayoutElement::QCPLayoutElement(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) - mParentLayout(0), - mMinimumSize(), - mMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), - mSizeConstraintRect(scrInnerRect), - mRect(0, 0, 0, 0), - mOuterRect(0, 0, 0, 0), - mMargins(0, 0, 0, 0), - mMinimumMargins(0, 0, 0, 0), - mAutoMargins(QCP::msAll) +QCPLayoutElement::QCPLayoutElement( QCustomPlot* parentPlot ) + : QCPLayerable( parentPlot ), // parenthood is changed as soon as layout element gets inserted into a layout (except for top level layout) + mParentLayout( 0 ) + , mMinimumSize() + , mMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX ) + , mSizeConstraintRect( scrInnerRect ) + , mRect( 0, 0, 0, 0 ) + , mOuterRect( 0, 0, 0, 0 ) + , mMargins( 0, 0, 0, 0 ) + , mMinimumMargins( 0, 0, 0, 0 ) + , mAutoMargins( QCP::msAll ) { } QCPLayoutElement::~QCPLayoutElement() { - setMarginGroup(QCP::msAll, 0); // unregister at margin groups, if there are any + setMarginGroup( QCP::msAll, 0 ); // unregister at margin groups, if there are any // unregister at layout: - if (qobject_cast(mParentLayout)) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor - mParentLayout->take(this); + if( qobject_cast( mParentLayout ) ) // the qobject_cast is just a safeguard in case the layout forgets to call clear() in its dtor and this dtor is called by QObject dtor + mParentLayout->take( this ); } /*! @@ -3211,12 +3180,12 @@ QCPLayoutElement::~QCPLayoutElement() \see rect */ -void QCPLayoutElement::setOuterRect(const QRect &rect) +void QCPLayoutElement::setOuterRect( const QRect& rect ) { - if (mOuterRect != rect) + if( mOuterRect != rect ) { mOuterRect = rect; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + mRect = mOuterRect.adjusted( mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom() ); } } @@ -3231,12 +3200,12 @@ void QCPLayoutElement::setOuterRect(const QRect &rect) \see setAutoMargins */ -void QCPLayoutElement::setMargins(const QMargins &margins) +void QCPLayoutElement::setMargins( const QMargins& margins ) { - if (mMargins != margins) + if( mMargins != margins ) { mMargins = margins; - mRect = mOuterRect.adjusted(mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom()); + mRect = mOuterRect.adjusted( mMargins.left(), mMargins.top(), -mMargins.right(), -mMargins.bottom() ); } } @@ -3249,9 +3218,9 @@ void QCPLayoutElement::setMargins(const QMargins &margins) \see setAutoMargins */ -void QCPLayoutElement::setMinimumMargins(const QMargins &margins) +void QCPLayoutElement::setMinimumMargins( const QMargins& margins ) { - if (mMinimumMargins != margins) + if( mMinimumMargins != margins ) { mMinimumMargins = margins; } @@ -3267,7 +3236,7 @@ void QCPLayoutElement::setMinimumMargins(const QMargins &margins) \see setMinimumMargins, setMargins, QCP::MarginSide */ -void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) +void QCPLayoutElement::setAutoMargins( QCP::MarginSides sides ) { mAutoMargins = sides; } @@ -3284,12 +3253,12 @@ void QCPLayoutElement::setAutoMargins(QCP::MarginSides sides) Whether this constraint applies to the inner or the outer rect can be specified with \ref setSizeConstraintRect (see \ref rect and \ref outerRect). */ -void QCPLayoutElement::setMinimumSize(const QSize &size) +void QCPLayoutElement::setMinimumSize( const QSize& size ) { - if (mMinimumSize != size) + if( mMinimumSize != size ) { mMinimumSize = size; - if (mParentLayout) + if( mParentLayout ) mParentLayout->sizeConstraintsChanged(); } } @@ -3301,9 +3270,9 @@ void QCPLayoutElement::setMinimumSize(const QSize &size) Whether this constraint applies to the inner or the outer rect can be specified with \ref setSizeConstraintRect (see \ref rect and \ref outerRect). */ -void QCPLayoutElement::setMinimumSize(int width, int height) +void QCPLayoutElement::setMinimumSize( int width, int height ) { - setMinimumSize(QSize(width, height)); + setMinimumSize( QSize( width, height ) ); } /*! @@ -3313,12 +3282,12 @@ void QCPLayoutElement::setMinimumSize(int width, int height) Whether this constraint applies to the inner or the outer rect can be specified with \ref setSizeConstraintRect (see \ref rect and \ref outerRect). */ -void QCPLayoutElement::setMaximumSize(const QSize &size) +void QCPLayoutElement::setMaximumSize( const QSize& size ) { - if (mMaximumSize != size) + if( mMaximumSize != size ) { mMaximumSize = size; - if (mParentLayout) + if( mParentLayout ) mParentLayout->sizeConstraintsChanged(); } } @@ -3330,9 +3299,9 @@ void QCPLayoutElement::setMaximumSize(const QSize &size) Whether this constraint applies to the inner or the outer rect can be specified with \ref setSizeConstraintRect (see \ref rect and \ref outerRect). */ -void QCPLayoutElement::setMaximumSize(int width, int height) +void QCPLayoutElement::setMaximumSize( int width, int height ) { - setMaximumSize(QSize(width, height)); + setMaximumSize( QSize( width, height ) ); } /*! @@ -3344,12 +3313,12 @@ void QCPLayoutElement::setMaximumSize(int width, int height) \see setMinimumSize, setMaximumSize */ -void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) +void QCPLayoutElement::setSizeConstraintRect( SizeConstraintRect constraintRect ) { - if (mSizeConstraintRect != constraintRect) + if( mSizeConstraintRect != constraintRect ) { mSizeConstraintRect = constraintRect; - if (mParentLayout) + if( mParentLayout ) mParentLayout->sizeConstraintsChanged(); } } @@ -3367,30 +3336,35 @@ void QCPLayoutElement::setSizeConstraintRect(SizeConstraintRect constraintRect) \see QCP::MarginSide */ -void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group) +void QCPLayoutElement::setMarginGroup( QCP::MarginSides sides, QCPMarginGroup* group ) { QVector sideVector; - if (sides.testFlag(QCP::msLeft)) sideVector.append(QCP::msLeft); - if (sides.testFlag(QCP::msRight)) sideVector.append(QCP::msRight); - if (sides.testFlag(QCP::msTop)) sideVector.append(QCP::msTop); - if (sides.testFlag(QCP::msBottom)) sideVector.append(QCP::msBottom); - - for (int i=0; iremoveChild(side, this); - - if (!group) // if setting to 0, remove hash entry. Else set hash entry to new group and register there + QCPMarginGroup* oldGroup = marginGroup( side ); + if( oldGroup ) // unregister at old group + oldGroup->removeChild( side, this ); + + if( !group ) // if setting to 0, remove hash entry. Else set hash entry to new group and register there { - mMarginGroups.remove(side); - } else // setting to a new group + mMarginGroups.remove( side ); + } + else // setting to a new group { mMarginGroups[side] = group; - group->addChild(side, this); + group->addChild( side, this ); } } } @@ -3408,29 +3382,29 @@ void QCPLayoutElement::setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *gr The default implementation executes the automatic margin mechanism in the \ref upMargins phase. Subclasses should make sure to call the base class implementation. */ -void QCPLayoutElement::update(UpdatePhase phase) +void QCPLayoutElement::update( UpdatePhase phase ) { - if (phase == upMargins) + if( phase == upMargins ) { - if (mAutoMargins != QCP::msNone) + if( mAutoMargins != QCP::msNone ) { // set the margins of this layout element according to automatic margin calculation, either directly or via a margin group: QMargins newMargins = mMargins; QList allMarginSides = QList() << QCP::msLeft << QCP::msRight << QCP::msTop << QCP::msBottom; - foreach (QCP::MarginSide side, allMarginSides) + foreach( QCP::MarginSide side, allMarginSides ) { - if (mAutoMargins.testFlag(side)) // this side's margin shall be calculated automatically + if( mAutoMargins.testFlag( side ) ) // this side's margin shall be calculated automatically { - if (mMarginGroups.contains(side)) - QCP::setMarginValue(newMargins, side, mMarginGroups[side]->commonMargin(side)); // this side is part of a margin group, so get the margin value from that group + if( mMarginGroups.contains( side ) ) + QCP::setMarginValue( newMargins, side, mMarginGroups[side]->commonMargin( side ) ); // this side is part of a margin group, so get the margin value from that group else - QCP::setMarginValue(newMargins, side, calculateAutoMargin(side)); // this side is not part of a group, so calculate the value directly + QCP::setMarginValue( newMargins, side, calculateAutoMargin( side ) ); // this side is not part of a group, so calculate the value directly // apply minimum margin restrictions: - if (QCP::getMarginValue(newMargins, side) < QCP::getMarginValue(mMinimumMargins, side)) - QCP::setMarginValue(newMargins, side, QCP::getMarginValue(mMinimumMargins, side)); + if( QCP::getMarginValue( newMargins, side ) < QCP::getMarginValue( mMinimumMargins, side ) ) + QCP::setMarginValue( newMargins, side, QCP::getMarginValue( mMinimumMargins, side ) ); } } - setMargins(newMargins); + setMargins( newMargins ); } } } @@ -3451,7 +3425,7 @@ void QCPLayoutElement::update(UpdatePhase phase) */ QSize QCPLayoutElement::minimumOuterSizeHint() const { - return QSize(mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()); + return QSize( mMargins.left() + mMargins.right(), mMargins.top() + mMargins.bottom() ); } /*! @@ -3470,7 +3444,7 @@ QSize QCPLayoutElement::minimumOuterSizeHint() const */ QSize QCPLayoutElement::maximumOuterSizeHint() const { - return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + return QSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX ); } /*! @@ -3480,9 +3454,9 @@ QSize QCPLayoutElement::maximumOuterSizeHint() const \warning There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have empty cells which yield 0 at the respective index.) */ -QList QCPLayoutElement::elements(bool recursive) const +QList QCPLayoutElement::elements( bool recursive ) const { - Q_UNUSED(recursive) + Q_UNUSED( recursive ) return QList(); } @@ -3497,23 +3471,24 @@ QList QCPLayoutElement::elements(bool recursive) const QCPLayoutElement subclasses may reimplement this method to provide more specific selection test behaviour. */ -double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPLayoutElement::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - - if (onlySelectable) + Q_UNUSED( details ) + + if( onlySelectable ) return -1; - - if (QRectF(mOuterRect).contains(pos)) + + if( QRectF( mOuterRect ).contains( pos ) ) { - if (mParentPlot) - return mParentPlot->selectionTolerance()*0.99; + if( mParentPlot ) + return mParentPlot->selectionTolerance() * 0.99; else { qDebug() << Q_FUNC_INFO << "parent plot not defined"; return -1; } - } else + } + else return -1; } @@ -3522,12 +3497,12 @@ double QCPLayoutElement::selectTest(const QPointF &pos, bool onlySelectable, QVa propagates the parent plot initialization to all child elements, by calling \ref QCPLayerable::initializeParentPlot on them. */ -void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) +void QCPLayoutElement::parentPlotInitialized( QCustomPlot* parentPlot ) { - foreach (QCPLayoutElement* el, elements(false)) + foreach( QCPLayoutElement* el, elements( false ) ) { - if (!el->parentPlot()) - el->initializeParentPlot(parentPlot); + if( !el->parentPlot() ) + el->initializeParentPlot( parentPlot ); } } @@ -3540,9 +3515,9 @@ void QCPLayoutElement::parentPlotInitialized(QCustomPlot *parentPlot) The default implementation just returns the respective manual margin (\ref setMargins) or the minimum margin, whichever is larger. */ -int QCPLayoutElement::calculateAutoMargin(QCP::MarginSide side) +int QCPLayoutElement::calculateAutoMargin( QCP::MarginSide side ) { - return qMax(QCP::getMarginValue(mMargins, side), QCP::getMarginValue(mMinimumMargins, side)); + return qMax( QCP::getMarginValue( mMargins, side ), QCP::getMarginValue( mMinimumMargins, side ) ); } /*! \internal @@ -3650,39 +3625,39 @@ QCPLayout::QCPLayout() For details about this method and the update phases, see the documentation of \ref QCPLayoutElement::update. */ -void QCPLayout::update(UpdatePhase phase) +void QCPLayout::update( UpdatePhase phase ) { - QCPLayoutElement::update(phase); - + QCPLayoutElement::update( phase ); + // set child element rects according to layout: - if (phase == upLayout) + if( phase == upLayout ) updateLayout(); - + // propagate update call to child elements: const int elCount = elementCount(); - for (int i=0; iupdate(phase); + if( QCPLayoutElement* el = elementAt( i ) ) + el->update( phase ); } } /* inherits documentation from base class */ -QList QCPLayout::elements(bool recursive) const +QList QCPLayout::elements( bool recursive ) const { const int c = elementCount(); QList result; -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(c); +#if QT_VERSION >= QT_VERSION_CHECK( 4, 7, 0 ) + result.reserve( c ); #endif - for (int i=0; ielements(recursive); + if( result.at( i ) ) + result << result.at( i )->elements( recursive ); } } return result; @@ -3710,13 +3685,14 @@ void QCPLayout::simplify() \see remove, takeAt */ -bool QCPLayout::removeAt(int index) +bool QCPLayout::removeAt( int index ) { - if (QCPLayoutElement *el = takeAt(index)) + if( QCPLayoutElement* el = takeAt( index ) ) { delete el; return true; - } else + } + else return false; } @@ -3731,13 +3707,14 @@ bool QCPLayout::removeAt(int index) \see removeAt, take */ -bool QCPLayout::remove(QCPLayoutElement *element) +bool QCPLayout::remove( QCPLayoutElement* element ) { - if (take(element)) + if( take( element ) ) { delete element; return true; - } else + } + else return false; } @@ -3749,10 +3726,10 @@ bool QCPLayout::remove(QCPLayoutElement *element) */ void QCPLayout::clear() { - for (int i=elementCount()-1; i>=0; --i) + for( int i = elementCount() - 1; i >= 0; --i ) { - if (elementAt(i)) - removeAt(i); + if( elementAt( i ) ) + removeAt( i ); } simplify(); } @@ -3767,9 +3744,9 @@ void QCPLayout::clear() */ void QCPLayout::sizeConstraintsChanged() const { - if (QWidget *w = qobject_cast(parent())) + if( QWidget* w = qobject_cast( parent() ) ) w->updateGeometry(); - else if (QCPLayout *l = qobject_cast(parent())) + else if( QCPLayout* l = qobject_cast( parent() ) ) l->sizeConstraintsChanged(); } @@ -3789,7 +3766,6 @@ void QCPLayout::updateLayout() { } - /*! \internal Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the @@ -3802,17 +3778,18 @@ void QCPLayout::updateLayout() method only changes properties in \a el. The removal from the old layout and the insertion into the new layout must be done additionally. */ -void QCPLayout::adoptElement(QCPLayoutElement *el) +void QCPLayout::adoptElement( QCPLayoutElement* el ) { - if (el) + if( el ) { el->mParentLayout = this; - el->setParentLayerable(this); - el->setParent(this); - if (!el->parentPlot()) - el->initializeParentPlot(mParentPlot); + el->setParentLayerable( this ); + el->setParent( this ); + if( !el->parentPlot() ) + el->initializeParentPlot( mParentPlot ); el->layoutChanged(); - } else + } + else qDebug() << Q_FUNC_INFO << "Null element passed"; } @@ -3826,15 +3803,16 @@ void QCPLayout::adoptElement(QCPLayoutElement *el) take or \ref takeAt). Note that this method only changes properties in \a el. The removal from the old layout must be done additionally. */ -void QCPLayout::releaseElement(QCPLayoutElement *el) +void QCPLayout::releaseElement( QCPLayoutElement* el ) { - if (el) + if( el ) { el->mParentLayout = 0; - el->setParentLayerable(0); - el->setParent(mParentPlot); + el->setParentLayerable( 0 ); + el->setParent( mParentPlot ); // Note: Don't initializeParentPlot(0) here, because layout element will stay in same parent plot - } else + } + else qDebug() << Q_FUNC_INFO << "Null element passed"; } @@ -3867,53 +3845,53 @@ void QCPLayout::releaseElement(QCPLayoutElement *el) The return value is a QVector containing the section sizes. */ -QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const +QVector QCPLayout::getSectionSizes( QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize ) const { - if (maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size()) + if( maxSizes.size() != minSizes.size() || minSizes.size() != stretchFactors.size() ) { qDebug() << Q_FUNC_INFO << "Passed vector sizes aren't equal:" << maxSizes << minSizes << stretchFactors; return QVector(); } - if (stretchFactors.isEmpty()) + if( stretchFactors.isEmpty() ) return QVector(); int sectionCount = stretchFactors.size(); - QVector sectionSizes(sectionCount); + QVector sectionSizes( sectionCount ); // if provided total size is forced smaller than total minimum size, ignore minimum sizes (squeeze sections): int minSizeSum = 0; - for (int i=0; i minimumLockedSections; QList unfinishedSections; - for (int i=0; i QCPLayout::getSectionSizes(QVector maxSizes, QVector minS // check if that maximum is actually within the bounds of the total size (i.e. can we stretch all remaining sections so far that the found section // actually hits its maximum, without exceeding the total size when we add up all sections) double stretchFactorSum = 0; - for (int i=0; i result(sectionCount); - for (int i=0; i result( sectionCount ); + for( int i = 0; i < sectionCount; ++i ) + result[i] = qRound( sectionSizes.at( i ) ); return result; } @@ -3992,17 +3971,18 @@ QVector QCPLayout::getSectionSizes(QVector maxSizes, QVector minS QCPLayoutElement::setSizeConstraintRect), as well as the minimum size hint, if no manual minimum size was set (\ref QCPLayoutElement::minimumOuterSizeHint). */ -QSize QCPLayout::getFinalMinimumOuterSize(const QCPLayoutElement *el) +QSize QCPLayout::getFinalMinimumOuterSize( const QCPLayoutElement* el ) { QSize minOuterHint = el->minimumOuterSizeHint(); - QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) - if (minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + QSize minOuter = el->minimumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset minimum of 0) + if( minOuter.width() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect ) minOuter.rwidth() += el->margins().left() + el->margins().right(); - if (minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + if( minOuter.height() > 0 && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect ) minOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height());; + + return QSize( minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height() ); + ; } /*! \internal @@ -4017,19 +3997,18 @@ QSize QCPLayout::getFinalMinimumOuterSize(const QCPLayoutElement *el) QCPLayoutElement::setSizeConstraintRect), as well as the maximum size hint, if no manual maximum size was set (\ref QCPLayoutElement::maximumOuterSizeHint). */ -QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) +QSize QCPLayout::getFinalMaximumOuterSize( const QCPLayoutElement* el ) { QSize maxOuterHint = el->maximumOuterSizeHint(); - QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) - if (maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + QSize maxOuter = el->maximumSize(); // depending on sizeConstraitRect this might be with respect to inner rect, so possibly add margins in next four lines (preserving unset maximum of QWIDGETSIZE_MAX) + if( maxOuter.width() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect ) maxOuter.rwidth() += el->margins().left() + el->margins().right(); - if (maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect) + if( maxOuter.height() < QWIDGETSIZE_MAX && el->sizeConstraintRect() == QCPLayoutElement::scrInnerRect ) maxOuter.rheight() += el->margins().top() + el->margins().bottom(); - - return QSize(maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()); -} + return QSize( maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height() ); +} //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayoutGrid @@ -4076,11 +4055,8 @@ QSize QCPLayout::getFinalMaximumOuterSize(const QCPLayoutElement *el) /*! Creates an instance of QCPLayoutGrid and sets default values. */ -QCPLayoutGrid::QCPLayoutGrid() : - mColumnSpacing(5), - mRowSpacing(5), - mWrap(0), - mFillOrder(foColumnsFirst) +QCPLayoutGrid::QCPLayoutGrid() + : mColumnSpacing( 5 ), mRowSpacing( 5 ), mWrap( 0 ), mFillOrder( foColumnsFirst ) { } @@ -4099,24 +4075,25 @@ QCPLayoutGrid::~QCPLayoutGrid() \see addElement, hasElement */ -QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const +QCPLayoutElement* QCPLayoutGrid::element( int row, int column ) const { - if (row >= 0 && row < mElements.size()) + if( row >= 0 && row < mElements.size() ) { - if (column >= 0 && column < mElements.first().size()) + if( column >= 0 && column < mElements.first().size() ) { - if (QCPLayoutElement *result = mElements.at(row).at(column)) + if( QCPLayoutElement* result = mElements.at( row ).at( column ) ) return result; else qDebug() << Q_FUNC_INFO << "Requested cell is empty. Row:" << row << "Column:" << column; - } else + } + else qDebug() << Q_FUNC_INFO << "Invalid column. Row:" << row << "Column:" << column; - } else + } + else qDebug() << Q_FUNC_INFO << "Invalid row. Row:" << row << "Column:" << column; return 0; } - /*! \overload Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it @@ -4131,18 +4108,19 @@ QCPLayoutElement *QCPLayoutGrid::element(int row, int column) const \see element, hasElement, take, remove */ -bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) +bool QCPLayoutGrid::addElement( int row, int column, QCPLayoutElement* element ) { - if (!hasElement(row, column)) + if( !hasElement( row, column ) ) { - if (element && element->layout()) // remove from old layout first - element->layout()->take(element); - expandTo(row+1, column+1); + if( element && element->layout() ) // remove from old layout first + element->layout()->take( element ); + expandTo( row + 1, column + 1 ); mElements[row][column] = element; - if (element) - adoptElement(element); + if( element ) + adoptElement( element ); return true; - } else + } + else qDebug() << Q_FUNC_INFO << "There is already an element in the specified row/column:" << row << column; return false; } @@ -4157,34 +4135,35 @@ bool QCPLayoutGrid::addElement(int row, int column, QCPLayoutElement *element) \see setFillOrder, setWrap, element, hasElement, take, remove */ -bool QCPLayoutGrid::addElement(QCPLayoutElement *element) +bool QCPLayoutGrid::addElement( QCPLayoutElement* element ) { int rowIndex = 0; int colIndex = 0; - if (mFillOrder == foColumnsFirst) + if( mFillOrder == foColumnsFirst ) { - while (hasElement(rowIndex, colIndex)) + while( hasElement( rowIndex, colIndex ) ) { ++colIndex; - if (colIndex >= mWrap && mWrap > 0) + if( colIndex >= mWrap && mWrap > 0 ) { colIndex = 0; ++rowIndex; } } - } else + } + else { - while (hasElement(rowIndex, colIndex)) + while( hasElement( rowIndex, colIndex ) ) { ++rowIndex; - if (rowIndex >= mWrap && mWrap > 0) + if( rowIndex >= mWrap && mWrap > 0 ) { rowIndex = 0; ++colIndex; } } } - return addElement(rowIndex, colIndex, element); + return addElement( rowIndex, colIndex, element ); } /*! @@ -4193,10 +4172,10 @@ bool QCPLayoutGrid::addElement(QCPLayoutElement *element) \see element */ -bool QCPLayoutGrid::hasElement(int row, int column) +bool QCPLayoutGrid::hasElement( int row, int column ) { - if (row >= 0 && row < rowCount() && column >= 0 && column < columnCount()) - return mElements.at(row).at(column); + if( row >= 0 && row < rowCount() && column >= 0 && column < columnCount() ) + return mElements.at( row ).at( column ); else return false; } @@ -4213,15 +4192,16 @@ bool QCPLayoutGrid::hasElement(int row, int column) \see setColumnStretchFactors, setRowStretchFactor */ -void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) +void QCPLayoutGrid::setColumnStretchFactor( int column, double factor ) { - if (column >= 0 && column < columnCount()) + if( column >= 0 && column < columnCount() ) { - if (factor > 0) + if( factor > 0 ) mColumnStretchFactors[column] = factor; else qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else + } + else qDebug() << Q_FUNC_INFO << "Invalid column:" << column; } @@ -4237,20 +4217,21 @@ void QCPLayoutGrid::setColumnStretchFactor(int column, double factor) \see setColumnStretchFactor, setRowStretchFactors */ -void QCPLayoutGrid::setColumnStretchFactors(const QList &factors) +void QCPLayoutGrid::setColumnStretchFactors( const QList& factors ) { - if (factors.size() == mColumnStretchFactors.size()) + if( factors.size() == mColumnStretchFactors.size() ) { mColumnStretchFactors = factors; - for (int i=0; i &factors) \see setColumnStretchFactors, setRowStretchFactor */ -void QCPLayoutGrid::setRowStretchFactor(int row, double factor) +void QCPLayoutGrid::setRowStretchFactor( int row, double factor ) { - if (row >= 0 && row < rowCount()) + if( row >= 0 && row < rowCount() ) { - if (factor > 0) + if( factor > 0 ) mRowStretchFactors[row] = factor; else qDebug() << Q_FUNC_INFO << "Invalid stretch factor, must be positive:" << factor; - } else + } + else qDebug() << Q_FUNC_INFO << "Invalid row:" << row; } @@ -4290,20 +4272,21 @@ void QCPLayoutGrid::setRowStretchFactor(int row, double factor) \see setRowStretchFactor, setColumnStretchFactors */ -void QCPLayoutGrid::setRowStretchFactors(const QList &factors) +void QCPLayoutGrid::setRowStretchFactors( const QList& factors ) { - if (factors.size() == mRowStretchFactors.size()) + if( factors.size() == mRowStretchFactors.size() ) { mRowStretchFactors = factors; - for (int i=0; i &factors) \see setRowSpacing */ -void QCPLayoutGrid::setColumnSpacing(int pixels) +void QCPLayoutGrid::setColumnSpacing( int pixels ) { mColumnSpacing = pixels; } @@ -4322,7 +4305,7 @@ void QCPLayoutGrid::setColumnSpacing(int pixels) \see setColumnSpacing */ -void QCPLayoutGrid::setRowSpacing(int pixels) +void QCPLayoutGrid::setRowSpacing( int pixels ) { mRowSpacing = pixels; } @@ -4344,9 +4327,9 @@ void QCPLayoutGrid::setRowSpacing(int pixels) \see setFillOrder */ -void QCPLayoutGrid::setWrap(int count) +void QCPLayoutGrid::setWrap( int count ) { - mWrap = qMax(0, count); + mWrap = qMax( 0, count ); } /*! @@ -4374,28 +4357,28 @@ void QCPLayoutGrid::setWrap(int count) \see setWrap, addElement(QCPLayoutElement*) */ -void QCPLayoutGrid::setFillOrder(FillOrder order, bool rearrange) +void QCPLayoutGrid::setFillOrder( FillOrder order, bool rearrange ) { // if rearranging, take all elements via linear index of old fill order: const int elCount = elementCount(); QVector tempElements; - if (rearrange) + if( rearrange ) { - tempElements.reserve(elCount); - for (int i=0; i()); - mRowStretchFactors.append(1); + mElements.append( QList() ); + mRowStretchFactors.append( 1 ); } // go through rows and expand columns as necessary: - int newColCount = qMax(columnCount(), newColumnCount); - for (int i=0; i rowCount()) + if( newIndex > rowCount() ) newIndex = rowCount(); - - mRowStretchFactors.insert(newIndex, 1); + + mRowStretchFactors.insert( newIndex, 1 ); QList newRow; - for (int col=0; col columnCount()) + if( newIndex > columnCount() ) newIndex = columnCount(); - - mColumnStretchFactors.insert(newIndex, 1); - for (int row=0; row= 0 && row < rowCount()) + if( row >= 0 && row < rowCount() ) { - if (column >= 0 && column < columnCount()) + if( column >= 0 && column < columnCount() ) { - switch (mFillOrder) + switch( mFillOrder ) { - case foRowsFirst: return column*rowCount() + row; - case foColumnsFirst: return row*columnCount() + column; + case foRowsFirst: + return column * rowCount() + row; + case foColumnsFirst: + return row * columnCount() + column; } - } else + } + else qDebug() << Q_FUNC_INFO << "row index out of bounds:" << row; - } else + } + else qDebug() << Q_FUNC_INFO << "column index out of bounds:" << column; return 0; } @@ -4529,34 +4516,32 @@ int QCPLayoutGrid::rowColToIndex(int row, int column) const \see rowColToIndex */ -void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const +void QCPLayoutGrid::indexToRowCol( int index, int& row, int& column ) const { row = -1; column = -1; const int nCols = columnCount(); const int nRows = rowCount(); - if (nCols == 0 || nRows == 0) + if( nCols == 0 || nRows == 0 ) return; - if (index < 0 || index >= elementCount()) + if( index < 0 || index >= elementCount() ) { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return; } - - switch (mFillOrder) + + switch( mFillOrder ) { - case foRowsFirst: - { - column = index / nRows; - row = index % nRows; - break; - } - case foColumnsFirst: - { - row = index / nCols; - column = index % nCols; - break; - } + case foRowsFirst: { + column = index / nRows; + row = index % nRows; + break; + } + case foColumnsFirst: { + row = index / nCols; + column = index % nCols; + break; + } } } @@ -4564,27 +4549,27 @@ void QCPLayoutGrid::indexToRowCol(int index, int &row, int &column) const void QCPLayoutGrid::updateLayout() { QVector minColWidths, minRowHeights, maxColWidths, maxRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - int totalRowSpacing = (rowCount()-1) * mRowSpacing; - int totalColSpacing = (columnCount()-1) * mColumnSpacing; - QVector colWidths = getSectionSizes(maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width()-totalColSpacing); - QVector rowHeights = getSectionSizes(maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height()-totalRowSpacing); - + getMinimumRowColSizes( &minColWidths, &minRowHeights ); + getMaximumRowColSizes( &maxColWidths, &maxRowHeights ); + + int totalRowSpacing = ( rowCount() - 1 ) * mRowSpacing; + int totalColSpacing = ( columnCount() - 1 ) * mColumnSpacing; + QVector colWidths = getSectionSizes( maxColWidths, minColWidths, mColumnStretchFactors.toVector(), mRect.width() - totalColSpacing ); + QVector rowHeights = getSectionSizes( maxRowHeights, minRowHeights, mRowStretchFactors.toVector(), mRect.height() - totalRowSpacing ); + // go through cells and set rects accordingly: int yOffset = mRect.top(); - for (int row=0; row 0) - yOffset += rowHeights.at(row-1)+mRowSpacing; + if( row > 0 ) + yOffset += rowHeights.at( row - 1 ) + mRowSpacing; int xOffset = mRect.left(); - for (int col=0; col 0) - xOffset += colWidths.at(col-1)+mColumnSpacing; - if (mElements.at(row).at(col)) - mElements.at(row).at(col)->setOuterRect(QRect(xOffset, yOffset, colWidths.at(col), rowHeights.at(row))); + if( col > 0 ) + xOffset += colWidths.at( col - 1 ) + mColumnSpacing; + if( mElements.at( row ).at( col ) ) + mElements.at( row ).at( col )->setOuterRect( QRect( xOffset, yOffset, colWidths.at( col ), rowHeights.at( row ) ) ); } } } @@ -4597,14 +4582,15 @@ void QCPLayoutGrid::updateLayout() \see rowColToIndex */ -QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const +QCPLayoutElement* QCPLayoutGrid::elementAt( int index ) const { - if (index >= 0 && index < elementCount()) + if( index >= 0 && index < elementCount() ) { int row, col; - indexToRowCol(index, row, col); - return mElements.at(row).at(col); - } else + indexToRowCol( index, row, col ); + return mElements.at( row ).at( col ); + } + else return 0; } @@ -4616,16 +4602,17 @@ QCPLayoutElement *QCPLayoutGrid::elementAt(int index) const \see rowColToIndex */ -QCPLayoutElement *QCPLayoutGrid::takeAt(int index) +QCPLayoutElement* QCPLayoutGrid::takeAt( int index ) { - if (QCPLayoutElement *el = elementAt(index)) + if( QCPLayoutElement* el = elementAt( index ) ) { - releaseElement(el); + releaseElement( el ); int row, col; - indexToRowCol(index, row, col); + indexToRowCol( index, row, col ); mElements[row][col] = 0; return el; - } else + } + else { qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; return 0; @@ -4633,40 +4620,41 @@ QCPLayoutElement *QCPLayoutGrid::takeAt(int index) } /* inherits documentation from base class */ -bool QCPLayoutGrid::take(QCPLayoutElement *element) +bool QCPLayoutGrid::take( QCPLayoutElement* element ) { - if (element) + if( element ) { - for (int i=0; i QCPLayoutGrid::elements(bool recursive) const +QList QCPLayoutGrid::elements( bool recursive ) const { QList result; const int elCount = elementCount(); -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - result.reserve(elCount); +#if QT_VERSION >= QT_VERSION_CHECK( 4, 7, 0 ) + result.reserve( elCount ); #endif - for (int i=0; ielements(recursive); + if( result.at( i ) ) + result << result.at( i )->elements( recursive ); } } return result; @@ -4678,43 +4666,43 @@ QList QCPLayoutGrid::elements(bool recursive) const void QCPLayoutGrid::simplify() { // remove rows with only empty cells: - for (int row=rowCount()-1; row>=0; --row) + for( int row = rowCount() - 1; row >= 0; --row ) { bool hasElements = false; - for (int col=0; col=0; --col) + for( int col = columnCount() - 1; col >= 0; --col ) { bool hasElements = false; - for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes(&minColWidths, &minRowHeights); - QSize result(0, 0); - for (int i=0; i maxColWidths, maxRowHeights; - getMaximumRowColSizes(&maxColWidths, &maxRowHeights); - - QSize result(0, 0); - for (int i=0; i QWIDGETSIZE_MAX) - result.setHeight(QWIDGETSIZE_MAX); - if (result.width() > QWIDGETSIZE_MAX) - result.setWidth(QWIDGETSIZE_MAX); + getMaximumRowColSizes( &maxColWidths, &maxRowHeights ); + + QSize result( 0, 0 ); + for( int i = 0; i < maxColWidths.size(); ++i ) + result.setWidth( qMin( result.width() + maxColWidths.at( i ), QWIDGETSIZE_MAX ) ); + for( int i = 0; i < maxRowHeights.size(); ++i ) + result.setHeight( qMin( result.height() + maxRowHeights.at( i ), QWIDGETSIZE_MAX ) ); + result.rwidth() += qMax( 0, columnCount() - 1 ) * mColumnSpacing; + result.rheight() += qMax( 0, rowCount() - 1 ) * mRowSpacing; + result.rwidth() += mMargins.left() + mMargins.right(); + result.rheight() += mMargins.top() + mMargins.bottom(); + if( result.height() > QWIDGETSIZE_MAX ) + result.setHeight( QWIDGETSIZE_MAX ); + if( result.width() > QWIDGETSIZE_MAX ) + result.setWidth( QWIDGETSIZE_MAX ); return result; } @@ -4771,21 +4759,21 @@ QSize QCPLayoutGrid::maximumOuterSizeHint() const \see getMaximumRowColSizes */ -void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const +void QCPLayoutGrid::getMinimumRowColSizes( QVector* minColWidths, QVector* minRowHeights ) const { - *minColWidths = QVector(columnCount(), 0); - *minRowHeights = QVector(rowCount(), 0); - for (int row=0; row( columnCount(), 0 ); + *minRowHeights = QVector( rowCount(), 0 ); + for( int row = 0; row < rowCount(); ++row ) { - for (int col=0; colat(col) < minSize.width()) - (*minColWidths)[col] = minSize.width(); - if (minRowHeights->at(row) < minSize.height()) - (*minRowHeights)[row] = minSize.height(); + QSize minSize = getFinalMinimumOuterSize( el ); + if( minColWidths->at( col ) < minSize.width() ) + ( *minColWidths )[col] = minSize.width(); + if( minRowHeights->at( row ) < minSize.height() ) + ( *minRowHeights )[row] = minSize.height(); } } } @@ -4804,27 +4792,26 @@ void QCPLayoutGrid::getMinimumRowColSizes(QVector *minColWidths, QVector *maxColWidths, QVector *maxRowHeights) const +void QCPLayoutGrid::getMaximumRowColSizes( QVector* maxColWidths, QVector* maxRowHeights ) const { - *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); - *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); - for (int row=0; row( columnCount(), QWIDGETSIZE_MAX ); + *maxRowHeights = QVector( rowCount(), QWIDGETSIZE_MAX ); + for( int row = 0; row < rowCount(); ++row ) { - for (int col=0; colat(col) > maxSize.width()) - (*maxColWidths)[col] = maxSize.width(); - if (maxRowHeights->at(row) > maxSize.height()) - (*maxRowHeights)[row] = maxSize.height(); + QSize maxSize = getFinalMaximumOuterSize( el ); + if( maxColWidths->at( col ) > maxSize.width() ) + ( *maxColWidths )[col] = maxSize.width(); + if( maxRowHeights->at( row ) > maxSize.height() ) + ( *maxRowHeights )[row] = maxSize.height(); } } } } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayoutInset //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4873,10 +4860,10 @@ QCPLayoutInset::~QCPLayoutInset() /*! Returns the placement type of the element with the specified \a index. */ -QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const +QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement( int index ) const { - if (elementAt(index)) - return mInsetPlacement.at(index); + if( elementAt( index ) ) + return mInsetPlacement.at( index ); else { qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4888,10 +4875,10 @@ QCPLayoutInset::InsetPlacement QCPLayoutInset::insetPlacement(int index) const Returns the alignment of the element with the specified \a index. The alignment only has a meaning, if the inset placement (\ref setInsetPlacement) is \ref ipBorderAligned. */ -Qt::Alignment QCPLayoutInset::insetAlignment(int index) const +Qt::Alignment QCPLayoutInset::insetAlignment( int index ) const { - if (elementAt(index)) - return mInsetAlignment.at(index); + if( elementAt( index ) ) + return mInsetAlignment.at( index ); else { qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4903,10 +4890,10 @@ Qt::Alignment QCPLayoutInset::insetAlignment(int index) const Returns the rect of the element with the specified \a index. The rect only has a meaning, if the inset placement (\ref setInsetPlacement) is \ref ipFree. */ -QRectF QCPLayoutInset::insetRect(int index) const +QRectF QCPLayoutInset::insetRect( int index ) const { - if (elementAt(index)) - return mInsetRect.at(index); + if( elementAt( index ) ) + return mInsetRect.at( index ); else { qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4919,9 +4906,9 @@ QRectF QCPLayoutInset::insetRect(int index) const \see InsetPlacement */ -void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement placement) +void QCPLayoutInset::setInsetPlacement( int index, QCPLayoutInset::InsetPlacement placement ) { - if (elementAt(index)) + if( elementAt( index ) ) mInsetPlacement[index] = placement; else qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4935,9 +4922,9 @@ void QCPLayoutInset::setInsetPlacement(int index, QCPLayoutInset::InsetPlacement Qt::AlignHCenter, Qt::AlighRight, Qt::AlignTop, Qt::AlignVCenter, Qt::AlignBottom. Any other alignment flags will be ignored. */ -void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) +void QCPLayoutInset::setInsetAlignment( int index, Qt::Alignment alignment ) { - if (elementAt(index)) + if( elementAt( index ) ) mInsetAlignment[index] = alignment; else qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4954,9 +4941,9 @@ void QCPLayoutInset::setInsetAlignment(int index, Qt::Alignment alignment) Note that the minimum and maximum sizes of the embedded element (\ref QCPLayoutElement::setMinimumSize, \ref QCPLayoutElement::setMaximumSize) are enforced. */ -void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) +void QCPLayoutInset::setInsetRect( int index, const QRectF& rect ) { - if (elementAt(index)) + if( elementAt( index ) ) mInsetRect[index] = rect; else qDebug() << Q_FUNC_INFO << "Invalid element index:" << index; @@ -4965,38 +4952,45 @@ void QCPLayoutInset::setInsetRect(int index, const QRectF &rect) /* inherits documentation from base class */ void QCPLayoutInset::updateLayout() { - for (int i=0; i finalMaxSize.width()) - insetRect.setWidth(finalMaxSize.width()); - if (insetRect.size().height() > finalMaxSize.height()) - insetRect.setHeight(finalMaxSize.height()); - } else if (mInsetPlacement.at(i) == ipBorderAligned) - { - insetRect.setSize(finalMinSize); - Qt::Alignment al = mInsetAlignment.at(i); - if (al.testFlag(Qt::AlignLeft)) insetRect.moveLeft(rect().x()); - else if (al.testFlag(Qt::AlignRight)) insetRect.moveRight(rect().x()+rect().width()); - else insetRect.moveLeft(rect().x()+rect().width()*0.5-finalMinSize.width()*0.5); // default to Qt::AlignHCenter - if (al.testFlag(Qt::AlignTop)) insetRect.moveTop(rect().y()); - else if (al.testFlag(Qt::AlignBottom)) insetRect.moveBottom(rect().y()+rect().height()); - else insetRect.moveTop(rect().y()+rect().height()*0.5-finalMinSize.height()*0.5); // default to Qt::AlignVCenter + insetRect = QRect( rect().x() + rect().width() * mInsetRect.at( i ).x(), + rect().y() + rect().height() * mInsetRect.at( i ).y(), + rect().width() * mInsetRect.at( i ).width(), + rect().height() * mInsetRect.at( i ).height() ); + if( insetRect.size().width() < finalMinSize.width() ) + insetRect.setWidth( finalMinSize.width() ); + if( insetRect.size().height() < finalMinSize.height() ) + insetRect.setHeight( finalMinSize.height() ); + if( insetRect.size().width() > finalMaxSize.width() ) + insetRect.setWidth( finalMaxSize.width() ); + if( insetRect.size().height() > finalMaxSize.height() ) + insetRect.setHeight( finalMaxSize.height() ); } - mElements.at(i)->setOuterRect(insetRect); + else if( mInsetPlacement.at( i ) == ipBorderAligned ) + { + insetRect.setSize( finalMinSize ); + Qt::Alignment al = mInsetAlignment.at( i ); + if( al.testFlag( Qt::AlignLeft ) ) + insetRect.moveLeft( rect().x() ); + else if( al.testFlag( Qt::AlignRight ) ) + insetRect.moveRight( rect().x() + rect().width() ); + else + insetRect.moveLeft( rect().x() + rect().width() * 0.5 - finalMinSize.width() * 0.5 ); // default to Qt::AlignHCenter + if( al.testFlag( Qt::AlignTop ) ) + insetRect.moveTop( rect().y() ); + else if( al.testFlag( Qt::AlignBottom ) ) + insetRect.moveBottom( rect().y() + rect().height() ); + else + insetRect.moveTop( rect().y() + rect().height() * 0.5 - finalMinSize.height() * 0.5 ); // default to Qt::AlignVCenter + } + mElements.at( i )->setOuterRect( insetRect ); } } @@ -5007,26 +5001,27 @@ int QCPLayoutInset::elementCount() const } /* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::elementAt(int index) const +QCPLayoutElement* QCPLayoutInset::elementAt( int index ) const { - if (index >= 0 && index < mElements.size()) - return mElements.at(index); + if( index >= 0 && index < mElements.size() ) + return mElements.at( index ); else return 0; } /* inherits documentation from base class */ -QCPLayoutElement *QCPLayoutInset::takeAt(int index) +QCPLayoutElement* QCPLayoutInset::takeAt( int index ) { - if (QCPLayoutElement *el = elementAt(index)) + if( QCPLayoutElement* el = elementAt( index ) ) { - releaseElement(el); - mElements.removeAt(index); - mInsetPlacement.removeAt(index); - mInsetAlignment.removeAt(index); - mInsetRect.removeAt(index); + releaseElement( el ); + mElements.removeAt( index ); + mInsetPlacement.removeAt( index ); + mInsetAlignment.removeAt( index ); + mInsetRect.removeAt( index ); return el; - } else + } + else { qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; return 0; @@ -5034,20 +5029,21 @@ QCPLayoutElement *QCPLayoutInset::takeAt(int index) } /* inherits documentation from base class */ -bool QCPLayoutInset::take(QCPLayoutElement *element) +bool QCPLayoutInset::take( QCPLayoutElement* element ) { - if (element) + if( element ) { - for (int i=0; irealVisibility() && mElements.at(i)->selectTest(pos, onlySelectable) >= 0) - return mParentPlot->selectionTolerance()*0.99; + if( mElements.at( i )->realVisibility() && mElements.at( i )->selectTest( pos, onlySelectable ) >= 0 ) + return mParentPlot->selectionTolerance() * 0.99; } return -1; } @@ -5088,18 +5084,19 @@ double QCPLayoutInset::selectTest(const QPointF &pos, bool onlySelectable, QVari \see addElement(QCPLayoutElement *element, const QRectF &rect) */ -void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignment) +void QCPLayoutInset::addElement( QCPLayoutElement* element, Qt::Alignment alignment ) { - if (element) + if( element ) { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipBorderAligned); - mInsetAlignment.append(alignment); - mInsetRect.append(QRectF(0.6, 0.6, 0.4, 0.4)); - adoptElement(element); - } else + if( element->layout() ) // remove from old layout first + element->layout()->take( element ); + mElements.append( element ); + mInsetPlacement.append( ipBorderAligned ); + mInsetAlignment.append( alignment ); + mInsetRect.append( QRectF( 0.6, 0.6, 0.4, 0.4 ) ); + adoptElement( element ); + } + else qDebug() << Q_FUNC_INFO << "Can't add null element"; } @@ -5114,23 +5111,23 @@ void QCPLayoutInset::addElement(QCPLayoutElement *element, Qt::Alignment alignme \see addElement(QCPLayoutElement *element, Qt::Alignment alignment) */ -void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) +void QCPLayoutInset::addElement( QCPLayoutElement* element, const QRectF& rect ) { - if (element) + if( element ) { - if (element->layout()) // remove from old layout first - element->layout()->take(element); - mElements.append(element); - mInsetPlacement.append(ipFree); - mInsetAlignment.append(Qt::AlignRight|Qt::AlignTop); - mInsetRect.append(rect); - adoptElement(element); - } else + if( element->layout() ) // remove from old layout first + element->layout()->take( element ); + mElements.append( element ); + mInsetPlacement.append( ipFree ); + mInsetAlignment.append( Qt::AlignRight | Qt::AlignTop ); + mInsetRect.append( rect ); + adoptElement( element ); + } + else qDebug() << Q_FUNC_INFO << "Can't add null element"; } /* end of 'src/layout.cpp' */ - /* including file 'src/lineending.cpp', size 11536 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5161,29 +5158,23 @@ void QCPLayoutInset::addElement(QCPLayoutElement *element, const QRectF &rect) /*! Creates a QCPLineEnding instance with default values (style \ref esNone). */ -QCPLineEnding::QCPLineEnding() : - mStyle(esNone), - mWidth(8), - mLength(10), - mInverted(false) +QCPLineEnding::QCPLineEnding() + : mStyle( esNone ), mWidth( 8 ), mLength( 10 ), mInverted( false ) { } /*! Creates a QCPLineEnding instance with the specified values. */ -QCPLineEnding::QCPLineEnding(QCPLineEnding::EndingStyle style, double width, double length, bool inverted) : - mStyle(style), - mWidth(width), - mLength(length), - mInverted(inverted) +QCPLineEnding::QCPLineEnding( QCPLineEnding::EndingStyle style, double width, double length, bool inverted ) + : mStyle( style ), mWidth( width ), mLength( length ), mInverted( inverted ) { } /*! Sets the style of the ending decoration. */ -void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) +void QCPLineEnding::setStyle( QCPLineEnding::EndingStyle style ) { mStyle = style; } @@ -5194,7 +5185,7 @@ void QCPLineEnding::setStyle(QCPLineEnding::EndingStyle style) \see setLength */ -void QCPLineEnding::setWidth(double width) +void QCPLineEnding::setWidth( double width ) { mWidth = width; } @@ -5205,7 +5196,7 @@ void QCPLineEnding::setWidth(double width) \see setWidth */ -void QCPLineEnding::setLength(double length) +void QCPLineEnding::setLength( double length ) { mLength = length; } @@ -5218,7 +5209,7 @@ void QCPLineEnding::setLength(double length) discs, this doesn't make a difference. However, asymmetric styles like \ref esHalfBar are affected by it, which can be used to control to which side the half bar points to. */ -void QCPLineEnding::setInverted(bool inverted) +void QCPLineEnding::setInverted( bool inverted ) { mInverted = inverted; } @@ -5234,24 +5225,23 @@ void QCPLineEnding::setInverted(bool inverted) */ double QCPLineEnding::boundingDistance() const { - switch (mStyle) + switch( mStyle ) { - case esNone: - return 0; - - case esFlatArrow: - case esSpikeArrow: - case esLineArrow: - case esSkewedBar: - return qSqrt(mWidth*mWidth+mLength*mLength); // items that have width and length - - case esDisc: - case esSquare: - case esDiamond: - case esBar: - case esHalfBar: - return mWidth*1.42; // items that only have a width -> width*sqrt(2) + case esNone: + return 0; + case esFlatArrow: + case esSpikeArrow: + case esLineArrow: + case esSkewedBar: + return qSqrt( mWidth * mWidth + mLength * mLength ); // items that have width and length + + case esDisc: + case esSquare: + case esDiamond: + case esBar: + case esHalfBar: + return mWidth * 1.42; // items that only have a width -> width*sqrt(2) } return 0; } @@ -5269,25 +5259,25 @@ double QCPLineEnding::boundingDistance() const */ double QCPLineEnding::realLength() const { - switch (mStyle) + switch( mStyle ) { - case esNone: - case esLineArrow: - case esSkewedBar: - case esBar: - case esHalfBar: - return 0; - - case esFlatArrow: - return mLength; - - case esDisc: - case esSquare: - case esDiamond: - return mWidth*0.5; - - case esSpikeArrow: - return mLength*0.8; + case esNone: + case esLineArrow: + case esSkewedBar: + case esBar: + case esHalfBar: + return 0; + + case esFlatArrow: + return mLength; + + case esDisc: + case esSquare: + case esDiamond: + return mWidth * 0.5; + + case esSpikeArrow: + return mLength * 0.8; } return 0; } @@ -5297,124 +5287,112 @@ double QCPLineEnding::realLength() const Draws the line ending with the specified \a painter at the position \a pos. The direction of the line ending is controlled with \a dir. */ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const +void QCPLineEnding::draw( QCPPainter* painter, const QCPVector2D& pos, const QCPVector2D& dir ) const { - if (mStyle == esNone) + if( mStyle == esNone ) return; - - QCPVector2D lengthVec = dir.normalized() * mLength*(mInverted ? -1 : 1); - if (lengthVec.isNull()) - lengthVec = QCPVector2D(1, 0); - QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth*0.5*(mInverted ? -1 : 1); - + + QCPVector2D lengthVec = dir.normalized() * mLength * ( mInverted ? -1 : 1 ); + if( lengthVec.isNull() ) + lengthVec = QCPVector2D( 1, 0 ); + QCPVector2D widthVec = dir.normalized().perpendicular() * mWidth * 0.5 * ( mInverted ? -1 : 1 ); + QPen penBackup = painter->pen(); QBrush brushBackup = painter->brush(); QPen miterPen = penBackup; - miterPen.setJoinStyle(Qt::MiterJoin); // to make arrow heads spikey - QBrush brush(painter->pen().color(), Qt::SolidPattern); - switch (mStyle) + miterPen.setJoinStyle( Qt::MiterJoin ); // to make arrow heads spikey + QBrush brush( painter->pen().color(), Qt::SolidPattern ); + switch( mStyle ) { - case esNone: break; - case esFlatArrow: + case esNone: + break; + case esFlatArrow: { + QPointF points[3] = { pos.toPointF(), + ( pos - lengthVec + widthVec ).toPointF(), + ( pos - lengthVec - widthVec ).toPointF() }; + painter->setPen( miterPen ); + painter->setBrush( brush ); + painter->drawConvexPolygon( points, 3 ); + painter->setBrush( brushBackup ); + painter->setPen( penBackup ); + break; + } + case esSpikeArrow: { + QPointF points[4] = { pos.toPointF(), + ( pos - lengthVec + widthVec ).toPointF(), + ( pos - lengthVec * 0.8 ).toPointF(), + ( pos - lengthVec - widthVec ).toPointF() }; + painter->setPen( miterPen ); + painter->setBrush( brush ); + painter->drawConvexPolygon( points, 4 ); + painter->setBrush( brushBackup ); + painter->setPen( penBackup ); + break; + } + case esLineArrow: { + QPointF points[3] = { ( pos - lengthVec + widthVec ).toPointF(), + pos.toPointF(), + ( pos - lengthVec - widthVec ).toPointF() }; + painter->setPen( miterPen ); + painter->drawPolyline( points, 3 ); + painter->setPen( penBackup ); + break; + } + case esDisc: { + painter->setBrush( brush ); + painter->drawEllipse( pos.toPointF(), mWidth * 0.5, mWidth * 0.5 ); + painter->setBrush( brushBackup ); + break; + } + case esSquare: { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = { ( pos - widthVecPerp + widthVec ).toPointF(), + ( pos - widthVecPerp - widthVec ).toPointF(), + ( pos + widthVecPerp - widthVec ).toPointF(), + ( pos + widthVecPerp + widthVec ).toPointF() }; + painter->setPen( miterPen ); + painter->setBrush( brush ); + painter->drawConvexPolygon( points, 4 ); + painter->setBrush( brushBackup ); + painter->setPen( penBackup ); + break; + } + case esDiamond: { + QCPVector2D widthVecPerp = widthVec.perpendicular(); + QPointF points[4] = { ( pos - widthVecPerp ).toPointF(), + ( pos - widthVec ).toPointF(), + ( pos + widthVecPerp ).toPointF(), + ( pos + widthVec ).toPointF() }; + painter->setPen( miterPen ); + painter->setBrush( brush ); + painter->drawConvexPolygon( points, 4 ); + painter->setBrush( brushBackup ); + painter->setPen( penBackup ); + break; + } + case esBar: { + painter->drawLine( ( pos + widthVec ).toPointF(), ( pos - widthVec ).toPointF() ); + break; + } + case esHalfBar: { + painter->drawLine( ( pos + widthVec ).toPointF(), pos.toPointF() ); + break; + } + case esSkewedBar: { + if( qFuzzyIsNull( painter->pen().widthF() ) && !painter->modes().testFlag( QCPPainter::pmNonCosmetic ) ) { - QPointF points[3] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 3); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; + // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line + painter->drawLine( ( pos + widthVec + lengthVec * 0.2 * ( mInverted ? -1 : 1 ) ).toPointF(), + ( pos - widthVec - lengthVec * 0.2 * ( mInverted ? -1 : 1 ) ).toPointF() ); } - case esSpikeArrow: + else { - QPointF points[4] = {pos.toPointF(), - (pos-lengthVec+widthVec).toPointF(), - (pos-lengthVec*0.8).toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esLineArrow: - { - QPointF points[3] = {(pos-lengthVec+widthVec).toPointF(), - pos.toPointF(), - (pos-lengthVec-widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->drawPolyline(points, 3); - painter->setPen(penBackup); - break; - } - case esDisc: - { - painter->setBrush(brush); - painter->drawEllipse(pos.toPointF(), mWidth*0.5, mWidth*0.5); - painter->setBrush(brushBackup); - break; - } - case esSquare: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp+widthVec).toPointF(), - (pos-widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp-widthVec).toPointF(), - (pos+widthVecPerp+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esDiamond: - { - QCPVector2D widthVecPerp = widthVec.perpendicular(); - QPointF points[4] = {(pos-widthVecPerp).toPointF(), - (pos-widthVec).toPointF(), - (pos+widthVecPerp).toPointF(), - (pos+widthVec).toPointF() - }; - painter->setPen(miterPen); - painter->setBrush(brush); - painter->drawConvexPolygon(points, 4); - painter->setBrush(brushBackup); - painter->setPen(penBackup); - break; - } - case esBar: - { - painter->drawLine((pos+widthVec).toPointF(), (pos-widthVec).toPointF()); - break; - } - case esHalfBar: - { - painter->drawLine((pos+widthVec).toPointF(), pos.toPointF()); - break; - } - case esSkewedBar: - { - if (qFuzzyIsNull(painter->pen().widthF()) && !painter->modes().testFlag(QCPPainter::pmNonCosmetic)) - { - // if drawing with cosmetic pen (perfectly thin stroke, happens only in vector exports), draw bar exactly on tip of line - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)).toPointF()); - } else - { - // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly - painter->drawLine((pos+widthVec+lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF(), - (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+dir.normalized()*qMax(1.0f, (float)painter->pen().widthF())*0.5f).toPointF()); - } - break; + // if drawing with thick (non-cosmetic) pen, shift bar a little in line direction to prevent line from sticking through bar slightly + painter->drawLine( ( pos + widthVec + lengthVec * 0.2 * ( mInverted ? -1 : 1 ) + dir.normalized() * qMax( 1.0f, (float)painter->pen().widthF() ) * 0.5f ).toPointF(), + ( pos - widthVec - lengthVec * 0.2 * ( mInverted ? -1 : 1 ) + dir.normalized() * qMax( 1.0f, (float)painter->pen().widthF() ) * 0.5f ).toPointF() ); } + break; + } } } @@ -5423,13 +5401,12 @@ void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, const QCPV Draws the line ending. The direction is controlled with the \a angle parameter in radians. */ -void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const +void QCPLineEnding::draw( QCPPainter* painter, const QCPVector2D& pos, double angle ) const { - draw(painter, pos, QCPVector2D(qCos(angle), qSin(angle))); + draw( painter, pos, QCPVector2D( qCos( angle ), qSin( angle ) ) ); } /* end of 'src/lineending.cpp' */ - /* including file 'src/axis/axisticker.cpp', size 18664 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5493,23 +5470,20 @@ void QCPLineEnding::draw(QCPPainter *painter, const QCPVector2D &pos, double ang Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTicker::QCPAxisTicker() : - mTickStepStrategy(tssReadability), - mTickCount(5), - mTickOrigin(0) +QCPAxisTicker::QCPAxisTicker() + : mTickStepStrategy( tssReadability ), mTickCount( 5 ), mTickOrigin( 0 ) { } QCPAxisTicker::~QCPAxisTicker() { - } /*! Sets which strategy the axis ticker follows when choosing the size of the tick step. For the available strategies, see \ref TickStepStrategy. */ -void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy) +void QCPAxisTicker::setTickStepStrategy( QCPAxisTicker::TickStepStrategy strategy ) { mTickStepStrategy = strategy; } @@ -5522,9 +5496,9 @@ void QCPAxisTicker::setTickStepStrategy(QCPAxisTicker::TickStepStrategy strategy Whether the readability has priority over meeting the requested \a count can be specified with \ref setTickStepStrategy. */ -void QCPAxisTicker::setTickCount(int count) +void QCPAxisTicker::setTickCount( int count ) { - if (count > 0) + if( count > 0 ) mTickCount = count; else qDebug() << Q_FUNC_INFO << "tick count must be greater than zero:" << count; @@ -5538,7 +5512,7 @@ void QCPAxisTicker::setTickCount(int count) step is five. If \a origin is now set to 1 instead, the correspondingly generated ticks would be {-4, 1, 6, 11, 16,...}. */ -void QCPAxisTicker::setTickOrigin(double origin) +void QCPAxisTicker::setTickOrigin( double origin ) { mTickOrigin = origin; } @@ -5556,29 +5530,30 @@ void QCPAxisTicker::setTickOrigin(double origin) and are respectively filled with sub tick coordinates, and tick label strings belonging to \a ticks by index. */ -void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels) +void QCPAxisTicker::generate( const QCPRange& range, const QLocale& locale, QChar formatChar, int precision, QVector& ticks, QVector* subTicks, QVector* tickLabels ) { // generate (major) ticks: - double tickStep = getTickStep(range); - ticks = createTickVector(tickStep, range); - trimTicks(range, ticks, true); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) - + double tickStep = getTickStep( range ); + ticks = createTickVector( tickStep, range ); + trimTicks( range, ticks, true ); // trim ticks to visible range plus one outer tick on each side (incase a subclass createTickVector creates more) + // generate sub ticks between major ticks: - if (subTicks) + if( subTicks ) { - if (ticks.size() > 0) + if( ticks.size() > 0 ) { - *subTicks = createSubTickVector(getSubTickCount(tickStep), ticks); - trimTicks(range, *subTicks, false); - } else + *subTicks = createSubTickVector( getSubTickCount( tickStep ), ticks ); + trimTicks( range, *subTicks, false ); + } + else *subTicks = QVector(); } - + // finally trim also outliers (no further clipping happens in axis drawing): - trimTicks(range, ticks, false); + trimTicks( range, ticks, false ); // generate labels for visible ticks if requested: - if (tickLabels) - *tickLabels = createLabelVector(ticks, locale, formatChar, precision); + if( tickLabels ) + *tickLabels = createLabelVector( ticks, locale, formatChar, precision ); } /*! \internal @@ -5591,10 +5566,10 @@ void QCPAxisTicker::generate(const QCPRange &range, const QLocale &locale, QChar implementation, it should reimplement this method. See \ref cleanMantissa for a possible helper function. */ -double QCPAxisTicker::getTickStep(const QCPRange &range) +double QCPAxisTicker::getTickStep( const QCPRange& range ) { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return cleanMantissa(exactStep); + double exactStep = range.size() / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return cleanMantissa( exactStep ); } /*! \internal @@ -5604,55 +5579,92 @@ double QCPAxisTicker::getTickStep(const QCPRange &range) Note that a returned sub tick count of e.g. 4 will split each tick interval into 5 sections. */ -int QCPAxisTicker::getSubTickCount(double tickStep) +int QCPAxisTicker::getSubTickCount( double tickStep ) { - int result = 1; // default to 1, if no proper value can be found - + int result = 1; // default to 1, if no proper value can be found + // separate integer and fractional part of mantissa: double epsilon = 0.01; double intPartf; int intPart; - double fracPart = modf(getMantissa(tickStep), &intPartf); + double fracPart = modf( getMantissa( tickStep ), &intPartf ); intPart = intPartf; - + // handle cases with (almost) integer mantissa: - if (fracPart < epsilon || 1.0-fracPart < epsilon) + if( fracPart < epsilon || 1.0 - fracPart < epsilon ) { - if (1.0-fracPart < epsilon) + if( 1.0 - fracPart < epsilon ) ++intPart; - switch (intPart) + switch( intPart ) { - case 1: result = 4; break; // 1.0 -> 0.2 substep - case 2: result = 3; break; // 2.0 -> 0.5 substep - case 3: result = 2; break; // 3.0 -> 1.0 substep - case 4: result = 3; break; // 4.0 -> 1.0 substep - case 5: result = 4; break; // 5.0 -> 1.0 substep - case 6: result = 2; break; // 6.0 -> 2.0 substep - case 7: result = 6; break; // 7.0 -> 1.0 substep - case 8: result = 3; break; // 8.0 -> 2.0 substep - case 9: result = 2; break; // 9.0 -> 3.0 substep + case 1: + result = 4; + break; // 1.0 -> 0.2 substep + case 2: + result = 3; + break; // 2.0 -> 0.5 substep + case 3: + result = 2; + break; // 3.0 -> 1.0 substep + case 4: + result = 3; + break; // 4.0 -> 1.0 substep + case 5: + result = 4; + break; // 5.0 -> 1.0 substep + case 6: + result = 2; + break; // 6.0 -> 2.0 substep + case 7: + result = 6; + break; // 7.0 -> 1.0 substep + case 8: + result = 3; + break; // 8.0 -> 2.0 substep + case 9: + result = 2; + break; // 9.0 -> 3.0 substep } - } else + } + else { // handle cases with significantly fractional mantissa: - if (qAbs(fracPart-0.5) < epsilon) // *.5 mantissa + if( qAbs( fracPart - 0.5 ) < epsilon ) // *.5 mantissa { - switch (intPart) + switch( intPart ) { - case 1: result = 2; break; // 1.5 -> 0.5 substep - case 2: result = 4; break; // 2.5 -> 0.5 substep - case 3: result = 4; break; // 3.5 -> 0.7 substep - case 4: result = 2; break; // 4.5 -> 1.5 substep - case 5: result = 4; break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) - case 6: result = 4; break; // 6.5 -> 1.3 substep - case 7: result = 2; break; // 7.5 -> 2.5 substep - case 8: result = 4; break; // 8.5 -> 1.7 substep - case 9: result = 4; break; // 9.5 -> 1.9 substep + case 1: + result = 2; + break; // 1.5 -> 0.5 substep + case 2: + result = 4; + break; // 2.5 -> 0.5 substep + case 3: + result = 4; + break; // 3.5 -> 0.7 substep + case 4: + result = 2; + break; // 4.5 -> 1.5 substep + case 5: + result = 4; + break; // 5.5 -> 1.1 substep (won't occur with default getTickStep from here on) + case 6: + result = 4; + break; // 6.5 -> 1.3 substep + case 7: + result = 2; + break; // 7.5 -> 2.5 substep + case 8: + result = 4; + break; // 8.5 -> 1.7 substep + case 9: + result = 4; + break; // 9.5 -> 1.9 substep } } // if mantissa fraction isn't 0.0 or 0.5, don't bother finding good sub tick marks, leave default } - + return result; } @@ -5667,9 +5679,9 @@ int QCPAxisTicker::getSubTickCount(double tickStep) be formatted accordingly using multiplication symbol and superscript during rendering of the label automatically. */ -QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +QString QCPAxisTicker::getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) { - return locale.toString(tick, formatChar.toLatin1(), precision); + return locale.toString( tick, formatChar.toLatin1(), precision ); } /*! \internal @@ -5681,18 +5693,18 @@ QString QCPAxisTicker::getTickLabel(double tick, const QLocale &locale, QChar fo reimplement this method. Depending on the purpose of the subclass it doesn't necessarily need to base its result on \a subTickCount or \a ticks. */ -QVector QCPAxisTicker::createSubTickVector(int subTickCount, const QVector &ticks) +QVector QCPAxisTicker::createSubTickVector( int subTickCount, const QVector& ticks ) { QVector result; - if (subTickCount <= 0 || ticks.size() < 2) + if( subTickCount <= 0 || ticks.size() < 2 ) return result; - - result.reserve((ticks.size()-1)*subTickCount); - for (int i=1; i QCPAxisTicker::createSubTickVector(int subTickCount, const QVect result on \a tickStep, e.g. when the ticks are spaced unequally like in the case of QCPAxisTickerLog. */ -QVector QCPAxisTicker::createTickVector(double tickStep, const QCPRange &range) +QVector QCPAxisTicker::createTickVector( double tickStep, const QCPRange& range ) { QVector result; // Generate tick positions according to tickStep: - qint64 firstStep = floor((range.lower-mTickOrigin)/tickStep); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = ceil((range.upper-mTickOrigin)/tickStep); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = lastStep-firstStep+1; - if (tickcount < 0) tickcount = 0; - result.resize(tickcount); - for (int i=0; i QCPAxisTicker::createTickVector(double tickStep, const QCPRange It is possible but uncommon for QCPAxisTicker subclasses to reimplement this method, as reimplementing \ref getTickLabel often achieves the intended result easier. */ -QVector QCPAxisTicker::createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision) +QVector QCPAxisTicker::createLabelVector( const QVector& ticks, const QLocale& locale, QChar formatChar, int precision ) { QVector result; - result.reserve(ticks.size()); - for (int i=0; i QCPAxisTicker::createLabelVector(const QVector &ticks, The passed \a ticks must be sorted in ascending order. */ -void QCPAxisTicker::trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const +void QCPAxisTicker::trimTicks( const QCPRange& range, QVector& ticks, bool keepOneOutlier ) const { bool lowFound = false; bool highFound = false; int lowIndex = 0; int highIndex = -1; - - for (int i=0; i < ticks.size(); ++i) + + for( int i = 0; i < ticks.size(); ++i ) { - if (ticks.at(i) >= range.lower) + if( ticks.at( i ) >= range.lower ) { lowFound = true; lowIndex = i; break; } } - for (int i=ticks.size()-1; i >= 0; --i) + for( int i = ticks.size() - 1; i >= 0; --i ) { - if (ticks.at(i) <= range.upper) + if( ticks.at( i ) <= range.upper ) { highFound = true; highIndex = i; break; } } - - if (highFound && lowFound) + + if( highFound && lowFound ) { - int trimFront = qMax(0, lowIndex-(keepOneOutlier ? 1 : 0)); - int trimBack = qMax(0, ticks.size()-(keepOneOutlier ? 2 : 1)-highIndex); - if (trimFront > 0 || trimBack > 0) - ticks = ticks.mid(trimFront, ticks.size()-trimFront-trimBack); - } else // all ticks are either all below or all above the range + int trimFront = qMax( 0, lowIndex - ( keepOneOutlier ? 1 : 0 ) ); + int trimBack = qMax( 0, ticks.size() - ( keepOneOutlier ? 2 : 1 ) - highIndex ); + if( trimFront > 0 || trimBack > 0 ) + ticks = ticks.mid( trimFront, ticks.size() - trimFront - trimBack ); + } + else // all ticks are either all below or all above the range ticks.clear(); } @@ -5793,17 +5807,17 @@ void QCPAxisTicker::trimTicks(const QCPRange &range, QVector &ticks, boo This method assumes \a candidates is not empty and sorted in ascending order. */ -double QCPAxisTicker::pickClosest(double target, const QVector &candidates) const +double QCPAxisTicker::pickClosest( double target, const QVector& candidates ) const { - if (candidates.size() == 1) + if( candidates.size() == 1 ) return candidates.first(); - QVector::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target); - if (it == candidates.constEnd()) - return *(it-1); - else if (it == candidates.constBegin()) + QVector::const_iterator it = std::lower_bound( candidates.constBegin(), candidates.constEnd(), target ); + if( it == candidates.constEnd() ) + return *( it - 1 ); + else if( it == candidates.constBegin() ) return *it; else - return target-*(it-1) < *it-target ? *(it-1) : *it; + return target - *( it - 1 ) < *it - target ? *( it - 1 ) : *it; } /*! \internal @@ -5813,11 +5827,12 @@ double QCPAxisTicker::pickClosest(double target, const QVector &candidat For example, an input of 142.6 will return a mantissa of 1.426 and a magnitude of 100. */ -double QCPAxisTicker::getMantissa(double input, double *magnitude) const +double QCPAxisTicker::getMantissa( double input, double* magnitude ) const { - const double mag = qPow(10.0, qFloor(qLn(input)/qLn(10.0))); - if (magnitude) *magnitude = mag; - return input/mag; + const double mag = qPow( 10.0, qFloor( qLn( input ) / qLn( 10.0 ) ) ); + if( magnitude ) + *magnitude = mag; + return input / mag; } /*! \internal @@ -5826,30 +5841,27 @@ double QCPAxisTicker::getMantissa(double input, double *magnitude) const strongly the mantissa is altered, and thus how strong the result deviates from the original \a input, depends on the current tick step strategy (see \ref setTickStepStrategy). */ -double QCPAxisTicker::cleanMantissa(double input) const +double QCPAxisTicker::cleanMantissa( double input ) const { double magnitude; - const double mantissa = getMantissa(input, &magnitude); - switch (mTickStepStrategy) + const double mantissa = getMantissa( input, &magnitude ); + switch( mTickStepStrategy ) { - case tssReadability: - { - return pickClosest(mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0)*magnitude; - } - case tssMeetTickCount: - { - // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 - if (mantissa <= 5.0) - return (int)(mantissa*2)/2.0*magnitude; // round digit after decimal point to 0.5 - else - return (int)(mantissa/2.0)*2.0*magnitude; // round to first digit in multiples of 2 - } + case tssReadability: { + return pickClosest( mantissa, QVector() << 1.0 << 2.0 << 2.5 << 5.0 << 10.0 ) * magnitude; + } + case tssMeetTickCount: { + // this gives effectively a mantissa of 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 8.0, 10.0 + if( mantissa <= 5.0 ) + return (int)( mantissa * 2 ) / 2.0 * magnitude; // round digit after decimal point to 0.5 + else + return (int)( mantissa / 2.0 ) * 2.0 * magnitude; // round to first digit in multiples of 2 + } } return input; } /* end of 'src/axis/axisticker.cpp' */ - /* including file 'src/axis/axistickerdatetime.cpp', size 14443 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5896,12 +5908,10 @@ double QCPAxisTicker::cleanMantissa(double input) const Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerDateTime::QCPAxisTickerDateTime() : - mDateTimeFormat(QLatin1String("hh:mm:ss\ndd.MM.yy")), - mDateTimeSpec(Qt::LocalTime), - mDateStrategy(dsNone) +QCPAxisTickerDateTime::QCPAxisTickerDateTime() + : mDateTimeFormat( QLatin1String( "hh:mm:ss\ndd.MM.yy" ) ), mDateTimeSpec( Qt::LocalTime ), mDateStrategy( dsNone ) { - setTickCount(4); + setTickCount( 4 ); } /*! @@ -5912,7 +5922,7 @@ QCPAxisTickerDateTime::QCPAxisTickerDateTime() : \see setDateTimeSpec */ -void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) +void QCPAxisTickerDateTime::setDateTimeFormat( const QString& format ) { mDateTimeFormat = format; } @@ -5927,7 +5937,7 @@ void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) \see setDateTimeFormat */ -void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) +void QCPAxisTickerDateTime::setDateTimeSpec( Qt::TimeSpec spec ) { mDateTimeSpec = spec; } @@ -5941,9 +5951,9 @@ void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick per year, the ticks will end up on 15. July at 9:45 of every year. */ -void QCPAxisTickerDateTime::setTickOrigin(double origin) +void QCPAxisTickerDateTime::setTickOrigin( double origin ) { - QCPAxisTicker::setTickOrigin(origin); + QCPAxisTicker::setTickOrigin( origin ); } /*! @@ -5953,9 +5963,9 @@ void QCPAxisTickerDateTime::setTickOrigin(double origin) example, If you pass 15. July, 9:45 to this method and the tick interval happens to be one tick per year, the ticks will end up on 15. July at 9:45 of every year. */ -void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) +void QCPAxisTickerDateTime::setTickOrigin( const QDateTime& origin ) { - setTickOrigin(dateTimeToKey(origin)); + setTickOrigin( dateTimeToKey( origin ) ); } /*! \internal @@ -5971,28 +5981,30 @@ void QCPAxisTickerDateTime::setTickOrigin(const QDateTime &origin) \seebaseclassmethod */ -double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) +double QCPAxisTickerDateTime::getTickStep( const QCPRange& range ) { - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - + double result = range.size() / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mDateStrategy = dsNone; - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + if( result < 1 ) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds { - result = cleanMantissa(result); - } else if (result < 86400*30.4375*12) // below a year + result = cleanMantissa( result ); + } + else if( result < 86400 * 30.4375 * 12 ) // below a year { - result = pickClosest(result, QVector() - << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5*60 << 5*60 << 10*60 << 15*60 << 30*60 << 60*60 // second, minute, hour range - << 3600*2 << 3600*3 << 3600*6 << 3600*12 << 3600*24 // hour to day range - << 86400*2 << 86400*5 << 86400*7 << 86400*14 << 86400*30.4375 << 86400*30.4375*2 << 86400*30.4375*3 << 86400*30.4375*6 << 86400*30.4375*12); // day, week, month range (avg. days per month includes leap years) - if (result > 86400*30.4375-1) // month tick intervals or larger + result = pickClosest( result, QVector() + << 1 << 2.5 << 5 << 10 << 15 << 30 << 60 << 2.5 * 60 << 5 * 60 << 10 * 60 << 15 * 60 << 30 * 60 << 60 * 60 // second, minute, hour range + << 3600 * 2 << 3600 * 3 << 3600 * 6 << 3600 * 12 << 3600 * 24 // hour to day range + << 86400 * 2 << 86400 * 5 << 86400 * 7 << 86400 * 14 << 86400 * 30.4375 << 86400 * 30.4375 * 2 << 86400 * 30.4375 * 3 << 86400 * 30.4375 * 6 << 86400 * 30.4375 * 12 ); // day, week, month range (avg. days per month includes leap years) + if( result > 86400 * 30.4375 - 1 ) // month tick intervals or larger mDateStrategy = dsUniformDayInMonth; - else if (result > 3600*24-1) // day tick intervals or larger + else if( result > 3600 * 24 - 1 ) // day tick intervals or larger mDateStrategy = dsUniformTimeInDay; - } else // more than a year, go back to normal clean mantissa algorithm but in units of years + } + else // more than a year, go back to normal clean mantissa algorithm but in units of years { - const double secondsPerYear = 86400*30.4375*12; // average including leap years - result = cleanMantissa(result/secondsPerYear)*secondsPerYear; + const double secondsPerYear = 86400 * 30.4375 * 12; // average including leap years + result = cleanMantissa( result / secondsPerYear ) * secondsPerYear; mDateStrategy = dsUniformDayInMonth; } return result; @@ -6005,30 +6017,68 @@ double QCPAxisTickerDateTime::getTickStep(const QCPRange &range) \seebaseclassmethod */ -int QCPAxisTickerDateTime::getSubTickCount(double tickStep) +int QCPAxisTickerDateTime::getSubTickCount( double tickStep ) { - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) + int result = QCPAxisTicker::getSubTickCount( tickStep ); + switch( qRound( tickStep ) ) // hand chosen subticks for specific minute/hour/day/week/month range (as specified in getTickStep) { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; - case 86400*2: result = 1; break; - case 86400*5: result = 4; break; - case 86400*7: result = 6; break; - case 86400*14: result = 1; break; - case (int)(86400*30.4375+0.5): result = 3; break; - case (int)(86400*30.4375*2+0.5): result = 1; break; - case (int)(86400*30.4375*3+0.5): result = 2; break; - case (int)(86400*30.4375*6+0.5): result = 5; break; - case (int)(86400*30.4375*12+0.5): result = 3; break; + case 5 * 60: + result = 4; + break; + case 10 * 60: + result = 1; + break; + case 15 * 60: + result = 2; + break; + case 30 * 60: + result = 1; + break; + case 60 * 60: + result = 3; + break; + case 3600 * 2: + result = 3; + break; + case 3600 * 3: + result = 2; + break; + case 3600 * 6: + result = 1; + break; + case 3600 * 12: + result = 3; + break; + case 3600 * 24: + result = 3; + break; + case 86400 * 2: + result = 1; + break; + case 86400 * 5: + result = 4; + break; + case 86400 * 7: + result = 6; + break; + case 86400 * 14: + result = 1; + break; + case(int)( 86400 * 30.4375 + 0.5 ): + result = 3; + break; + case(int)( 86400 * 30.4375 * 2 + 0.5 ): + result = 1; + break; + case(int)( 86400 * 30.4375 * 3 + 0.5 ): + result = 2; + break; + case(int)( 86400 * 30.4375 * 6 + 0.5 ): + result = 5; + break; + case(int)( 86400 * 30.4375 * 12 + 0.5 ): + result = 3; + break; } return result; } @@ -6040,11 +6090,11 @@ int QCPAxisTickerDateTime::getSubTickCount(double tickStep) \seebaseclassmethod */ -QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +QString QCPAxisTickerDateTime::getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) { - Q_UNUSED(precision) - Q_UNUSED(formatChar) - return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); + Q_UNUSED( precision ) + Q_UNUSED( formatChar ) + return locale.toString( keyToDateTime( tick ).toTimeSpec( mDateTimeSpec ), mDateTimeFormat ); } /*! \internal @@ -6054,36 +6104,37 @@ QString QCPAxisTickerDateTime::getTickLabel(double tick, const QLocale &locale, \seebaseclassmethod */ -QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const QCPRange &range) +QVector QCPAxisTickerDateTime::createTickVector( double tickStep, const QCPRange& range ) { - QVector result = QCPAxisTicker::createTickVector(tickStep, range); - if (!result.isEmpty()) + QVector result = QCPAxisTicker::createTickVector( tickStep, range ); + if( !result.isEmpty() ) { - if (mDateStrategy == dsUniformTimeInDay) + if( mDateStrategy == dsUniformTimeInDay ) { - QDateTime uniformDateTime = keyToDateTime(mTickOrigin); // the time of this datetime will be set for all other ticks, if possible + QDateTime uniformDateTime = keyToDateTime( mTickOrigin ); // the time of this datetime will be set for all other ticks, if possible QDateTime tickDateTime; - for (int i=0; i 15) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day - tickDateTime = tickDateTime.addMonths(-1); - tickDateTime.setDate(QDate(tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay)); - result[i] = dateTimeToKey(tickDateTime); + tickDateTime = keyToDateTime( result.at( i ) ); + tickDateTime.setTime( uniformDateTime.time() ); + int thisUniformDay = uniformDateTime.date().day() <= tickDateTime.date().daysInMonth() ? uniformDateTime.date().day() : tickDateTime.date().daysInMonth(); // don't exceed month (e.g. try to set day 31 in February) + if( thisUniformDay - tickDateTime.date().day() < -15 ) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths( 1 ); + else if( thisUniformDay - tickDateTime.date().day() > 15 ) // with leap years involved, date month may jump backwards or forwards, and needs to be corrected before setting day + tickDateTime = tickDateTime.addMonths( -1 ); + tickDateTime.setDate( QDate( tickDateTime.date().year(), tickDateTime.date().month(), thisUniformDay ) ); + result[i] = dateTimeToKey( tickDateTime ); } } } @@ -6099,13 +6150,13 @@ QVector QCPAxisTickerDateTime::createTickVector(double tickStep, const Q \see dateTimeToKey */ -QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) +QDateTime QCPAxisTickerDateTime::keyToDateTime( double key ) { -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime::fromTime_t(key).addMSecs((key-(qint64)key)*1000); -# else - return QDateTime::fromMSecsSinceEpoch(key*1000.0); -# endif +#if QT_VERSION < QT_VERSION_CHECK( 4, 7, 0 ) + return QDateTime::fromTime_t( key ).addMSecs( ( key - (qint64)key ) * 1000 ); +#else + return QDateTime::fromMSecsSinceEpoch( key * 1000.0 ); +#endif } /*! \overload @@ -6119,13 +6170,13 @@ QDateTime QCPAxisTickerDateTime::keyToDateTime(double key) \see keyToDateTime */ -double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) +double QCPAxisTickerDateTime::dateTimeToKey( const QDateTime dateTime ) { -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return dateTime.toTime_t()+dateTime.time().msec()/1000.0; -# else - return dateTime.toMSecsSinceEpoch()/1000.0; -# endif +#if QT_VERSION < QT_VERSION_CHECK( 4, 7, 0 ) + return dateTime.toTime_t() + dateTime.time().msec() / 1000.0; +#else + return dateTime.toMSecsSinceEpoch() / 1000.0; +#endif } /*! \overload @@ -6136,17 +6187,16 @@ double QCPAxisTickerDateTime::dateTimeToKey(const QDateTime dateTime) \see keyToDateTime */ -double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) +double QCPAxisTickerDateTime::dateTimeToKey( const QDate date ) { -# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) - return QDateTime(date).toTime_t(); -# else - return QDateTime(date).toMSecsSinceEpoch()/1000.0; -# endif +#if QT_VERSION < QT_VERSION_CHECK( 4, 7, 0 ) + return QDateTime( date ).toTime_t(); +#else + return QDateTime( date ).toMSecsSinceEpoch() / 1000.0; +#endif } /* end of 'src/axis/axistickerdatetime.cpp' */ - /* including file 'src/axis/axistickertime.cpp', size 11747 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6193,23 +6243,21 @@ double QCPAxisTickerDateTime::dateTimeToKey(const QDate date) Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerTime::QCPAxisTickerTime() : - mTimeFormat(QLatin1String("%h:%m:%s")), - mSmallestUnit(tuSeconds), - mBiggestUnit(tuHours) +QCPAxisTickerTime::QCPAxisTickerTime() + : mTimeFormat( QLatin1String( "%h:%m:%s" ) ), mSmallestUnit( tuSeconds ), mBiggestUnit( tuHours ) { - setTickCount(4); + setTickCount( 4 ); mFieldWidth[tuMilliseconds] = 3; mFieldWidth[tuSeconds] = 2; mFieldWidth[tuMinutes] = 2; mFieldWidth[tuHours] = 2; mFieldWidth[tuDays] = 1; - - mFormatPattern[tuMilliseconds] = QLatin1String("%z"); - mFormatPattern[tuSeconds] = QLatin1String("%s"); - mFormatPattern[tuMinutes] = QLatin1String("%m"); - mFormatPattern[tuHours] = QLatin1String("%h"); - mFormatPattern[tuDays] = QLatin1String("%d"); + + mFormatPattern[tuMilliseconds] = QLatin1String( "%z" ); + mFormatPattern[tuSeconds] = QLatin1String( "%s" ); + mFormatPattern[tuMinutes] = QLatin1String( "%m" ); + mFormatPattern[tuHours] = QLatin1String( "%h" ); + mFormatPattern[tuDays] = QLatin1String( "%d" ); } /*! @@ -6230,21 +6278,21 @@ QCPAxisTickerTime::QCPAxisTickerTime() : other hand %%h is available, the minutes will wrap around to zero after 59 and the time will carry to the hour digit. */ -void QCPAxisTickerTime::setTimeFormat(const QString &format) +void QCPAxisTickerTime::setTimeFormat( const QString& format ) { mTimeFormat = format; - + // determine smallest and biggest unit in format, to optimize unit replacement and allow biggest // unit to consume remaining time of a tick value and grow beyond its modulo (e.g. min > 59) mSmallestUnit = tuMilliseconds; mBiggestUnit = tuMilliseconds; bool hasSmallest = false; - for (int i = tuMilliseconds; i <= tuDays; ++i) + for( int i = tuMilliseconds; i <= tuDays; ++i ) { - TimeUnit unit = static_cast(i); - if (mTimeFormat.contains(mFormatPattern.value(unit))) + TimeUnit unit = static_cast( i ); + if( mTimeFormat.contains( mFormatPattern.value( unit ) ) ) { - if (!hasSmallest) + if( !hasSmallest ) { mSmallestUnit = unit; hasSmallest = true; @@ -6261,9 +6309,9 @@ void QCPAxisTickerTime::setTimeFormat(const QString &format) \see setTimeFormat */ -void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int width) +void QCPAxisTickerTime::setFieldWidth( QCPAxisTickerTime::TimeUnit unit, int width ) { - mFieldWidth[unit] = qMax(width, 1); + mFieldWidth[unit] = qMax( width, 1 ); } /*! \internal @@ -6275,47 +6323,49 @@ void QCPAxisTickerTime::setFieldWidth(QCPAxisTickerTime::TimeUnit unit, int widt \seebaseclassmethod */ -double QCPAxisTickerTime::getTickStep(const QCPRange &range) +double QCPAxisTickerTime::getTickStep( const QCPRange& range ) { - double result = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - - if (result < 1) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds + double result = range.size() / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + + if( result < 1 ) // ideal tick step is below 1 second -> use normal clean mantissa algorithm in units of seconds { - if (mSmallestUnit == tuMilliseconds) - result = qMax(cleanMantissa(result), 0.001); // smallest tick step is 1 millisecond - else // have no milliseconds available in format, so stick with 1 second tickstep + if( mSmallestUnit == tuMilliseconds ) + result = qMax( cleanMantissa( result ), 0.001 ); // smallest tick step is 1 millisecond + else // have no milliseconds available in format, so stick with 1 second tickstep result = 1.0; - } else if (result < 3600*24) // below a day + } + else if( result < 3600 * 24 ) // below a day { // the filling of availableSteps seems a bit contorted but it fills in a sorted fashion and thus saves a post-fill sorting run QVector availableSteps; // seconds range: - if (mSmallestUnit <= tuSeconds) + if( mSmallestUnit <= tuSeconds ) availableSteps << 1; - if (mSmallestUnit == tuMilliseconds) - availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it - else if (mSmallestUnit == tuSeconds) + if( mSmallestUnit == tuMilliseconds ) + availableSteps << 2.5; // only allow half second steps if milliseconds are there to display it + else if( mSmallestUnit == tuSeconds ) availableSteps << 2; - if (mSmallestUnit <= tuSeconds) + if( mSmallestUnit <= tuSeconds ) availableSteps << 5 << 10 << 15 << 30; // minutes range: - if (mSmallestUnit <= tuMinutes) - availableSteps << 1*60; - if (mSmallestUnit <= tuSeconds) - availableSteps << 2.5*60; // only allow half minute steps if seconds are there to display it - else if (mSmallestUnit == tuMinutes) - availableSteps << 2*60; - if (mSmallestUnit <= tuMinutes) - availableSteps << 5*60 << 10*60 << 15*60 << 30*60; + if( mSmallestUnit <= tuMinutes ) + availableSteps << 1 * 60; + if( mSmallestUnit <= tuSeconds ) + availableSteps << 2.5 * 60; // only allow half minute steps if seconds are there to display it + else if( mSmallestUnit == tuMinutes ) + availableSteps << 2 * 60; + if( mSmallestUnit <= tuMinutes ) + availableSteps << 5 * 60 << 10 * 60 << 15 * 60 << 30 * 60; // hours range: - if (mSmallestUnit <= tuHours) - availableSteps << 1*3600 << 2*3600 << 3*3600 << 6*3600 << 12*3600 << 24*3600; + if( mSmallestUnit <= tuHours ) + availableSteps << 1 * 3600 << 2 * 3600 << 3 * 3600 << 6 * 3600 << 12 * 3600 << 24 * 3600; // pick available step that is most appropriate to approximate ideal step: - result = pickClosest(result, availableSteps); - } else // more than a day, go back to normal clean mantissa algorithm but in units of days + result = pickClosest( result, availableSteps ); + } + else // more than a day, go back to normal clean mantissa algorithm but in units of days { - const double secondsPerDay = 3600*24; - result = cleanMantissa(result/secondsPerDay)*secondsPerDay; + const double secondsPerDay = 3600 * 24; + result = cleanMantissa( result / secondsPerDay ) * secondsPerDay; } return result; } @@ -6326,21 +6376,41 @@ double QCPAxisTickerTime::getTickStep(const QCPRange &range) \seebaseclassmethod */ -int QCPAxisTickerTime::getSubTickCount(double tickStep) +int QCPAxisTickerTime::getSubTickCount( double tickStep ) { - int result = QCPAxisTicker::getSubTickCount(tickStep); - switch (qRound(tickStep)) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) + int result = QCPAxisTicker::getSubTickCount( tickStep ); + switch( qRound( tickStep ) ) // hand chosen subticks for specific minute/hour/day range (as specified in getTickStep) { - case 5*60: result = 4; break; - case 10*60: result = 1; break; - case 15*60: result = 2; break; - case 30*60: result = 1; break; - case 60*60: result = 3; break; - case 3600*2: result = 3; break; - case 3600*3: result = 2; break; - case 3600*6: result = 1; break; - case 3600*12: result = 3; break; - case 3600*24: result = 3; break; + case 5 * 60: + result = 4; + break; + case 10 * 60: + result = 1; + break; + case 15 * 60: + result = 2; + break; + case 30 * 60: + result = 1; + break; + case 60 * 60: + result = 3; + break; + case 3600 * 2: + result = 3; + break; + case 3600 * 3: + result = 2; + break; + case 3600 * 6: + result = 1; + break; + case 3600 * 12: + result = 3; + break; + case 3600 * 24: + result = 3; + break; } return result; } @@ -6352,31 +6422,32 @@ int QCPAxisTickerTime::getSubTickCount(double tickStep) \seebaseclassmethod */ -QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +QString QCPAxisTickerTime::getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) { - Q_UNUSED(precision) - Q_UNUSED(formatChar) - Q_UNUSED(locale) + Q_UNUSED( precision ) + Q_UNUSED( formatChar ) + Q_UNUSED( locale ) bool negative = tick < 0; - if (negative) tick *= -1; - double values[tuDays+1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) - double restValues[tuDays+1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time - - restValues[tuMilliseconds] = tick*1000; - values[tuMilliseconds] = modf(restValues[tuMilliseconds]/1000, &restValues[tuSeconds])*1000; - values[tuSeconds] = modf(restValues[tuSeconds]/60, &restValues[tuMinutes])*60; - values[tuMinutes] = modf(restValues[tuMinutes]/60, &restValues[tuHours])*60; - values[tuHours] = modf(restValues[tuHours]/24, &restValues[tuDays])*24; + if( negative ) + tick *= -1; + double values[tuDays + 1]; // contains the msec/sec/min/... value with its respective modulo (e.g. minute 0..59) + double restValues[tuDays + 1]; // contains the msec/sec/min/... value as if it's the largest available unit and thus consumes the remaining time + + restValues[tuMilliseconds] = tick * 1000; + values[tuMilliseconds] = modf( restValues[tuMilliseconds] / 1000, &restValues[tuSeconds] ) * 1000; + values[tuSeconds] = modf( restValues[tuSeconds] / 60, &restValues[tuMinutes] ) * 60; + values[tuMinutes] = modf( restValues[tuMinutes] / 60, &restValues[tuHours] ) * 60; + values[tuHours] = modf( restValues[tuHours] / 24, &restValues[tuDays] ) * 24; // no need to set values[tuDays] because days are always a rest value (there is no higher unit so it consumes all remaining time) - + QString result = mTimeFormat; - for (int i = mSmallestUnit; i <= mBiggestUnit; ++i) + for( int i = mSmallestUnit; i <= mBiggestUnit; ++i ) { - TimeUnit iUnit = static_cast(i); - replaceUnit(result, iUnit, qRound(iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit])); + TimeUnit iUnit = static_cast( i ); + replaceUnit( result, iUnit, qRound( iUnit == mBiggestUnit ? restValues[iUnit] : values[iUnit] ) ); } - if (negative) - result.prepend(QLatin1Char('-')); + if( negative ) + result.prepend( QLatin1Char( '-' ) ); return result; } @@ -6385,17 +6456,16 @@ QString QCPAxisTickerTime::getTickLabel(double tick, const QLocale &locale, QCha Replaces all occurrences of the format pattern belonging to \a unit in \a text with the specified \a value, using the field width as specified with \ref setFieldWidth for the \a unit. */ -void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit unit, int value) const +void QCPAxisTickerTime::replaceUnit( QString& text, QCPAxisTickerTime::TimeUnit unit, int value ) const { - QString valueStr = QString::number(value); - while (valueStr.size() < mFieldWidth.value(unit)) - valueStr.prepend(QLatin1Char('0')); - - text.replace(mFormatPattern.value(unit), valueStr); + QString valueStr = QString::number( value ); + while( valueStr.size() < mFieldWidth.value( unit ) ) + valueStr.prepend( QLatin1Char( '0' ) ); + + text.replace( mFormatPattern.value( unit ), valueStr ); } /* end of 'src/axis/axistickertime.cpp' */ - /* including file 'src/axis/axistickerfixed.cpp', size 5583 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6426,9 +6496,8 @@ void QCPAxisTickerTime::replaceUnit(QString &text, QCPAxisTickerTime::TimeUnit u Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerFixed::QCPAxisTickerFixed() : - mTickStep(1.0), - mScaleStrategy(ssNone) +QCPAxisTickerFixed::QCPAxisTickerFixed() + : mTickStep( 1.0 ), mScaleStrategy( ssNone ) { } @@ -6441,9 +6510,9 @@ QCPAxisTickerFixed::QCPAxisTickerFixed() : step. This will enable the ticker to reduce the number of ticks to a reasonable amount (see \ref setTickCount). */ -void QCPAxisTickerFixed::setTickStep(double step) +void QCPAxisTickerFixed::setTickStep( double step ) { - if (step > 0) + if( step > 0 ) mTickStep = step; else qDebug() << Q_FUNC_INFO << "tick step must be greater than zero:" << step; @@ -6456,7 +6525,7 @@ void QCPAxisTickerFixed::setTickStep(double step) The default strategy is \ref ssNone, which means the tick step is absolutely fixed. */ -void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy strategy) +void QCPAxisTickerFixed::setScaleStrategy( QCPAxisTickerFixed::ScaleStrategy strategy ) { mScaleStrategy = strategy; } @@ -6471,33 +6540,29 @@ void QCPAxisTickerFixed::setScaleStrategy(QCPAxisTickerFixed::ScaleStrategy stra \seebaseclassmethod */ -double QCPAxisTickerFixed::getTickStep(const QCPRange &range) +double QCPAxisTickerFixed::getTickStep( const QCPRange& range ) { - switch (mScaleStrategy) + switch( mScaleStrategy ) { - case ssNone: - { + case ssNone: { + return mTickStep; + } + case ssMultiples: { + double exactStep = range.size() / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + if( exactStep < mTickStep ) return mTickStep; - } - case ssMultiples: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - if (exactStep < mTickStep) - return mTickStep; - else - return (qint64)(cleanMantissa(exactStep/mTickStep)+0.5)*mTickStep; - } - case ssPowers: - { - double exactStep = range.size()/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - return qPow(mTickStep, (int)(qLn(exactStep)/qLn(mTickStep)+0.5)); - } + else + return ( qint64 )( cleanMantissa( exactStep / mTickStep ) + 0.5 ) * mTickStep; + } + case ssPowers: { + double exactStep = range.size() / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + return qPow( mTickStep, (int)( qLn( exactStep ) / qLn( mTickStep ) + 0.5 ) ); + } } return mTickStep; } /* end of 'src/axis/axistickerfixed.cpp' */ - /* including file 'src/axis/axistickertext.cpp', size 8661 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6541,8 +6606,8 @@ double QCPAxisTickerFixed::getTickStep(const QCPRange &range) Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerText::QCPAxisTickerText() : - mSubTickCount(0) +QCPAxisTickerText::QCPAxisTickerText() + : mSubTickCount( 0 ) { } @@ -6556,7 +6621,7 @@ QCPAxisTickerText::QCPAxisTickerText() : \see addTicks, addTick, clear */ -void QCPAxisTickerText::setTicks(const QMap &ticks) +void QCPAxisTickerText::setTicks( const QMap& ticks ) { mTicks = ticks; } @@ -6569,10 +6634,10 @@ void QCPAxisTickerText::setTicks(const QMap &ticks) \see addTicks, addTick, clear */ -void QCPAxisTickerText::setTicks(const QVector &positions, const QVector &labels) +void QCPAxisTickerText::setTicks( const QVector& positions, const QVector& labels ) { clear(); - addTicks(positions, labels); + addTicks( positions, labels ); } /*! @@ -6580,9 +6645,9 @@ void QCPAxisTickerText::setTicks(const QVector &positions, const QVector automatic sub tick count calculation. So if sub ticks are needed, they must be configured with this method. */ -void QCPAxisTickerText::setSubTickCount(int subTicks) +void QCPAxisTickerText::setSubTickCount( int subTicks ) { - if (subTicks >= 0) + if( subTicks >= 0 ) mSubTickCount = subTicks; else qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; @@ -6607,9 +6672,9 @@ void QCPAxisTickerText::clear() \see addTicks, setTicks, clear */ -void QCPAxisTickerText::addTick(double position, const QString &label) +void QCPAxisTickerText::addTick( double position, const QString& label ) { - mTicks.insert(position, label); + mTicks.insert( position, label ); } /*! \overload @@ -6622,9 +6687,9 @@ void QCPAxisTickerText::addTick(double position, const QString &label) \see addTick, setTicks, clear */ -void QCPAxisTickerText::addTicks(const QMap &ticks) +void QCPAxisTickerText::addTicks( const QMap& ticks ) { - mTicks.unite(ticks); + mTicks.unite( ticks ); } /*! \overload @@ -6638,13 +6703,13 @@ void QCPAxisTickerText::addTicks(const QMap &ticks) \see addTick, setTicks, clear */ -void QCPAxisTickerText::addTicks(const QVector &positions, const QVector &labels) +void QCPAxisTickerText::addTicks( const QVector& positions, const QVector& labels ) { - if (positions.size() != labels.size()) + if( positions.size() != labels.size() ) qDebug() << Q_FUNC_INFO << "passed unequal length vectors for positions and labels:" << positions.size() << labels.size(); - int n = qMin(positions.size(), labels.size()); - for (int i=0; i &positions, const QVector \seebaseclassmethod */ -double QCPAxisTickerText::getTickStep(const QCPRange &range) +double QCPAxisTickerText::getTickStep( const QCPRange& range ) { // text axis ticker has manual tick positions, so doesn't need this method - Q_UNUSED(range) + Q_UNUSED( range ) return 1.0; } @@ -6664,9 +6729,9 @@ double QCPAxisTickerText::getTickStep(const QCPRange &range) \seebaseclassmethod */ -int QCPAxisTickerText::getSubTickCount(double tickStep) +int QCPAxisTickerText::getSubTickCount( double tickStep ) { - Q_UNUSED(tickStep) + Q_UNUSED( tickStep ) return mSubTickCount; } @@ -6676,12 +6741,12 @@ int QCPAxisTickerText::getSubTickCount(double tickStep) \seebaseclassmethod */ -QString QCPAxisTickerText::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +QString QCPAxisTickerText::getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) { - Q_UNUSED(locale) - Q_UNUSED(formatChar) - Q_UNUSED(precision) - return mTicks.value(tick); + Q_UNUSED( locale ) + Q_UNUSED( formatChar ) + Q_UNUSED( precision ) + return mTicks.value( tick ); } /*! @@ -6691,26 +6756,27 @@ QString QCPAxisTickerText::getTickLabel(double tick, const QLocale &locale, QCha \seebaseclassmethod */ -QVector QCPAxisTickerText::createTickVector(double tickStep, const QCPRange &range) +QVector QCPAxisTickerText::createTickVector( double tickStep, const QCPRange& range ) { - Q_UNUSED(tickStep) + Q_UNUSED( tickStep ) QVector result; - if (mTicks.isEmpty()) + if( mTicks.isEmpty() ) return result; - - QMap::const_iterator start = mTicks.lowerBound(range.lower); - QMap::const_iterator end = mTicks.upperBound(range.upper); + + QMap::const_iterator start = mTicks.lowerBound( range.lower ); + QMap::const_iterator end = mTicks.upperBound( range.upper ); // this method should try to give one tick outside of range so proper subticks can be generated: - if (start != mTicks.constBegin()) --start; - if (end != mTicks.constEnd()) ++end; - for (QMap::const_iterator it = start; it != end; ++it) - result.append(it.key()); - + if( start != mTicks.constBegin() ) + --start; + if( end != mTicks.constEnd() ) + ++end; + for( QMap::const_iterator it = start; it != end; ++it ) + result.append( it.key() ); + return result; } /* end of 'src/axis/axistickertext.cpp' */ - /* including file 'src/axis/axistickerpi.cpp', size 11170 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6737,14 +6803,10 @@ QVector QCPAxisTickerText::createTickVector(double tickStep, const QCPRa Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerPi::QCPAxisTickerPi() : - mPiSymbol(QLatin1String(" ")+QChar(0x03C0)), - mPiValue(M_PI), - mPeriodicity(0), - mFractionStyle(fsUnicodeFractions), - mPiTickStep(0) +QCPAxisTickerPi::QCPAxisTickerPi() + : mPiSymbol( QLatin1String( " " ) + QChar( 0x03C0 ) ), mPiValue( M_PI ), mPeriodicity( 0 ), mFractionStyle( fsUnicodeFractions ), mPiTickStep( 0 ) { - setTickCount(4); + setTickCount( 4 ); } /*! @@ -6754,7 +6816,7 @@ QCPAxisTickerPi::QCPAxisTickerPi() : If a space shall appear between the number and the symbol, make sure the space is contained in \a symbol. */ -void QCPAxisTickerPi::setPiSymbol(QString symbol) +void QCPAxisTickerPi::setPiSymbol( QString symbol ) { mPiSymbol = symbol; } @@ -6765,7 +6827,7 @@ void QCPAxisTickerPi::setPiSymbol(QString symbol) This will be used to place the appropriate fractions of the symbol at the respective axis coordinates. */ -void QCPAxisTickerPi::setPiValue(double pi) +void QCPAxisTickerPi::setPiValue( double pi ) { mPiValue = pi; } @@ -6778,16 +6840,16 @@ void QCPAxisTickerPi::setPiValue(double pi) For example, an axis that identifies 0 with 2pi would set \a multiplesOfPi to two. */ -void QCPAxisTickerPi::setPeriodicity(int multiplesOfPi) +void QCPAxisTickerPi::setPeriodicity( int multiplesOfPi ) { - mPeriodicity = qAbs(multiplesOfPi); + mPeriodicity = qAbs( multiplesOfPi ); } /*! Sets how the numerical/fractional part preceding the symbolic constant is displayed in tick labels. See \ref FractionStyle for the various options. */ -void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) +void QCPAxisTickerPi::setFractionStyle( QCPAxisTickerPi::FractionStyle style ) { mFractionStyle = style; } @@ -6800,11 +6862,11 @@ void QCPAxisTickerPi::setFractionStyle(QCPAxisTickerPi::FractionStyle style) \seebaseclassmethod */ -double QCPAxisTickerPi::getTickStep(const QCPRange &range) +double QCPAxisTickerPi::getTickStep( const QCPRange& range ) { - mPiTickStep = range.size()/mPiValue/(double)(mTickCount+1e-10); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers - mPiTickStep = cleanMantissa(mPiTickStep); - return mPiTickStep*mPiValue; + mPiTickStep = range.size() / mPiValue / (double)( mTickCount + 1e-10 ); // mTickCount ticks on average, the small addition is to prevent jitter on exact integers + mPiTickStep = cleanMantissa( mPiTickStep ); + return mPiTickStep * mPiValue; } /*! \internal @@ -6815,9 +6877,9 @@ double QCPAxisTickerPi::getTickStep(const QCPRange &range) \seebaseclassmethod */ -int QCPAxisTickerPi::getSubTickCount(double tickStep) +int QCPAxisTickerPi::getSubTickCount( double tickStep ) { - return QCPAxisTicker::getSubTickCount(tickStep/mPiValue); + return QCPAxisTicker::getSubTickCount( tickStep / mPiValue ); } /*! \internal @@ -6828,32 +6890,33 @@ int QCPAxisTickerPi::getSubTickCount(double tickStep) \seebaseclassmethod */ -QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) +QString QCPAxisTickerPi::getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) { - double tickInPis = tick/mPiValue; - if (mPeriodicity > 0) - tickInPis = fmod(tickInPis, mPeriodicity); - - if (mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50) + double tickInPis = tick / mPiValue; + if( mPeriodicity > 0 ) + tickInPis = fmod( tickInPis, mPeriodicity ); + + if( mFractionStyle != fsFloatingPoint && mPiTickStep > 0.09 && mPiTickStep < 50 ) { // simply construct fraction from decimal like 1.234 -> 1234/1000 and then simplify fraction, smaller digits are irrelevant due to mPiTickStep conditional above int denominator = 1000; - int numerator = qRound(tickInPis*denominator); - simplifyFraction(numerator, denominator); - if (qAbs(numerator) == 1 && denominator == 1) - return (numerator < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); - else if (numerator == 0) - return QLatin1String("0"); + int numerator = qRound( tickInPis * denominator ); + simplifyFraction( numerator, denominator ); + if( qAbs( numerator ) == 1 && denominator == 1 ) + return ( numerator < 0 ? QLatin1String( "-" ) : QLatin1String( "" ) ) + mPiSymbol.trimmed(); + else if( numerator == 0 ) + return QLatin1String( "0" ); else - return fractionToString(numerator, denominator) + mPiSymbol; - } else + return fractionToString( numerator, denominator ) + mPiSymbol; + } + else { - if (qFuzzyIsNull(tickInPis)) - return QLatin1String("0"); - else if (qFuzzyCompare(qAbs(tickInPis), 1.0)) - return (tickInPis < 0 ? QLatin1String("-") : QLatin1String("")) + mPiSymbol.trimmed(); + if( qFuzzyIsNull( tickInPis ) ) + return QLatin1String( "0" ); + else if( qFuzzyCompare( qAbs( tickInPis ), 1.0 ) ) + return ( tickInPis < 0 ? QLatin1String( "-" ) : QLatin1String( "" ) ) + mPiSymbol.trimmed(); else - return QCPAxisTicker::getTickLabel(tickInPis, locale, formatChar, precision) + mPiSymbol; + return QCPAxisTicker::getTickLabel( tickInPis, locale, formatChar, precision ) + mPiSymbol; } } @@ -6863,14 +6926,14 @@ QString QCPAxisTickerPi::getTickLabel(double tick, const QLocale &locale, QChar the fraction is in irreducible form, i.e. numerator and denominator don't share any common factors which could be cancelled. */ -void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const +void QCPAxisTickerPi::simplifyFraction( int& numerator, int& denominator ) const { - if (numerator == 0 || denominator == 0) + if( numerator == 0 || denominator == 0 ) return; - + int num = numerator; int denom = denominator; - while (denom != 0) // euclidean gcd algorithm + while( denom != 0 ) // euclidean gcd algorithm { int oldDenom = denom; denom = num % denom; @@ -6890,47 +6953,50 @@ void QCPAxisTickerPi::simplifyFraction(int &numerator, int &denominator) const simplifies the passed fraction to an irreducible form using \ref simplifyFraction and factors out any integer parts of the fraction (e.g. "10/4" becomes "2 1/2"). */ -QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const +QString QCPAxisTickerPi::fractionToString( int numerator, int denominator ) const { - if (denominator == 0) + if( denominator == 0 ) { qDebug() << Q_FUNC_INFO << "called with zero denominator"; return QString(); } - if (mFractionStyle == fsFloatingPoint) // should never be the case when calling this function + if( mFractionStyle == fsFloatingPoint ) // should never be the case when calling this function { qDebug() << Q_FUNC_INFO << "shouldn't be called with fraction style fsDecimal"; - return QString::number(numerator/(double)denominator); // failsafe + return QString::number( numerator / (double)denominator ); // failsafe } - int sign = numerator*denominator < 0 ? -1 : 1; - numerator = qAbs(numerator); - denominator = qAbs(denominator); - - if (denominator == 1) + int sign = numerator * denominator < 0 ? -1 : 1; + numerator = qAbs( numerator ); + denominator = qAbs( denominator ); + + if( denominator == 1 ) { - return QString::number(sign*numerator); - } else + return QString::number( sign * numerator ); + } + else { - int integerPart = numerator/denominator; - int remainder = numerator%denominator; - if (remainder == 0) + int integerPart = numerator / denominator; + int remainder = numerator % denominator; + if( remainder == 0 ) { - return QString::number(sign*integerPart); - } else + return QString::number( sign * integerPart ); + } + else { - if (mFractionStyle == fsAsciiFractions) + if( mFractionStyle == fsAsciiFractions ) { - return QString(QLatin1String("%1%2%3/%4")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart)+QLatin1String(" ") : QLatin1String("")) - .arg(remainder) - .arg(denominator); - } else if (mFractionStyle == fsUnicodeFractions) + return QString( QLatin1String( "%1%2%3/%4" ) ) + .arg( sign == -1 ? QLatin1String( "-" ) : QLatin1String( "" ) ) + .arg( integerPart > 0 ? QString::number( integerPart ) + QLatin1String( " " ) : QLatin1String( "" ) ) + .arg( remainder ) + .arg( denominator ); + } + else if( mFractionStyle == fsUnicodeFractions ) { - return QString(QLatin1String("%1%2%3")) - .arg(sign == -1 ? QLatin1String("-") : QLatin1String("")) - .arg(integerPart > 0 ? QString::number(integerPart) : QLatin1String("")) - .arg(unicodeFraction(remainder, denominator)); + return QString( QLatin1String( "%1%2%3" ) ) + .arg( sign == -1 ? QLatin1String( "-" ) : QLatin1String( "" ) ) + .arg( integerPart > 0 ? QString::number( integerPart ) : QLatin1String( "" ) ) + .arg( unicodeFraction( remainder, denominator ) ); } } } @@ -6946,9 +7012,9 @@ QString QCPAxisTickerPi::fractionToString(int numerator, int denominator) const This method doesn't use the single-character common fractions but builds each fraction from a superscript unicode number, the unicode fraction character, and a subscript unicode number. */ -QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const +QString QCPAxisTickerPi::unicodeFraction( int numerator, int denominator ) const { - return unicodeSuperscript(numerator)+QChar(0x2044)+unicodeSubscript(denominator); + return unicodeSuperscript( numerator ) + QChar( 0x2044 ) + unicodeSubscript( denominator ); } /*! \internal @@ -6956,21 +7022,33 @@ QString QCPAxisTickerPi::unicodeFraction(int numerator, int denominator) const Returns the unicode string representing \a number as superscript. This is used to build unicode fractions in \ref unicodeFraction. */ -QString QCPAxisTickerPi::unicodeSuperscript(int number) const +QString QCPAxisTickerPi::unicodeSuperscript( int number ) const { - if (number == 0) - return QString(QChar(0x2070)); - + if( number == 0 ) + return QString( QChar( 0x2070 ) ); + QString result; - while (number > 0) + while( number > 0 ) { - const int digit = number%10; - switch (digit) + const int digit = number % 10; + switch( digit ) { - case 1: { result.prepend(QChar(0x00B9)); break; } - case 2: { result.prepend(QChar(0x00B2)); break; } - case 3: { result.prepend(QChar(0x00B3)); break; } - default: { result.prepend(QChar(0x2070+digit)); break; } + case 1: { + result.prepend( QChar( 0x00B9 ) ); + break; + } + case 2: { + result.prepend( QChar( 0x00B2 ) ); + break; + } + case 3: { + result.prepend( QChar( 0x00B3 ) ); + break; + } + default: { + result.prepend( QChar( 0x2070 + digit ) ); + break; + } } number /= 10; } @@ -6982,22 +7060,21 @@ QString QCPAxisTickerPi::unicodeSuperscript(int number) const Returns the unicode string representing \a number as subscript. This is used to build unicode fractions in \ref unicodeFraction. */ -QString QCPAxisTickerPi::unicodeSubscript(int number) const +QString QCPAxisTickerPi::unicodeSubscript( int number ) const { - if (number == 0) - return QString(QChar(0x2080)); - + if( number == 0 ) + return QString( QChar( 0x2080 ) ); + QString result; - while (number > 0) + while( number > 0 ) { - result.prepend(QChar(0x2080+number%10)); + result.prepend( QChar( 0x2080 + number % 10 ) ); number /= 10; } return result; } /* end of 'src/axis/axistickerpi.cpp' */ - /* including file 'src/axis/axistickerlog.cpp', size 7106 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -7028,10 +7105,9 @@ QString QCPAxisTickerPi::unicodeSubscript(int number) const Constructs the ticker and sets reasonable default values. Axis tickers are commonly created managed by a QSharedPointer, which then can be passed to QCPAxis::setTicker. */ -QCPAxisTickerLog::QCPAxisTickerLog() : - mLogBase(10.0), - mSubTickCount(8), // generates 10 intervals - mLogBaseLnInv(1.0/qLn(mLogBase)) +QCPAxisTickerLog::QCPAxisTickerLog() + : mLogBase( 10.0 ), mSubTickCount( 8 ), // generates 10 intervals + mLogBaseLnInv( 1.0 / qLn( mLogBase ) ) { } @@ -7039,13 +7115,14 @@ QCPAxisTickerLog::QCPAxisTickerLog() : Sets the logarithm base used for tick coordinate generation. The ticks will be placed at integer powers of \a base. */ -void QCPAxisTickerLog::setLogBase(double base) +void QCPAxisTickerLog::setLogBase( double base ) { - if (base > 0) + if( base > 0 ) { mLogBase = base; - mLogBaseLnInv = 1.0/qLn(mLogBase); - } else + mLogBaseLnInv = 1.0 / qLn( mLogBase ); + } + else qDebug() << Q_FUNC_INFO << "log base has to be greater than zero:" << base; } @@ -7059,9 +7136,9 @@ void QCPAxisTickerLog::setLogBase(double base) ticks (the default). This means e.g. between the ticks 10 and 100 there will be eight ticks, namely at 20, 30, 40, 50, 60, 70, 80 and 90. */ -void QCPAxisTickerLog::setSubTickCount(int subTicks) +void QCPAxisTickerLog::setSubTickCount( int subTicks ) { - if (subTicks >= 0) + if( subTicks >= 0 ) mSubTickCount = subTicks; else qDebug() << Q_FUNC_INFO << "sub tick count can't be negative:" << subTicks; @@ -7074,10 +7151,10 @@ void QCPAxisTickerLog::setSubTickCount(int subTicks) \seebaseclassmethod */ -double QCPAxisTickerLog::getTickStep(const QCPRange &range) +double QCPAxisTickerLog::getTickStep( const QCPRange& range ) { // Logarithmic axis ticker has unequal tick spacing, so doesn't need this method - Q_UNUSED(range) + Q_UNUSED( range ) return 1.0; } @@ -7088,9 +7165,9 @@ double QCPAxisTickerLog::getTickStep(const QCPRange &range) \seebaseclassmethod */ -int QCPAxisTickerLog::getSubTickCount(double tickStep) +int QCPAxisTickerLog::getSubTickCount( double tickStep ) { - Q_UNUSED(tickStep) + Q_UNUSED( tickStep ) return mSubTickCount; } @@ -7103,46 +7180,46 @@ int QCPAxisTickerLog::getSubTickCount(double tickStep) \seebaseclassmethod */ -QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) +QVector QCPAxisTickerLog::createTickVector( double tickStep, const QCPRange& range ) { - Q_UNUSED(tickStep) + Q_UNUSED( tickStep ) QVector result; - if (range.lower > 0 && range.upper > 0) // positive range + if( range.lower > 0 && range.upper > 0 ) // positive range { - double exactPowerStep = qLn(range.upper/range.lower)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = qPow(newLogBase, qFloor(qLn(range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick > 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + double exactPowerStep = qLn( range.upper / range.lower ) * mLogBaseLnInv / (double)( mTickCount + 1e-10 ); + double newLogBase = qPow( mLogBase, qMax( (int)cleanMantissa( exactPowerStep ), 1 ) ); + double currentTick = qPow( newLogBase, qFloor( qLn( range.lower ) / qLn( newLogBase ) ) ); + result.append( currentTick ); + while( currentTick < range.upper && currentTick > 0 ) // currentMag might be zero for ranges ~1e-300, just cancel in that case { currentTick *= newLogBase; - result.append(currentTick); + result.append( currentTick ); } - } else if (range.lower < 0 && range.upper < 0) // negative range + } + else if( range.lower < 0 && range.upper < 0 ) // negative range { - double exactPowerStep = qLn(range.lower/range.upper)*mLogBaseLnInv/(double)(mTickCount+1e-10); - double newLogBase = qPow(mLogBase, qMax((int)cleanMantissa(exactPowerStep), 1)); - double currentTick = -qPow(newLogBase, qCeil(qLn(-range.lower)/qLn(newLogBase))); - result.append(currentTick); - while (currentTick < range.upper && currentTick < 0) // currentMag might be zero for ranges ~1e-300, just cancel in that case + double exactPowerStep = qLn( range.lower / range.upper ) * mLogBaseLnInv / (double)( mTickCount + 1e-10 ); + double newLogBase = qPow( mLogBase, qMax( (int)cleanMantissa( exactPowerStep ), 1 ) ); + double currentTick = -qPow( newLogBase, qCeil( qLn( -range.lower ) / qLn( newLogBase ) ) ); + result.append( currentTick ); + while( currentTick < range.upper && currentTick < 0 ) // currentMag might be zero for ranges ~1e-300, just cancel in that case { currentTick /= newLogBase; - result.append(currentTick); + result.append( currentTick ); } - } else // invalid range for logarithmic scale, because lower and upper have different sign + } + else // invalid range for logarithmic scale, because lower and upper have different sign { qDebug() << Q_FUNC_INFO << "Invalid range for logarithmic plot: " << range.lower << ".." << range.upper; } - + return result; } /* end of 'src/axis/axistickerlog.cpp' */ - /* including file 'src/axis/axis.cpp', size 99515 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPGrid //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -7165,19 +7242,18 @@ QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRan You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. */ -QCPGrid::QCPGrid(QCPAxis *parentAxis) : - QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), - mParentAxis(parentAxis) +QCPGrid::QCPGrid( QCPAxis* parentAxis ) + : QCPLayerable( parentAxis->parentPlot(), QString(), parentAxis ), mParentAxis( parentAxis ) { // warning: this is called in QCPAxis constructor, so parentAxis members should not be accessed/called - setParent(parentAxis); - setPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); - setSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); - setZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); - setSubGridVisible(false); - setAntialiased(false); - setAntialiasedSubGrid(false); - setAntialiasedZeroLine(false); + setParent( parentAxis ); + setPen( QPen( QColor( 200, 200, 200 ), 0, Qt::DotLine ) ); + setSubGridPen( QPen( QColor( 220, 220, 220 ), 0, Qt::DotLine ) ); + setZeroLinePen( QPen( QColor( 200, 200, 200 ), 0, Qt::SolidLine ) ); + setSubGridVisible( false ); + setAntialiased( false ); + setAntialiasedSubGrid( false ); + setAntialiasedZeroLine( false ); } /*! @@ -7185,7 +7261,7 @@ QCPGrid::QCPGrid(QCPAxis *parentAxis) : \see setSubGridPen */ -void QCPGrid::setSubGridVisible(bool visible) +void QCPGrid::setSubGridVisible( bool visible ) { mSubGridVisible = visible; } @@ -7193,7 +7269,7 @@ void QCPGrid::setSubGridVisible(bool visible) /*! Sets whether sub grid lines are drawn antialiased. */ -void QCPGrid::setAntialiasedSubGrid(bool enabled) +void QCPGrid::setAntialiasedSubGrid( bool enabled ) { mAntialiasedSubGrid = enabled; } @@ -7201,7 +7277,7 @@ void QCPGrid::setAntialiasedSubGrid(bool enabled) /*! Sets whether zero lines are drawn antialiased. */ -void QCPGrid::setAntialiasedZeroLine(bool enabled) +void QCPGrid::setAntialiasedZeroLine( bool enabled ) { mAntialiasedZeroLine = enabled; } @@ -7209,7 +7285,7 @@ void QCPGrid::setAntialiasedZeroLine(bool enabled) /*! Sets the pen with which (major) grid lines are drawn. */ -void QCPGrid::setPen(const QPen &pen) +void QCPGrid::setPen( const QPen& pen ) { mPen = pen; } @@ -7217,7 +7293,7 @@ void QCPGrid::setPen(const QPen &pen) /*! Sets the pen with which sub grid lines are drawn. */ -void QCPGrid::setSubGridPen(const QPen &pen) +void QCPGrid::setSubGridPen( const QPen& pen ) { mSubGridPen = pen; } @@ -7228,7 +7304,7 @@ void QCPGrid::setSubGridPen(const QPen &pen) Zero lines are lines at value coordinate 0 which may be drawn with a different pen than other grid lines. To disable zero lines and just draw normal grid lines at zero, set \a pen to Qt::NoPen. */ -void QCPGrid::setZeroLinePen(const QPen &pen) +void QCPGrid::setZeroLinePen( const QPen& pen ) { mZeroLinePen = pen; } @@ -7246,9 +7322,9 @@ void QCPGrid::setZeroLinePen(const QPen &pen) \see setAntialiased */ -void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPGrid::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); + applyAntialiasingHint( painter, mAntialiased, QCP::aeGrid ); } /*! \internal @@ -7256,13 +7332,17 @@ void QCPGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const Draws grid lines and sub grid lines at the positions of (sub) ticks of the parent axis, spanning over the complete axis rect. Also draws the zero line, if appropriate (\ref setZeroLinePen). */ -void QCPGrid::draw(QCPPainter *painter) +void QCPGrid::draw( QCPPainter* painter ) { - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - if (mParentAxis->subTicks() && mSubGridVisible) - drawSubGridLines(painter); - drawGridLines(painter); + if( !mParentAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid parent axis"; + return; + } + + if( mParentAxis->subTicks() && mSubGridVisible ) + drawSubGridLines( painter ); + drawGridLines( painter ); } /*! \internal @@ -7271,69 +7351,76 @@ void QCPGrid::draw(QCPPainter *painter) This is a helper function called by \ref draw. */ -void QCPGrid::drawGridLines(QCPPainter *painter) const +void QCPGrid::drawGridLines( QCPPainter* painter ) const { - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - + if( !mParentAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid parent axis"; + return; + } + const int tickCount = mParentAxis->mTickVector.size(); - double t; // helper variable, result of coordinate-to-pixel transforms - if (mParentAxis->orientation() == Qt::Horizontal) + double t; // helper variable, result of coordinate-to-pixel transforms + if( mParentAxis->orientation() == Qt::Horizontal ) { // draw zeroline: int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + if( mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0 ) { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero - for (int i=0; isetPen( mZeroLinePen ); + double epsilon = mParentAxis->range().size() * 1E-6; // for comparing double to zero + for( int i = 0; i < tickCount; ++i ) { - if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) + if( qAbs( mParentAxis->mTickVector.at( i ) ) < epsilon ) { zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + t = mParentAxis->coordToPixel( mParentAxis->mTickVector.at( i ) ); // x + painter->drawLine( QLineF( t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top() ) ); break; } } } // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; isetPen( mPen ); + for( int i = 0; i < tickCount; ++i ) { - if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + if( i == zeroLineIndex ) + continue; // don't draw a gridline on top of the zeroline + t = mParentAxis->coordToPixel( mParentAxis->mTickVector.at( i ) ); // x + painter->drawLine( QLineF( t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top() ) ); } - } else + } + else { // draw zeroline: int zeroLineIndex = -1; - if (mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0) + if( mZeroLinePen.style() != Qt::NoPen && mParentAxis->mRange.lower < 0 && mParentAxis->mRange.upper > 0 ) { - applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); - painter->setPen(mZeroLinePen); - double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero - for (int i=0; isetPen( mZeroLinePen ); + double epsilon = mParentAxis->mRange.size() * 1E-6; // for comparing double to zero + for( int i = 0; i < tickCount; ++i ) { - if (qAbs(mParentAxis->mTickVector.at(i)) < epsilon) + if( qAbs( mParentAxis->mTickVector.at( i ) ) < epsilon ) { zeroLineIndex = i; - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + t = mParentAxis->coordToPixel( mParentAxis->mTickVector.at( i ) ); // y + painter->drawLine( QLineF( mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t ) ); break; } } } // draw grid lines: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - for (int i=0; isetPen( mPen ); + for( int i = 0; i < tickCount; ++i ) { - if (i == zeroLineIndex) continue; // don't draw a gridline on top of the zeroline - t = mParentAxis->coordToPixel(mParentAxis->mTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + if( i == zeroLineIndex ) + continue; // don't draw a gridline on top of the zeroline + t = mParentAxis->coordToPixel( mParentAxis->mTickVector.at( i ) ); // y + painter->drawLine( QLineF( mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t ) ); } } } @@ -7344,31 +7431,35 @@ void QCPGrid::drawGridLines(QCPPainter *painter) const This is a helper function called by \ref draw. */ -void QCPGrid::drawSubGridLines(QCPPainter *painter) const +void QCPGrid::drawSubGridLines( QCPPainter* painter ) const { - if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } - - applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeSubGrid); - double t; // helper variable, result of coordinate-to-pixel transforms - painter->setPen(mSubGridPen); - if (mParentAxis->orientation() == Qt::Horizontal) + if( !mParentAxis ) { - for (int i=0; imSubTickVector.size(); ++i) + qDebug() << Q_FUNC_INFO << "invalid parent axis"; + return; + } + + applyAntialiasingHint( painter, mAntialiasedSubGrid, QCP::aeSubGrid ); + double t; // helper variable, result of coordinate-to-pixel transforms + painter->setPen( mSubGridPen ); + if( mParentAxis->orientation() == Qt::Horizontal ) + { + for( int i = 0; i < mParentAxis->mSubTickVector.size(); ++i ) { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // x - painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); + t = mParentAxis->coordToPixel( mParentAxis->mSubTickVector.at( i ) ); // x + painter->drawLine( QLineF( t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top() ) ); } - } else + } + else { - for (int i=0; imSubTickVector.size(); ++i) + for( int i = 0; i < mParentAxis->mSubTickVector.size(); ++i ) { - t = mParentAxis->coordToPixel(mParentAxis->mSubTickVector.at(i)); // y - painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); + t = mParentAxis->coordToPixel( mParentAxis->mSubTickVector.at( i ) ); // y + painter->drawLine( QLineF( mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t ) ); } } } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxis //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -7503,78 +7594,86 @@ void QCPGrid::drawSubGridLines(QCPPainter *painter) const them for you with \ref QCPAxisRect::addAxis. If you want to use own QCPAxis-subclasses however, create them manually and then inject them also via \ref QCPAxisRect::addAxis. */ -QCPAxis::QCPAxis(QCPAxisRect *parent, AxisType type) : - QCPLayerable(parent->parentPlot(), QString(), parent), - // axis base: - mAxisType(type), - mAxisRect(parent), - mPadding(5), - mOrientation(orientation(type)), - mSelectableParts(spAxis | spTickLabels | spAxisLabel), - mSelectedParts(spNone), - mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedBasePen(QPen(Qt::blue, 2)), - // axis label: - mLabel(), - mLabelFont(mParentPlot->font()), - mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), - mLabelColor(Qt::black), - mSelectedLabelColor(Qt::blue), - // tick labels: - mTickLabels(true), - mTickLabelFont(mParentPlot->font()), - mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), - mTickLabelColor(Qt::black), - mSelectedTickLabelColor(Qt::blue), - mNumberPrecision(6), - mNumberFormatChar('g'), - mNumberBeautifulPowers(true), - // ticks and subticks: - mTicks(true), - mSubTicks(true), - mTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedTickPen(QPen(Qt::blue, 2)), - mSubTickPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), - mSelectedSubTickPen(QPen(Qt::blue, 2)), - // scale and range: - mRange(0, 5), - mRangeReversed(false), - mScaleType(stLinear), - // internal members: - mGrid(new QCPGrid(this)), - mAxisPainter(new QCPAxisPainterPrivate(parent->parentPlot())), - mTicker(new QCPAxisTicker), - mCachedMarginValid(false), - mCachedMargin(0) +QCPAxis::QCPAxis( QCPAxisRect* parent, AxisType type ) + : QCPLayerable( parent->parentPlot(), QString(), parent ), + // axis base: + mAxisType( type ) + , mAxisRect( parent ) + , mPadding( 5 ) + , mOrientation( orientation( type ) ) + , mSelectableParts( spAxis | spTickLabels | spAxisLabel ) + , mSelectedParts( spNone ) + , mBasePen( QPen( Qt::black, 0, Qt::SolidLine, Qt::SquareCap ) ) + , mSelectedBasePen( QPen( Qt::blue, 2 ) ) + , + // axis label: + mLabel() + , mLabelFont( mParentPlot->font() ) + , mSelectedLabelFont( QFont( mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold ) ) + , mLabelColor( Qt::black ) + , mSelectedLabelColor( Qt::blue ) + , + // tick labels: + mTickLabels( true ) + , mTickLabelFont( mParentPlot->font() ) + , mSelectedTickLabelFont( QFont( mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold ) ) + , mTickLabelColor( Qt::black ) + , mSelectedTickLabelColor( Qt::blue ) + , mNumberPrecision( 6 ) + , mNumberFormatChar( 'g' ) + , mNumberBeautifulPowers( true ) + , + // ticks and subticks: + mTicks( true ) + , mSubTicks( true ) + , mTickPen( QPen( Qt::black, 0, Qt::SolidLine, Qt::SquareCap ) ) + , mSelectedTickPen( QPen( Qt::blue, 2 ) ) + , mSubTickPen( QPen( Qt::black, 0, Qt::SolidLine, Qt::SquareCap ) ) + , mSelectedSubTickPen( QPen( Qt::blue, 2 ) ) + , + // scale and range: + mRange( 0, 5 ) + , mRangeReversed( false ) + , mScaleType( stLinear ) + , + // internal members: + mGrid( new QCPGrid( this ) ) + , mAxisPainter( new QCPAxisPainterPrivate( parent->parentPlot() ) ) + , mTicker( new QCPAxisTicker ) + , mCachedMarginValid( false ) + , mCachedMargin( 0 ) { - setParent(parent); - mGrid->setVisible(false); - setAntialiased(false); - setLayer(mParentPlot->currentLayer()); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again - - if (type == atTop) + setParent( parent ); + mGrid->setVisible( false ); + setAntialiased( false ); + setLayer( mParentPlot->currentLayer() ); // it's actually on that layer already, but we want it in front of the grid, so we place it on there again + + if( type == atTop ) { - setTickLabelPadding(3); - setLabelPadding(6); - } else if (type == atRight) + setTickLabelPadding( 3 ); + setLabelPadding( 6 ); + } + else if( type == atRight ) { - setTickLabelPadding(7); - setLabelPadding(12); - } else if (type == atBottom) + setTickLabelPadding( 7 ); + setLabelPadding( 12 ); + } + else if( type == atBottom ) { - setTickLabelPadding(3); - setLabelPadding(3); - } else if (type == atLeft) + setTickLabelPadding( 3 ); + setLabelPadding( 3 ); + } + else if( type == atLeft ) { - setTickLabelPadding(5); - setLabelPadding(10); + setTickLabelPadding( 5 ); + setLabelPadding( 10 ); } } QCPAxis::~QCPAxis() { delete mAxisPainter; - delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order + delete mGrid; // delete grid here instead of via parent ~QObject for better defined deletion order } /* No documentation as it is a property getter */ @@ -7599,12 +7698,12 @@ QCPAxis::LabelSide QCPAxis::tickLabelSide() const QString QCPAxis::numberFormat() const { QString result; - result.append(mNumberFormatChar); - if (mNumberBeautifulPowers) + result.append( mNumberFormatChar ); + if( mNumberBeautifulPowers ) { - result.append(QLatin1Char('b')); - if (mAxisPainter->numberMultiplyCross) - result.append(QLatin1Char('c')); + result.append( QLatin1Char( 'b' ) ); + if( mAxisPainter->numberMultiplyCross ) + result.append( QLatin1Char( 'c' ) ); } return result; } @@ -7671,15 +7770,15 @@ QCPLineEnding QCPAxis::upperEnding() const \ref setNumberPrecision */ -void QCPAxis::setScaleType(QCPAxis::ScaleType type) +void QCPAxis::setScaleType( QCPAxis::ScaleType type ) { - if (mScaleType != type) + if( mScaleType != type ) { mScaleType = type; - if (mScaleType == stLogarithmic) - setRange(mRange.sanitizedForLogScale()); + if( mScaleType == stLogarithmic ) + setRange( mRange.sanitizedForLogScale() ); mCachedMarginValid = false; - emit scaleTypeChanged(mScaleType); + emit scaleTypeChanged( mScaleType ); } } @@ -7691,22 +7790,24 @@ void QCPAxis::setScaleType(QCPAxis::ScaleType type) To invert the direction of an axis, use \ref setRangeReversed. */ -void QCPAxis::setRange(const QCPRange &range) +void QCPAxis::setRange( const QCPRange& range ) { - if (range.lower == mRange.lower && range.upper == mRange.upper) + if( range.lower == mRange.lower && range.upper == mRange.upper ) + return; + + if( !QCPRange::validRange( range ) ) return; - - if (!QCPRange::validRange(range)) return; QCPRange oldRange = mRange; - if (mScaleType == stLogarithmic) + if( mScaleType == stLogarithmic ) { mRange = range.sanitizedForLogScale(); - } else + } + else { mRange = range.sanitizedForLinScale(); } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! @@ -7719,12 +7820,12 @@ void QCPAxis::setRange(const QCPRange &range) \see SelectablePart, setSelectedParts */ -void QCPAxis::setSelectableParts(const SelectableParts &selectable) +void QCPAxis::setSelectableParts( const SelectableParts& selectable ) { - if (mSelectableParts != selectable) + if( mSelectableParts != selectable ) { mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); + emit selectableChanged( mSelectableParts ); } } @@ -7743,12 +7844,12 @@ void QCPAxis::setSelectableParts(const SelectableParts &selectable) \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor */ -void QCPAxis::setSelectedParts(const SelectableParts &selected) +void QCPAxis::setSelectedParts( const SelectableParts& selected ) { - if (mSelectedParts != selected) + if( mSelectedParts != selected ) { mSelectedParts = selected; - emit selectionChanged(mSelectedParts); + emit selectionChanged( mSelectedParts ); } } @@ -7761,24 +7862,26 @@ void QCPAxis::setSelectedParts(const SelectableParts &selected) There is also a slot to set a range, see \ref setRange(const QCPRange &range). */ -void QCPAxis::setRange(double lower, double upper) +void QCPAxis::setRange( double lower, double upper ) { - if (lower == mRange.lower && upper == mRange.upper) + if( lower == mRange.lower && upper == mRange.upper ) + return; + + if( !QCPRange::validRange( lower, upper ) ) return; - - if (!QCPRange::validRange(lower, upper)) return; QCPRange oldRange = mRange; mRange.lower = lower; mRange.upper = upper; - if (mScaleType == stLogarithmic) + if( mScaleType == stLogarithmic ) { mRange = mRange.sanitizedForLogScale(); - } else + } + else { mRange = mRange.sanitizedForLinScale(); } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! @@ -7792,58 +7895,60 @@ void QCPAxis::setRange(double lower, double upper) or center of the range to be aligned with \a position. Any other values of \a alignment will default to Qt::AlignCenter. */ -void QCPAxis::setRange(double position, double size, Qt::AlignmentFlag alignment) +void QCPAxis::setRange( double position, double size, Qt::AlignmentFlag alignment ) { - if (alignment == Qt::AlignLeft) - setRange(position, position+size); - else if (alignment == Qt::AlignRight) - setRange(position-size, position); - else // alignment == Qt::AlignCenter - setRange(position-size/2.0, position+size/2.0); + if( alignment == Qt::AlignLeft ) + setRange( position, position + size ); + else if( alignment == Qt::AlignRight ) + setRange( position - size, position ); + else // alignment == Qt::AlignCenter + setRange( position - size / 2.0, position + size / 2.0 ); } /*! Sets the lower bound of the axis range. The upper bound is not changed. \see setRange */ -void QCPAxis::setRangeLower(double lower) +void QCPAxis::setRangeLower( double lower ) { - if (mRange.lower == lower) + if( mRange.lower == lower ) return; - + QCPRange oldRange = mRange; mRange.lower = lower; - if (mScaleType == stLogarithmic) + if( mScaleType == stLogarithmic ) { mRange = mRange.sanitizedForLogScale(); - } else + } + else { mRange = mRange.sanitizedForLinScale(); } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! Sets the upper bound of the axis range. The lower bound is not changed. \see setRange */ -void QCPAxis::setRangeUpper(double upper) +void QCPAxis::setRangeUpper( double upper ) { - if (mRange.upper == upper) + if( mRange.upper == upper ) return; - + QCPRange oldRange = mRange; mRange.upper = upper; - if (mScaleType == stLogarithmic) + if( mScaleType == stLogarithmic ) { mRange = mRange.sanitizedForLogScale(); - } else + } + else { mRange = mRange.sanitizedForLinScale(); } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! @@ -7855,7 +7960,7 @@ void QCPAxis::setRangeUpper(double upper) of the \ref setRange interface will still reference the mathematically smaller number than the \a upper part. */ -void QCPAxis::setRangeReversed(bool reversed) +void QCPAxis::setRangeReversed( bool reversed ) { mRangeReversed = reversed; } @@ -7873,9 +7978,9 @@ void QCPAxis::setRangeReversed(bool reversed) \see ticker */ -void QCPAxis::setTicker(QSharedPointer ticker) +void QCPAxis::setTicker( QSharedPointer ticker ) { - if (ticker) + if( ticker ) mTicker = ticker; else qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; @@ -7890,9 +7995,9 @@ void QCPAxis::setTicker(QSharedPointer ticker) \see setSubTicks */ -void QCPAxis::setTicks(bool show) +void QCPAxis::setTicks( bool show ) { - if (mTicks != show) + if( mTicks != show ) { mTicks = show; mCachedMarginValid = false; @@ -7902,13 +8007,13 @@ void QCPAxis::setTicks(bool show) /*! Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. */ -void QCPAxis::setTickLabels(bool show) +void QCPAxis::setTickLabels( bool show ) { - if (mTickLabels != show) + if( mTickLabels != show ) { mTickLabels = show; mCachedMarginValid = false; - if (!mTickLabels) + if( !mTickLabels ) mTickVectorLabels.clear(); } } @@ -7917,9 +8022,9 @@ void QCPAxis::setTickLabels(bool show) Sets the distance between the axis base line (including any outward ticks) and the tick labels. \see setLabelPadding, setPadding */ -void QCPAxis::setTickLabelPadding(int padding) +void QCPAxis::setTickLabelPadding( int padding ) { - if (mAxisPainter->tickLabelPadding != padding) + if( mAxisPainter->tickLabelPadding != padding ) { mAxisPainter->tickLabelPadding = padding; mCachedMarginValid = false; @@ -7931,9 +8036,9 @@ void QCPAxis::setTickLabelPadding(int padding) \see setTickLabels, setTickLabelColor */ -void QCPAxis::setTickLabelFont(const QFont &font) +void QCPAxis::setTickLabelFont( const QFont& font ) { - if (font != mTickLabelFont) + if( font != mTickLabelFont ) { mTickLabelFont = font; mCachedMarginValid = false; @@ -7945,7 +8050,7 @@ void QCPAxis::setTickLabelFont(const QFont &font) \see setTickLabels, setTickLabelFont */ -void QCPAxis::setTickLabelColor(const QColor &color) +void QCPAxis::setTickLabelColor( const QColor& color ) { mTickLabelColor = color; } @@ -7959,11 +8064,11 @@ void QCPAxis::setTickLabelColor(const QColor &color) other angles, the label is drawn with an offset such that it seems to point toward or away from the tick mark. */ -void QCPAxis::setTickLabelRotation(double degrees) +void QCPAxis::setTickLabelRotation( double degrees ) { - if (!qFuzzyIsNull(degrees-mAxisPainter->tickLabelRotation)) + if( !qFuzzyIsNull( degrees - mAxisPainter->tickLabelRotation ) ) { - mAxisPainter->tickLabelRotation = qBound(-90.0, degrees, 90.0); + mAxisPainter->tickLabelRotation = qBound( -90.0, degrees, 90.0 ); mCachedMarginValid = false; } } @@ -7975,7 +8080,7 @@ void QCPAxis::setTickLabelRotation(double degrees) to be inside the axis rect, to save space. If \a side is set to \ref lsInside, the tick labels appear on the inside are additionally clipped to the axis rect. */ -void QCPAxis::setTickLabelSide(LabelSide side) +void QCPAxis::setTickLabelSide( LabelSide side ) { mAxisPainter->tickLabelSide = side; mCachedMarginValid = false; @@ -8011,55 +8116,59 @@ void QCPAxis::setTickLabelSide(LabelSide side) \li \c hello illegal format code, since first char is not 'e', 'E', 'f', 'g' or 'G'. Current format code will not be changed. */ -void QCPAxis::setNumberFormat(const QString &formatCode) +void QCPAxis::setNumberFormat( const QString& formatCode ) { - if (formatCode.isEmpty()) + if( formatCode.isEmpty() ) { qDebug() << Q_FUNC_INFO << "Passed formatCode is empty"; return; } mCachedMarginValid = false; - + // interpret first char as number format char: - QString allowedFormatChars(QLatin1String("eEfgG")); - if (allowedFormatChars.contains(formatCode.at(0))) + QString allowedFormatChars( QLatin1String( "eEfgG" ) ); + if( allowedFormatChars.contains( formatCode.at( 0 ) ) ) { - mNumberFormatChar = QLatin1Char(formatCode.at(0).toLatin1()); - } else + mNumberFormatChar = QLatin1Char( formatCode.at( 0 ).toLatin1() ); + } + else { qDebug() << Q_FUNC_INFO << "Invalid number format code (first char not in 'eEfgG'):" << formatCode; return; } - if (formatCode.length() < 2) + if( formatCode.length() < 2 ) { mNumberBeautifulPowers = false; mAxisPainter->numberMultiplyCross = false; return; } - + // interpret second char as indicator for beautiful decimal powers: - if (formatCode.at(1) == QLatin1Char('b') && (mNumberFormatChar == QLatin1Char('e') || mNumberFormatChar == QLatin1Char('g'))) + if( formatCode.at( 1 ) == QLatin1Char( 'b' ) && ( mNumberFormatChar == QLatin1Char( 'e' ) || mNumberFormatChar == QLatin1Char( 'g' ) ) ) { mNumberBeautifulPowers = true; - } else + } + else { qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; return; } - if (formatCode.length() < 3) + if( formatCode.length() < 3 ) { mAxisPainter->numberMultiplyCross = false; return; } - + // interpret third char as indicator for dot or cross multiplication symbol: - if (formatCode.at(2) == QLatin1Char('c')) + if( formatCode.at( 2 ) == QLatin1Char( 'c' ) ) { mAxisPainter->numberMultiplyCross = true; - } else if (formatCode.at(2) == QLatin1Char('d')) + } + else if( formatCode.at( 2 ) == QLatin1Char( 'd' ) ) { mAxisPainter->numberMultiplyCross = false; - } else + } + else { qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; return; @@ -8071,9 +8180,9 @@ void QCPAxis::setNumberFormat(const QString &formatCode) for details. The effect of precisions are most notably for number Formats starting with 'e', see \ref setNumberFormat */ -void QCPAxis::setNumberPrecision(int precision) +void QCPAxis::setNumberPrecision( int precision ) { - if (mNumberPrecision != precision) + if( mNumberPrecision != precision ) { mNumberPrecision = precision; mCachedMarginValid = false; @@ -8088,10 +8197,10 @@ void QCPAxis::setNumberPrecision(int precision) \see setSubTickLength, setTickLengthIn, setTickLengthOut */ -void QCPAxis::setTickLength(int inside, int outside) +void QCPAxis::setTickLength( int inside, int outside ) { - setTickLengthIn(inside); - setTickLengthOut(outside); + setTickLengthIn( inside ); + setTickLengthOut( outside ); } /*! @@ -8100,9 +8209,9 @@ void QCPAxis::setTickLength(int inside, int outside) \see setTickLengthOut, setTickLength, setSubTickLength */ -void QCPAxis::setTickLengthIn(int inside) +void QCPAxis::setTickLengthIn( int inside ) { - if (mAxisPainter->tickLengthIn != inside) + if( mAxisPainter->tickLengthIn != inside ) { mAxisPainter->tickLengthIn = inside; } @@ -8115,12 +8224,12 @@ void QCPAxis::setTickLengthIn(int inside) \see setTickLengthIn, setTickLength, setSubTickLength */ -void QCPAxis::setTickLengthOut(int outside) +void QCPAxis::setTickLengthOut( int outside ) { - if (mAxisPainter->tickLengthOut != outside) + if( mAxisPainter->tickLengthOut != outside ) { mAxisPainter->tickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin + mCachedMarginValid = false; // only outside tick length can change margin } } @@ -8131,9 +8240,9 @@ void QCPAxis::setTickLengthOut(int outside) \see setTicks */ -void QCPAxis::setSubTicks(bool show) +void QCPAxis::setSubTicks( bool show ) { - if (mSubTicks != show) + if( mSubTicks != show ) { mSubTicks = show; mCachedMarginValid = false; @@ -8148,10 +8257,10 @@ void QCPAxis::setSubTicks(bool show) \see setTickLength, setSubTickLengthIn, setSubTickLengthOut */ -void QCPAxis::setSubTickLength(int inside, int outside) +void QCPAxis::setSubTickLength( int inside, int outside ) { - setSubTickLengthIn(inside); - setSubTickLengthOut(outside); + setSubTickLengthIn( inside ); + setSubTickLengthOut( outside ); } /*! @@ -8160,9 +8269,9 @@ void QCPAxis::setSubTickLength(int inside, int outside) \see setSubTickLengthOut, setSubTickLength, setTickLength */ -void QCPAxis::setSubTickLengthIn(int inside) +void QCPAxis::setSubTickLengthIn( int inside ) { - if (mAxisPainter->subTickLengthIn != inside) + if( mAxisPainter->subTickLengthIn != inside ) { mAxisPainter->subTickLengthIn = inside; } @@ -8175,12 +8284,12 @@ void QCPAxis::setSubTickLengthIn(int inside) \see setSubTickLengthIn, setSubTickLength, setTickLength */ -void QCPAxis::setSubTickLengthOut(int outside) +void QCPAxis::setSubTickLengthOut( int outside ) { - if (mAxisPainter->subTickLengthOut != outside) + if( mAxisPainter->subTickLengthOut != outside ) { mAxisPainter->subTickLengthOut = outside; - mCachedMarginValid = false; // only outside tick length can change margin + mCachedMarginValid = false; // only outside tick length can change margin } } @@ -8189,7 +8298,7 @@ void QCPAxis::setSubTickLengthOut(int outside) \see setTickPen, setSubTickPen */ -void QCPAxis::setBasePen(const QPen &pen) +void QCPAxis::setBasePen( const QPen& pen ) { mBasePen = pen; } @@ -8199,7 +8308,7 @@ void QCPAxis::setBasePen(const QPen &pen) \see setTickLength, setBasePen */ -void QCPAxis::setTickPen(const QPen &pen) +void QCPAxis::setTickPen( const QPen& pen ) { mTickPen = pen; } @@ -8209,7 +8318,7 @@ void QCPAxis::setTickPen(const QPen &pen) \see setSubTickCount, setSubTickLength, setBasePen */ -void QCPAxis::setSubTickPen(const QPen &pen) +void QCPAxis::setSubTickPen( const QPen& pen ) { mSubTickPen = pen; } @@ -8219,9 +8328,9 @@ void QCPAxis::setSubTickPen(const QPen &pen) \see setLabelColor */ -void QCPAxis::setLabelFont(const QFont &font) +void QCPAxis::setLabelFont( const QFont& font ) { - if (mLabelFont != font) + if( mLabelFont != font ) { mLabelFont = font; mCachedMarginValid = false; @@ -8233,7 +8342,7 @@ void QCPAxis::setLabelFont(const QFont &font) \see setLabelFont */ -void QCPAxis::setLabelColor(const QColor &color) +void QCPAxis::setLabelColor( const QColor& color ) { mLabelColor = color; } @@ -8242,9 +8351,9 @@ void QCPAxis::setLabelColor(const QColor &color) Sets the text of the axis label that will be shown below/above or next to the axis, depending on its orientation. To disable axis labels, pass an empty string as \a str. */ -void QCPAxis::setLabel(const QString &str) +void QCPAxis::setLabel( const QString& str ) { - if (mLabel != str) + if( mLabel != str ) { mLabel = str; mCachedMarginValid = false; @@ -8256,9 +8365,9 @@ void QCPAxis::setLabel(const QString &str) \see setTickLabelPadding, setPadding */ -void QCPAxis::setLabelPadding(int padding) +void QCPAxis::setLabelPadding( int padding ) { - if (mAxisPainter->labelPadding != padding) + if( mAxisPainter->labelPadding != padding ) { mAxisPainter->labelPadding = padding; mCachedMarginValid = false; @@ -8275,9 +8384,9 @@ void QCPAxis::setLabelPadding(int padding) \see setLabelPadding, setTickLabelPadding */ -void QCPAxis::setPadding(int padding) +void QCPAxis::setPadding( int padding ) { - if (mPadding != padding) + if( mPadding != padding ) { mPadding = padding; mCachedMarginValid = false; @@ -8292,7 +8401,7 @@ void QCPAxis::setPadding(int padding) offset of the other, outer axes is controlled automatically, to place them at appropriate positions. */ -void QCPAxis::setOffset(int offset) +void QCPAxis::setOffset( int offset ) { mAxisPainter->offset = offset; } @@ -8302,9 +8411,9 @@ void QCPAxis::setOffset(int offset) \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedTickLabelFont(const QFont &font) +void QCPAxis::setSelectedTickLabelFont( const QFont& font ) { - if (font != mSelectedTickLabelFont) + if( font != mSelectedTickLabelFont ) { mSelectedTickLabelFont = font; // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts @@ -8316,7 +8425,7 @@ void QCPAxis::setSelectedTickLabelFont(const QFont &font) \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedLabelFont(const QFont &font) +void QCPAxis::setSelectedLabelFont( const QFont& font ) { mSelectedLabelFont = font; // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts @@ -8327,9 +8436,9 @@ void QCPAxis::setSelectedLabelFont(const QFont &font) \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedTickLabelColor(const QColor &color) +void QCPAxis::setSelectedTickLabelColor( const QColor& color ) { - if (color != mSelectedTickLabelColor) + if( color != mSelectedTickLabelColor ) { mSelectedTickLabelColor = color; } @@ -8340,7 +8449,7 @@ void QCPAxis::setSelectedTickLabelColor(const QColor &color) \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedLabelColor(const QColor &color) +void QCPAxis::setSelectedLabelColor( const QColor& color ) { mSelectedLabelColor = color; } @@ -8350,7 +8459,7 @@ void QCPAxis::setSelectedLabelColor(const QColor &color) \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedBasePen(const QPen &pen) +void QCPAxis::setSelectedBasePen( const QPen& pen ) { mSelectedBasePen = pen; } @@ -8360,7 +8469,7 @@ void QCPAxis::setSelectedBasePen(const QPen &pen) \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedTickPen(const QPen &pen) +void QCPAxis::setSelectedTickPen( const QPen& pen ) { mSelectedTickPen = pen; } @@ -8370,7 +8479,7 @@ void QCPAxis::setSelectedTickPen(const QPen &pen) \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPAxis::setSelectedSubTickPen(const QPen &pen) +void QCPAxis::setSelectedSubTickPen( const QPen& pen ) { mSelectedSubTickPen = pen; } @@ -8385,7 +8494,7 @@ void QCPAxis::setSelectedSubTickPen(const QPen &pen) \see setUpperEnding */ -void QCPAxis::setLowerEnding(const QCPLineEnding &ending) +void QCPAxis::setLowerEnding( const QCPLineEnding& ending ) { mAxisPainter->lowerEnding = ending; } @@ -8400,7 +8509,7 @@ void QCPAxis::setLowerEnding(const QCPLineEnding &ending) \see setLowerEnding */ -void QCPAxis::setUpperEnding(const QCPLineEnding &ending) +void QCPAxis::setUpperEnding( const QCPLineEnding& ending ) { mAxisPainter->upperEnding = ending; } @@ -8412,20 +8521,21 @@ void QCPAxis::setUpperEnding(const QCPLineEnding &ending) If the scale type is \ref stLogarithmic, the range bounds are multiplied by \a diff. This corresponds to an apparent "linear" move in logarithmic scaling by a distance of log(diff). */ -void QCPAxis::moveRange(double diff) +void QCPAxis::moveRange( double diff ) { QCPRange oldRange = mRange; - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { mRange.lower += diff; mRange.upper += diff; - } else // mScaleType == stLogarithmic + } + else // mScaleType == stLogarithmic { mRange.lower *= diff; mRange.upper *= diff; } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! @@ -8437,9 +8547,9 @@ void QCPAxis::moveRange(double diff) If you wish to scale around a different coordinate than the current axis range center, use the overload \ref scaleRange(double factor, double center). */ -void QCPAxis::scaleRange(double factor) +void QCPAxis::scaleRange( double factor ) { - scaleRange(factor, range().center()); + scaleRange( factor, range().center() ); } /*! \overload @@ -8451,30 +8561,32 @@ void QCPAxis::scaleRange(double factor) \see scaleRange(double factor) */ -void QCPAxis::scaleRange(double factor, double center) +void QCPAxis::scaleRange( double factor, double center ) { QCPRange oldRange = mRange; - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { QCPRange newRange; - newRange.lower = (mRange.lower-center)*factor + center; - newRange.upper = (mRange.upper-center)*factor + center; - if (QCPRange::validRange(newRange)) + newRange.lower = ( mRange.lower - center ) * factor + center; + newRange.upper = ( mRange.upper - center ) * factor + center; + if( QCPRange::validRange( newRange ) ) mRange = newRange.sanitizedForLinScale(); - } else // mScaleType == stLogarithmic + } + else // mScaleType == stLogarithmic { - if ((mRange.upper < 0 && center < 0) || (mRange.upper > 0 && center > 0)) // make sure center has same sign as range + if( ( mRange.upper < 0 && center < 0 ) || ( mRange.upper > 0 && center > 0 ) ) // make sure center has same sign as range { QCPRange newRange; - newRange.lower = qPow(mRange.lower/center, factor)*center; - newRange.upper = qPow(mRange.upper/center, factor)*center; - if (QCPRange::validRange(newRange)) + newRange.lower = qPow( mRange.lower / center, factor ) * center; + newRange.upper = qPow( mRange.upper / center, factor ) * center; + if( QCPRange::validRange( newRange ) ) mRange = newRange.sanitizedForLogScale(); - } else + } + else qDebug() << Q_FUNC_INFO << "Center of scaling operation doesn't lie in same logarithmic sign domain as range:" << center; } - emit rangeChanged(mRange); - emit rangeChanged(mRange, oldRange); + emit rangeChanged( mRange ); + emit rangeChanged( mRange, oldRange ); } /*! @@ -8490,22 +8602,22 @@ void QCPAxis::scaleRange(double factor, double center) won't have the desired effect, since the widget dimensions aren't defined yet, and a resizeEvent will follow. */ -void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) +void QCPAxis::setScaleRatio( const QCPAxis* otherAxis, double ratio ) { int otherPixelSize, ownPixelSize; - - if (otherAxis->orientation() == Qt::Horizontal) + + if( otherAxis->orientation() == Qt::Horizontal ) otherPixelSize = otherAxis->axisRect()->width(); else otherPixelSize = otherAxis->axisRect()->height(); - - if (orientation() == Qt::Horizontal) + + if( orientation() == Qt::Horizontal ) ownPixelSize = axisRect()->width(); else ownPixelSize = axisRect()->height(); - - double newRangeSize = ratio*otherAxis->range().size()*ownPixelSize/(double)otherPixelSize; - setRange(range().center(), newRangeSize, Qt::AlignCenter); + + double newRangeSize = ratio * otherAxis->range().size() * ownPixelSize / (double)otherPixelSize; + setRange( range().center(), newRangeSize, Qt::AlignCenter ); } /*! @@ -8514,86 +8626,90 @@ void QCPAxis::setScaleRatio(const QCPAxis *otherAxis, double ratio) \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */ -void QCPAxis::rescale(bool onlyVisiblePlottables) +void QCPAxis::rescale( bool onlyVisiblePlottables ) { QList p = plottables(); QCPRange newRange; bool haveRange = false; - for (int i=0; irealVisibility() && onlyVisiblePlottables) + if( !p.at( i )->realVisibility() && onlyVisiblePlottables ) continue; QCPRange plottableRange; bool currentFoundRange; QCP::SignDomain signDomain = QCP::sdBoth; - if (mScaleType == stLogarithmic) - signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - if (p.at(i)->keyAxis() == this) - plottableRange = p.at(i)->getKeyRange(currentFoundRange, signDomain); + if( mScaleType == stLogarithmic ) + signDomain = ( mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive ); + if( p.at( i )->keyAxis() == this ) + plottableRange = p.at( i )->getKeyRange( currentFoundRange, signDomain ); else - plottableRange = p.at(i)->getValueRange(currentFoundRange, signDomain); - if (currentFoundRange) + plottableRange = p.at( i )->getValueRange( currentFoundRange, signDomain ); + if( currentFoundRange ) { - if (!haveRange) + if( !haveRange ) newRange = plottableRange; else - newRange.expand(plottableRange); + newRange.expand( plottableRange ); haveRange = true; } } - if (haveRange) + if( haveRange ) { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + if( !QCPRange::validRange( newRange ) ) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mScaleType == stLinear) + double center = ( newRange.lower + newRange.upper ) * 0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if( mScaleType == stLinear ) { - newRange.lower = center-mRange.size()/2.0; - newRange.upper = center+mRange.size()/2.0; - } else // mScaleType == stLogarithmic + newRange.lower = center - mRange.size() / 2.0; + newRange.upper = center + mRange.size() / 2.0; + } + else // mScaleType == stLogarithmic { - newRange.lower = center/qSqrt(mRange.upper/mRange.lower); - newRange.upper = center*qSqrt(mRange.upper/mRange.lower); + newRange.lower = center / qSqrt( mRange.upper / mRange.lower ); + newRange.upper = center * qSqrt( mRange.upper / mRange.lower ); } } - setRange(newRange); + setRange( newRange ); } } /*! Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. */ -double QCPAxis::pixelToCoord(double value) const +double QCPAxis::pixelToCoord( double value ) const { - if (orientation() == Qt::Horizontal) + if( orientation() == Qt::Horizontal ) { - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { - if (!mRangeReversed) - return (value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.lower; + if( !mRangeReversed ) + return ( value - mAxisRect->left() ) / (double)mAxisRect->width() * mRange.size() + mRange.lower; else - return -(value-mAxisRect->left())/(double)mAxisRect->width()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic - { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->left())/(double)mAxisRect->width())*mRange.lower; - else - return qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/(double)mAxisRect->width())*mRange.upper; + return -( value - mAxisRect->left() ) / (double)mAxisRect->width() * mRange.size() + mRange.upper; } - } else // orientation() == Qt::Vertical + else // mScaleType == stLogarithmic + { + if( !mRangeReversed ) + return qPow( mRange.upper / mRange.lower, ( value - mAxisRect->left() ) / (double)mAxisRect->width() ) * mRange.lower; + else + return qPow( mRange.upper / mRange.lower, ( mAxisRect->left() - value ) / (double)mAxisRect->width() ) * mRange.upper; + } + } + else // orientation() == Qt::Vertical { - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { - if (!mRangeReversed) - return (mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.lower; + if( !mRangeReversed ) + return ( mAxisRect->bottom() - value ) / (double)mAxisRect->height() * mRange.size() + mRange.lower; else - return -(mAxisRect->bottom()-value)/(double)mAxisRect->height()*mRange.size()+mRange.upper; - } else // mScaleType == stLogarithmic + return -( mAxisRect->bottom() - value ) / (double)mAxisRect->height() * mRange.size() + mRange.upper; + } + else // mScaleType == stLogarithmic { - if (!mRangeReversed) - return qPow(mRange.upper/mRange.lower, (mAxisRect->bottom()-value)/(double)mAxisRect->height())*mRange.lower; + if( !mRangeReversed ) + return qPow( mRange.upper / mRange.lower, ( mAxisRect->bottom() - value ) / (double)mAxisRect->height() ) * mRange.lower; else - return qPow(mRange.upper/mRange.lower, (value-mAxisRect->bottom())/(double)mAxisRect->height())*mRange.upper; + return qPow( mRange.upper / mRange.lower, ( value - mAxisRect->bottom() ) / (double)mAxisRect->height() ) * mRange.upper; } } } @@ -8601,50 +8717,53 @@ double QCPAxis::pixelToCoord(double value) const /*! Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. */ -double QCPAxis::coordToPixel(double value) const +double QCPAxis::coordToPixel( double value ) const { - if (orientation() == Qt::Horizontal) + if( orientation() == Qt::Horizontal ) { - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { - if (!mRangeReversed) - return (value-mRange.lower)/mRange.size()*mAxisRect->width()+mAxisRect->left(); + if( !mRangeReversed ) + return ( value - mRange.lower ) / mRange.size() * mAxisRect->width() + mAxisRect->left(); else - return (mRange.upper-value)/mRange.size()*mAxisRect->width()+mAxisRect->left(); - } else // mScaleType == stLogarithmic + return ( mRange.upper - value ) / mRange.size() * mAxisRect->width() + mAxisRect->left(); + } + else // mScaleType == stLogarithmic { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->right()+200 : mAxisRect->left()-200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->left()-200 : mAxisRect->right()+200; + if( value >= 0.0 && mRange.upper < 0.0 ) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->right() + 200 : mAxisRect->left() - 200; + else if( value <= 0.0 && mRange.upper >= 0.0 ) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->left() - 200 : mAxisRect->right() + 200; else { - if (!mRangeReversed) - return qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + if( !mRangeReversed ) + return qLn( value / mRange.lower ) / qLn( mRange.upper / mRange.lower ) * mAxisRect->width() + mAxisRect->left(); else - return qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->width()+mAxisRect->left(); + return qLn( mRange.upper / value ) / qLn( mRange.upper / mRange.lower ) * mAxisRect->width() + mAxisRect->left(); } } - } else // orientation() == Qt::Vertical + } + else // orientation() == Qt::Vertical { - if (mScaleType == stLinear) + if( mScaleType == stLinear ) { - if (!mRangeReversed) - return mAxisRect->bottom()-(value-mRange.lower)/mRange.size()*mAxisRect->height(); + if( !mRangeReversed ) + return mAxisRect->bottom() - ( value - mRange.lower ) / mRange.size() * mAxisRect->height(); else - return mAxisRect->bottom()-(mRange.upper-value)/mRange.size()*mAxisRect->height(); - } else // mScaleType == stLogarithmic + return mAxisRect->bottom() - ( mRange.upper - value ) / mRange.size() * mAxisRect->height(); + } + else // mScaleType == stLogarithmic { - if (value >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->top()-200 : mAxisRect->bottom()+200; - else if (value <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just draw it outside visible range - return !mRangeReversed ? mAxisRect->bottom()+200 : mAxisRect->top()-200; + if( value >= 0.0 && mRange.upper < 0.0 ) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->top() - 200 : mAxisRect->bottom() + 200; + else if( value <= 0.0 && mRange.upper >= 0.0 ) // invalid value for logarithmic scale, just draw it outside visible range + return !mRangeReversed ? mAxisRect->bottom() + 200 : mAxisRect->top() - 200; else { - if (!mRangeReversed) - return mAxisRect->bottom()-qLn(value/mRange.lower)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + if( !mRangeReversed ) + return mAxisRect->bottom() - qLn( value / mRange.lower ) / qLn( mRange.upper / mRange.lower ) * mAxisRect->height(); else - return mAxisRect->bottom()-qLn(mRange.upper/value)/qLn(mRange.upper/mRange.lower)*mAxisRect->height(); + return mAxisRect->bottom() - qLn( mRange.upper / value ) / qLn( mRange.upper / mRange.lower ) * mAxisRect->height(); } } } @@ -8659,32 +8778,33 @@ double QCPAxis::coordToPixel(double value) const \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions */ -QCPAxis::SelectablePart QCPAxis::getPartAt(const QPointF &pos) const +QCPAxis::SelectablePart QCPAxis::getPartAt( const QPointF& pos ) const { - if (!mVisible) + if( !mVisible ) return spNone; - - if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) + + if( mAxisPainter->axisSelectionBox().contains( pos.toPoint() ) ) return spAxis; - else if (mAxisPainter->tickLabelsSelectionBox().contains(pos.toPoint())) + else if( mAxisPainter->tickLabelsSelectionBox().contains( pos.toPoint() ) ) return spTickLabels; - else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) + else if( mAxisPainter->labelSelectionBox().contains( pos.toPoint() ) ) return spAxisLabel; else return spNone; } /* inherits documentation from base class */ -double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPAxis::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if (!mParentPlot) return -1; - SelectablePart part = getPartAt(pos); - if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) + if( !mParentPlot ) return -1; - - if (details) - details->setValue(part); - return mParentPlot->selectionTolerance()*0.99; + SelectablePart part = getPartAt( pos ); + if( ( onlySelectable && !mSelectableParts.testFlag( part ) ) || part == spNone ) + return -1; + + if( details ) + details->setValue( part ); + return mParentPlot->selectionTolerance() * 0.99; } /*! @@ -8697,12 +8817,13 @@ double QCPAxis::selectTest(const QPointF &pos, bool onlySelectable, QVariant *de QList QCPAxis::plottables() const { QList result; - if (!mParentPlot) return result; - - for (int i=0; imPlottables.size(); ++i) + if( !mParentPlot ) + return result; + + for( int i = 0; i < mParentPlot->mPlottables.size(); ++i ) { - if (mParentPlot->mPlottables.at(i)->keyAxis() == this ||mParentPlot->mPlottables.at(i)->valueAxis() == this) - result.append(mParentPlot->mPlottables.at(i)); + if( mParentPlot->mPlottables.at( i )->keyAxis() == this || mParentPlot->mPlottables.at( i )->valueAxis() == this ) + result.append( mParentPlot->mPlottables.at( i ) ); } return result; } @@ -8715,12 +8836,13 @@ QList QCPAxis::plottables() const QList QCPAxis::graphs() const { QList result; - if (!mParentPlot) return result; - - for (int i=0; imGraphs.size(); ++i) + if( !mParentPlot ) + return result; + + for( int i = 0; i < mParentPlot->mGraphs.size(); ++i ) { - if (mParentPlot->mGraphs.at(i)->keyAxis() == this || mParentPlot->mGraphs.at(i)->valueAxis() == this) - result.append(mParentPlot->mGraphs.at(i)); + if( mParentPlot->mGraphs.at( i )->keyAxis() == this || mParentPlot->mGraphs.at( i )->valueAxis() == this ) + result.append( mParentPlot->mGraphs.at( i ) ); } return result; } @@ -8734,16 +8856,17 @@ QList QCPAxis::graphs() const QList QCPAxis::items() const { QList result; - if (!mParentPlot) return result; - - for (int itemId=0; itemIdmItems.size(); ++itemId) + if( !mParentPlot ) + return result; + + for( int itemId = 0; itemId < mParentPlot->mItems.size(); ++itemId ) { - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posId positions = mParentPlot->mItems.at( itemId )->positions(); + for( int posId = 0; posId < positions.size(); ++posId ) { - if (positions.at(posId)->keyAxis() == this || positions.at(posId)->valueAxis() == this) + if( positions.at( posId )->keyAxis() == this || positions.at( posId )->valueAxis() == this ) { - result.append(mParentPlot->mItems.at(itemId)); + result.append( mParentPlot->mItems.at( itemId ) ); break; } } @@ -8755,15 +8878,20 @@ QList QCPAxis::items() const Transforms a margin side to the logically corresponding axis type. (QCP::msLeft to QCPAxis::atLeft, QCP::msRight to QCPAxis::atRight, etc.) */ -QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) +QCPAxis::AxisType QCPAxis::marginSideToAxisType( QCP::MarginSide side ) { - switch (side) + switch( side ) { - case QCP::msLeft: return atLeft; - case QCP::msRight: return atRight; - case QCP::msTop: return atTop; - case QCP::msBottom: return atBottom; - default: break; + case QCP::msLeft: + return atLeft; + case QCP::msRight: + return atRight; + case QCP::msTop: + return atTop; + case QCP::msBottom: + return atBottom; + default: + break; } qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << (int)side; return atLeft; @@ -8772,38 +8900,49 @@ QCPAxis::AxisType QCPAxis::marginSideToAxisType(QCP::MarginSide side) /*! Returns the axis type that describes the opposite axis of an axis with the specified \a type. */ -QCPAxis::AxisType QCPAxis::opposite(QCPAxis::AxisType type) +QCPAxis::AxisType QCPAxis::opposite( QCPAxis::AxisType type ) { - switch (type) + switch( type ) { - case atLeft: return atRight; break; - case atRight: return atLeft; break; - case atBottom: return atTop; break; - case atTop: return atBottom; break; - default: qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; break; + case atLeft: + return atRight; + break; + case atRight: + return atLeft; + break; + case atBottom: + return atTop; + break; + case atTop: + return atBottom; + break; + default: + qDebug() << Q_FUNC_INFO << "invalid axis type"; + return atLeft; + break; } } /* inherits documentation from base class */ -void QCPAxis::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPAxis::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) + Q_UNUSED( event ) SelectablePart part = details.value(); - if (mSelectableParts.testFlag(part)) + if( mSelectableParts.testFlag( part ) ) { SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^part : part); - if (selectionStateChanged) + setSelectedParts( additive ? mSelectedParts ^ part : part ); + if( selectionStateChanged ) *selectionStateChanged = mSelectedParts != selBefore; } } /* inherits documentation from base class */ -void QCPAxis::deselectEvent(bool *selectionStateChanged) +void QCPAxis::deselectEvent( bool* selectionStateChanged ) { SelectableParts selBefore = mSelectedParts; - setSelectedParts(mSelectedParts & ~mSelectableParts); - if (selectionStateChanged) + setSelectedParts( mSelectedParts & ~mSelectableParts ); + if( selectionStateChanged ) *selectionStateChanged = mSelectedParts != selBefore; } @@ -8822,28 +8961,28 @@ void QCPAxis::deselectEvent(bool *selectionStateChanged) \note The dragging of possibly multiple axes at once by starting the drag anywhere in the axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::mousePressEvent. */ -void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) +void QCPAxis::mousePressEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) - if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag) || - !mAxisRect->rangeDrag().testFlag(orientation()) || - !mAxisRect->rangeDragAxes(orientation()).contains(this)) + Q_UNUSED( details ) + if( !mParentPlot->interactions().testFlag( QCP::iRangeDrag ) || + !mAxisRect->rangeDrag().testFlag( orientation() ) || + !mAxisRect->rangeDragAxes( orientation() ).contains( this ) ) { event->ignore(); return; } - - if (event->buttons() & Qt::LeftButton) + + if( event->buttons() & Qt::LeftButton ) { mDragging = true; // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) + if( mParentPlot->noAntialiasingOnDrag() ) { mAADragBackup = mParentPlot->antialiasedElements(); mNotAADragBackup = mParentPlot->notAntialiasedElements(); } // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + if( mParentPlot->interactions().testFlag( QCP::iRangeDrag ) ) mDragStartRange = mRange; } } @@ -8860,25 +8999,26 @@ void QCPAxis::mousePressEvent(QMouseEvent *event, const QVariant &details) \see QCPAxis::mousePressEvent */ -void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +void QCPAxis::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) { - if (mDragging) + if( mDragging ) { const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); const double currentPixel = orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y(); - if (mScaleType == QCPAxis::stLinear) + if( mScaleType == QCPAxis::stLinear ) { - const double diff = pixelToCoord(startPixel) - pixelToCoord(currentPixel); - setRange(mDragStartRange.lower+diff, mDragStartRange.upper+diff); - } else if (mScaleType == QCPAxis::stLogarithmic) - { - const double diff = pixelToCoord(startPixel) / pixelToCoord(currentPixel); - setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); + const double diff = pixelToCoord( startPixel ) - pixelToCoord( currentPixel ); + setRange( mDragStartRange.lower + diff, mDragStartRange.upper + diff ); } - - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); + else if( mScaleType == QCPAxis::stLogarithmic ) + { + const double diff = pixelToCoord( startPixel ) / pixelToCoord( currentPixel ); + setRange( mDragStartRange.lower * diff, mDragStartRange.upper * diff ); + } + + if( mParentPlot->noAntialiasingOnDrag() ) + mParentPlot->setNotAntialiasedElements( QCP::aeAll ); + mParentPlot->replot( QCustomPlot::rpQueuedReplot ); } } @@ -8894,15 +9034,15 @@ void QCPAxis::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) \see QCPAxis::mousePressEvent */ -void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +void QCPAxis::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) { - Q_UNUSED(event) - Q_UNUSED(startPos) + Q_UNUSED( event ) + Q_UNUSED( startPos ) mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) + if( mParentPlot->noAntialiasingOnDrag() ) { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + mParentPlot->setAntialiasedElements( mAADragBackup ); + mParentPlot->setNotAntialiasedElements( mNotAADragBackup ); } } @@ -8921,20 +9061,20 @@ void QCPAxis::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) \note The zooming of possibly multiple axes at once by performing the wheel event anywhere in the axis rect is handled by the axis rect's mouse event, e.g. \ref QCPAxisRect::wheelEvent. */ -void QCPAxis::wheelEvent(QWheelEvent *event) +void QCPAxis::wheelEvent( QWheelEvent* event ) { // Mouse range zooming interaction: - if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom) || - !mAxisRect->rangeZoom().testFlag(orientation()) || - !mAxisRect->rangeZoomAxes(orientation()).contains(this)) + if( !mParentPlot->interactions().testFlag( QCP::iRangeZoom ) || + !mAxisRect->rangeZoom().testFlag( orientation() ) || + !mAxisRect->rangeZoomAxes( orientation() ).contains( this ) ) { event->ignore(); return; } - - const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); - scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y())); + + const double wheelSteps = event->delta() / 120.0; // a single step delta is +/-120 usually + const double factor = qPow( mAxisRect->rangeZoomFactor( orientation() ), wheelSteps ); + scaleRange( factor, pixelToCoord( orientation() == Qt::Horizontal ? event->pos().x() : event->pos().y() ) ); mParentPlot->replot(); } @@ -8953,9 +9093,9 @@ void QCPAxis::wheelEvent(QWheelEvent *event) \see setAntialiased */ -void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPAxis::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); + applyAntialiasingHint( painter, mAntialiased, QCP::aeAxes ); } /*! \internal @@ -8964,32 +9104,32 @@ void QCPAxis::applyDefaultAntialiasingHint(QCPPainter *painter) const \seebaseclassmethod */ -void QCPAxis::draw(QCPPainter *painter) +void QCPAxis::draw( QCPPainter* painter ) { - QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - subTickPositions.reserve(mSubTickVector.size()); - - if (mTicks) + QVector subTickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve( mTickVector.size() ); + tickLabels.reserve( mTickVector.size() ); + subTickPositions.reserve( mSubTickVector.size() ); + + if( mTicks ) { - for (int i=0; itype = mAxisType; @@ -9009,7 +9149,7 @@ void QCPAxis::draw(QCPPainter *painter) mAxisPainter->tickPositions = tickPositions; mAxisPainter->tickLabels = tickLabels; mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw(painter); + mAxisPainter->draw( painter ); } /*! \internal @@ -9022,12 +9162,14 @@ void QCPAxis::draw(QCPPainter *painter) */ void QCPAxis::setupTickVectors() { - if (!mParentPlot) return; - if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; - + if( !mParentPlot ) + return; + if( ( !mTicks && !mTickLabels && !mGrid->visible() ) || mRange.size() <= 0 ) + return; + QVector oldLabels = mTickVectorLabels; - mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too + mTicker->generate( mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0 ); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too } /*! \internal @@ -9037,7 +9179,7 @@ void QCPAxis::setupTickVectors() */ QPen QCPAxis::getBasePen() const { - return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; + return mSelectedParts.testFlag( spAxis ) ? mSelectedBasePen : mBasePen; } /*! \internal @@ -9047,7 +9189,7 @@ QPen QCPAxis::getBasePen() const */ QPen QCPAxis::getTickPen() const { - return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; + return mSelectedParts.testFlag( spAxis ) ? mSelectedTickPen : mTickPen; } /*! \internal @@ -9057,7 +9199,7 @@ QPen QCPAxis::getTickPen() const */ QPen QCPAxis::getSubTickPen() const { - return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; + return mSelectedParts.testFlag( spAxis ) ? mSelectedSubTickPen : mSubTickPen; } /*! \internal @@ -9067,7 +9209,7 @@ QPen QCPAxis::getSubTickPen() const */ QFont QCPAxis::getTickLabelFont() const { - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; + return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelFont : mTickLabelFont; } /*! \internal @@ -9077,7 +9219,7 @@ QFont QCPAxis::getTickLabelFont() const */ QFont QCPAxis::getLabelFont() const { - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; + return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelFont : mLabelFont; } /*! \internal @@ -9087,7 +9229,7 @@ QFont QCPAxis::getLabelFont() const */ QColor QCPAxis::getTickLabelColor() const { - return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; + return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelColor : mTickLabelColor; } /*! \internal @@ -9097,7 +9239,7 @@ QColor QCPAxis::getTickLabelColor() const */ QColor QCPAxis::getLabelColor() const { - return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; + return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelColor : mLabelColor; } /*! \internal @@ -9116,27 +9258,27 @@ QColor QCPAxis::getLabelColor() const */ int QCPAxis::calculateMargin() { - if (!mVisible) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis + if( !mVisible ) // if not visible, directly return 0, don't cache 0 because we can't react to setVisible in QCPAxis return 0; - - if (mCachedMarginValid) + + if( mCachedMarginValid ) return mCachedMargin; - + // run through similar steps as QCPAxis::draw, and calculate margin needed to fit axis and its labels int margin = 0; - - QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter - QVector tickLabels; // the final vector passed to QCPAxisPainter - tickPositions.reserve(mTickVector.size()); - tickLabels.reserve(mTickVector.size()); - - if (mTicks) + + QVector tickPositions; // the final coordToPixel transformed vector passed to QCPAxisPainter + QVector tickLabels; // the final vector passed to QCPAxisPainter + tickPositions.reserve( mTickVector.size() ); + tickLabels.reserve( mTickVector.size() ); + + if( mTicks ) { - for (int i=0; isetPen(basePen); - if (QCPAxis::orientation(type) == Qt::Horizontal) - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(axisRect.width()+xCor, yCor)); + painter->setPen( basePen ); + if( QCPAxis::orientation( type ) == Qt::Horizontal ) + baseLine.setPoints( origin + QPointF( xCor, yCor ), origin + QPointF( axisRect.width() + xCor, yCor ) ); else - baseLine.setPoints(origin+QPointF(xCor, yCor), origin+QPointF(xCor, -axisRect.height()+yCor)); - if (reversedEndings) - baseLine = QLineF(baseLine.p2(), baseLine.p1()); // won't make a difference for line itself, but for line endings later - painter->drawLine(baseLine); - + baseLine.setPoints( origin + QPointF( xCor, yCor ), origin + QPointF( xCor, -axisRect.height() + yCor ) ); + if( reversedEndings ) + baseLine = QLineF( baseLine.p2(), baseLine.p1() ); // won't make a difference for line itself, but for line endings later + painter->drawLine( baseLine ); + // draw ticks: - if (!tickPositions.isEmpty()) + if( !tickPositions.isEmpty() ) { - painter->setPen(tickPen); - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) - if (QCPAxis::orientation(type) == Qt::Horizontal) + painter->setPen( tickPen ); + int tickDir = ( type == QCPAxis::atBottom || type == QCPAxis::atRight ) ? -1 : 1; // direction of ticks ("inward" is right for left axis and left for right axis) + if( QCPAxis::orientation( type ) == Qt::Horizontal ) { - for (int i=0; idrawLine(QLineF(tickPositions.at(i)+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPositions.at(i)+xCor, origin.y()+tickLengthIn*tickDir+yCor)); - } else + for( int i = 0; i < tickPositions.size(); ++i ) + painter->drawLine( QLineF( tickPositions.at( i ) + xCor, origin.y() - tickLengthOut * tickDir + yCor, tickPositions.at( i ) + xCor, origin.y() + tickLengthIn * tickDir + yCor ) ); + } + else { - for (int i=0; idrawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPositions.at(i)+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPositions.at(i)+yCor)); + for( int i = 0; i < tickPositions.size(); ++i ) + painter->drawLine( QLineF( origin.x() - tickLengthOut * tickDir + xCor, tickPositions.at( i ) + yCor, origin.x() + tickLengthIn * tickDir + xCor, tickPositions.at( i ) + yCor ) ); } } - + // draw subticks: - if (!subTickPositions.isEmpty()) + if( !subTickPositions.isEmpty() ) { - painter->setPen(subTickPen); + painter->setPen( subTickPen ); // direction of ticks ("inward" is right for left axis and left for right axis) - int tickDir = (type == QCPAxis::atBottom || type == QCPAxis::atRight) ? -1 : 1; - if (QCPAxis::orientation(type) == Qt::Horizontal) + int tickDir = ( type == QCPAxis::atBottom || type == QCPAxis::atRight ) ? -1 : 1; + if( QCPAxis::orientation( type ) == Qt::Horizontal ) { - for (int i=0; idrawLine(QLineF(subTickPositions.at(i)+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPositions.at(i)+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); - } else + for( int i = 0; i < subTickPositions.size(); ++i ) + painter->drawLine( QLineF( subTickPositions.at( i ) + xCor, origin.y() - subTickLengthOut * tickDir + yCor, subTickPositions.at( i ) + xCor, origin.y() + subTickLengthIn * tickDir + yCor ) ); + } + else { - for (int i=0; idrawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPositions.at(i)+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPositions.at(i)+yCor)); + for( int i = 0; i < subTickPositions.size(); ++i ) + painter->drawLine( QLineF( origin.x() - subTickLengthOut * tickDir + xCor, subTickPositions.at( i ) + yCor, origin.x() + subTickLengthIn * tickDir + xCor, subTickPositions.at( i ) + yCor ) ); } } - margin += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - + margin += qMax( 0, qMax( tickLengthOut, subTickLengthOut ) ); + // draw axis base endings: bool antialiasingBackup = painter->antialiasing(); - painter->setAntialiasing(true); // always want endings to be antialiased, even if base and ticks themselves aren't - painter->setBrush(QBrush(basePen.color())); - QCPVector2D baseLineVector(baseLine.dx(), baseLine.dy()); - if (lowerEnding.style() != QCPLineEnding::esNone) - lowerEnding.draw(painter, QCPVector2D(baseLine.p1())-baseLineVector.normalized()*lowerEnding.realLength()*(lowerEnding.inverted()?-1:1), -baseLineVector); - if (upperEnding.style() != QCPLineEnding::esNone) - upperEnding.draw(painter, QCPVector2D(baseLine.p2())+baseLineVector.normalized()*upperEnding.realLength()*(upperEnding.inverted()?-1:1), baseLineVector); - painter->setAntialiasing(antialiasingBackup); - + painter->setAntialiasing( true ); // always want endings to be antialiased, even if base and ticks themselves aren't + painter->setBrush( QBrush( basePen.color() ) ); + QCPVector2D baseLineVector( baseLine.dx(), baseLine.dy() ); + if( lowerEnding.style() != QCPLineEnding::esNone ) + lowerEnding.draw( painter, QCPVector2D( baseLine.p1() ) - baseLineVector.normalized() * lowerEnding.realLength() * ( lowerEnding.inverted() ? -1 : 1 ), -baseLineVector ); + if( upperEnding.style() != QCPLineEnding::esNone ) + upperEnding.draw( painter, QCPVector2D( baseLine.p2() ) + baseLineVector.normalized() * upperEnding.realLength() * ( upperEnding.inverted() ? -1 : 1 ), baseLineVector ); + painter->setAntialiasing( antialiasingBackup ); + // tick labels: QRect oldClipRect; - if (tickLabelSide == QCPAxis::lsInside) // if using inside labels, clip them to the axis rect + if( tickLabelSide == QCPAxis::lsInside ) // if using inside labels, clip them to the axis rect { oldClipRect = painter->clipRegion().boundingRect(); - painter->setClipRect(axisRect); + painter->setClipRect( axisRect ); } - QSize tickLabelsSize(0, 0); // size of largest tick label, for offset calculation of axis label - if (!tickLabels.isEmpty()) + QSize tickLabelsSize( 0, 0 ); // size of largest tick label, for offset calculation of axis label + if( !tickLabels.isEmpty() ) { - if (tickLabelSide == QCPAxis::lsOutside) + if( tickLabelSide == QCPAxis::lsOutside ) margin += tickLabelPadding; - painter->setFont(tickLabelFont); - painter->setPen(QPen(tickLabelColor)); - const int maxLabelIndex = qMin(tickPositions.size(), tickLabels.size()); + painter->setFont( tickLabelFont ); + painter->setPen( QPen( tickLabelColor ) ); + const int maxLabelIndex = qMin( tickPositions.size(), tickLabels.size() ); int distanceToAxis = margin; - if (tickLabelSide == QCPAxis::lsInside) - distanceToAxis = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); - for (int i=0; isetClipRect(oldClipRect); - + if( tickLabelSide == QCPAxis::lsInside ) + painter->setClipRect( oldClipRect ); + // axis label: QRect labelBounds; - if (!label.isEmpty()) + if( !label.isEmpty() ) { margin += labelPadding; - painter->setFont(labelFont); - painter->setPen(QPen(labelColor)); - labelBounds = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip, label); - if (type == QCPAxis::atLeft) + painter->setFont( labelFont ); + painter->setPen( QPen( labelColor ) ); + labelBounds = painter->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::TextDontClip, label ); + if( type == QCPAxis::atLeft ) { QTransform oldTransform = painter->transform(); - painter->translate((origin.x()-margin-labelBounds.height()), origin.y()); - painter->rotate(-90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); + painter->translate( ( origin.x() - margin - labelBounds.height() ), origin.y() ); + painter->rotate( -90 ); + painter->drawText( 0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label ); + painter->setTransform( oldTransform ); } - else if (type == QCPAxis::atRight) + else if( type == QCPAxis::atRight ) { QTransform oldTransform = painter->transform(); - painter->translate((origin.x()+margin+labelBounds.height()), origin.y()-axisRect.height()); - painter->rotate(90); - painter->drawText(0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - painter->setTransform(oldTransform); + painter->translate( ( origin.x() + margin + labelBounds.height() ), origin.y() - axisRect.height() ); + painter->rotate( 90 ); + painter->drawText( 0, 0, axisRect.height(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label ); + painter->setTransform( oldTransform ); } - else if (type == QCPAxis::atTop) - painter->drawText(origin.x(), origin.y()-margin-labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); - else if (type == QCPAxis::atBottom) - painter->drawText(origin.x(), origin.y()+margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label); + else if( type == QCPAxis::atTop ) + painter->drawText( origin.x(), origin.y() - margin - labelBounds.height(), axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label ); + else if( type == QCPAxis::atBottom ) + painter->drawText( origin.x(), origin.y() + margin, axisRect.width(), labelBounds.height(), Qt::TextDontClip | Qt::AlignCenter, label ); } - + // set selection boxes: int selectionTolerance = 0; - if (mParentPlot) + if( mParentPlot ) selectionTolerance = mParentPlot->selectionTolerance(); else qDebug() << Q_FUNC_INFO << "mParentPlot is null"; - int selAxisOutSize = qMax(qMax(tickLengthOut, subTickLengthOut), selectionTolerance); + int selAxisOutSize = qMax( qMax( tickLengthOut, subTickLengthOut ), selectionTolerance ); int selAxisInSize = selectionTolerance; int selTickLabelSize; int selTickLabelOffset; - if (tickLabelSide == QCPAxis::lsOutside) + if( tickLabelSide == QCPAxis::lsOutside ) { - selTickLabelSize = (QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = qMax(tickLengthOut, subTickLengthOut)+tickLabelPadding; - } else + selTickLabelSize = ( QCPAxis::orientation( type ) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width() ); + selTickLabelOffset = qMax( tickLengthOut, subTickLengthOut ) + tickLabelPadding; + } + else { - selTickLabelSize = -(QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width()); - selTickLabelOffset = -(qMax(tickLengthIn, subTickLengthIn)+tickLabelPadding); + selTickLabelSize = -( QCPAxis::orientation( type ) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width() ); + selTickLabelOffset = -( qMax( tickLengthIn, subTickLengthIn ) + tickLabelPadding ); } int selLabelSize = labelBounds.height(); - int selLabelOffset = qMax(tickLengthOut, subTickLengthOut)+(!tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding+selTickLabelSize : 0)+labelPadding; - if (type == QCPAxis::atLeft) + int selLabelOffset = qMax( tickLengthOut, subTickLengthOut ) + ( !tickLabels.isEmpty() && tickLabelSide == QCPAxis::lsOutside ? tickLabelPadding + selTickLabelSize : 0 ) + labelPadding; + if( type == QCPAxis::atLeft ) { - mAxisSelectionBox.setCoords(origin.x()-selAxisOutSize, axisRect.top(), origin.x()+selAxisInSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()-selTickLabelOffset-selTickLabelSize, axisRect.top(), origin.x()-selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()-selLabelOffset-selLabelSize, axisRect.top(), origin.x()-selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atRight) + mAxisSelectionBox.setCoords( origin.x() - selAxisOutSize, axisRect.top(), origin.x() + selAxisInSize, axisRect.bottom() ); + mTickLabelsSelectionBox.setCoords( origin.x() - selTickLabelOffset - selTickLabelSize, axisRect.top(), origin.x() - selTickLabelOffset, axisRect.bottom() ); + mLabelSelectionBox.setCoords( origin.x() - selLabelOffset - selLabelSize, axisRect.top(), origin.x() - selLabelOffset, axisRect.bottom() ); + } + else if( type == QCPAxis::atRight ) { - mAxisSelectionBox.setCoords(origin.x()-selAxisInSize, axisRect.top(), origin.x()+selAxisOutSize, axisRect.bottom()); - mTickLabelsSelectionBox.setCoords(origin.x()+selTickLabelOffset+selTickLabelSize, axisRect.top(), origin.x()+selTickLabelOffset, axisRect.bottom()); - mLabelSelectionBox.setCoords(origin.x()+selLabelOffset+selLabelSize, axisRect.top(), origin.x()+selLabelOffset, axisRect.bottom()); - } else if (type == QCPAxis::atTop) + mAxisSelectionBox.setCoords( origin.x() - selAxisInSize, axisRect.top(), origin.x() + selAxisOutSize, axisRect.bottom() ); + mTickLabelsSelectionBox.setCoords( origin.x() + selTickLabelOffset + selTickLabelSize, axisRect.top(), origin.x() + selTickLabelOffset, axisRect.bottom() ); + mLabelSelectionBox.setCoords( origin.x() + selLabelOffset + selLabelSize, axisRect.top(), origin.x() + selLabelOffset, axisRect.bottom() ); + } + else if( type == QCPAxis::atTop ) { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisOutSize, axisRect.right(), origin.y()+selAxisInSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()-selTickLabelOffset-selTickLabelSize, axisRect.right(), origin.y()-selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()-selLabelOffset-selLabelSize, axisRect.right(), origin.y()-selLabelOffset); - } else if (type == QCPAxis::atBottom) + mAxisSelectionBox.setCoords( axisRect.left(), origin.y() - selAxisOutSize, axisRect.right(), origin.y() + selAxisInSize ); + mTickLabelsSelectionBox.setCoords( axisRect.left(), origin.y() - selTickLabelOffset - selTickLabelSize, axisRect.right(), origin.y() - selTickLabelOffset ); + mLabelSelectionBox.setCoords( axisRect.left(), origin.y() - selLabelOffset - selLabelSize, axisRect.right(), origin.y() - selLabelOffset ); + } + else if( type == QCPAxis::atBottom ) { - mAxisSelectionBox.setCoords(axisRect.left(), origin.y()-selAxisInSize, axisRect.right(), origin.y()+selAxisOutSize); - mTickLabelsSelectionBox.setCoords(axisRect.left(), origin.y()+selTickLabelOffset+selTickLabelSize, axisRect.right(), origin.y()+selTickLabelOffset); - mLabelSelectionBox.setCoords(axisRect.left(), origin.y()+selLabelOffset+selLabelSize, axisRect.right(), origin.y()+selLabelOffset); + mAxisSelectionBox.setCoords( axisRect.left(), origin.y() - selAxisInSize, axisRect.right(), origin.y() + selAxisOutSize ); + mTickLabelsSelectionBox.setCoords( axisRect.left(), origin.y() + selTickLabelOffset + selTickLabelSize, axisRect.right(), origin.y() + selTickLabelOffset ); + mLabelSelectionBox.setCoords( axisRect.left(), origin.y() + selLabelOffset + selLabelSize, axisRect.right(), origin.y() + selLabelOffset ); } mAxisSelectionBox = mAxisSelectionBox.normalized(); mTickLabelsSelectionBox = mTickLabelsSelectionBox.normalized(); @@ -9416,33 +9556,33 @@ void QCPAxisPainterPrivate::draw(QCPPainter *painter) int QCPAxisPainterPrivate::size() const { int result = 0; - + // get length of tick marks pointing outwards: - if (!tickPositions.isEmpty()) - result += qMax(0, qMax(tickLengthOut, subTickLengthOut)); - + if( !tickPositions.isEmpty() ) + result += qMax( 0, qMax( tickLengthOut, subTickLengthOut ) ); + // calculate size of tick labels: - if (tickLabelSide == QCPAxis::lsOutside) + if( tickLabelSide == QCPAxis::lsOutside ) { - QSize tickLabelsSize(0, 0); - if (!tickLabels.isEmpty()) + QSize tickLabelsSize( 0, 0 ); + if( !tickLabels.isEmpty() ) { - for (int i=0; ibufferDevicePixelRatio())); - result.append(QByteArray::number(tickLabelRotation)); - result.append(QByteArray::number((int)tickLabelSide)); - result.append(QByteArray::number((int)substituteExponent)); - result.append(QByteArray::number((int)numberMultiplyCross)); - result.append(tickLabelColor.name().toLatin1()+QByteArray::number(tickLabelColor.alpha(), 16)); - result.append(tickLabelFont.toString().toLatin1()); + result.append( QByteArray::number( mParentPlot->bufferDevicePixelRatio() ) ); + result.append( QByteArray::number( tickLabelRotation ) ); + result.append( QByteArray::number( (int)tickLabelSide ) ); + result.append( QByteArray::number( (int)substituteExponent ) ); + result.append( QByteArray::number( (int)numberMultiplyCross ) ); + result.append( tickLabelColor.name().toLatin1() + QByteArray::number( tickLabelColor.alpha(), 16 ) ); + result.append( tickLabelFont.toString().toLatin1() ); return result; } @@ -9496,84 +9636,95 @@ QByteArray QCPAxisPainterPrivate::generateLabelParameterHash() const superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref getTickLabelData). */ -void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize) +void QCPAxisPainterPrivate::placeTickLabel( QCPPainter* painter, double position, int distanceToAxis, const QString& text, QSize* tickLabelsSize ) { // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if (text.isEmpty()) return; + if( text.isEmpty() ) + return; QSize finalSize; QPointF labelAnchor; - switch (type) + switch( type ) { - case QCPAxis::atLeft: labelAnchor = QPointF(axisRect.left()-distanceToAxis-offset, position); break; - case QCPAxis::atRight: labelAnchor = QPointF(axisRect.right()+distanceToAxis+offset, position); break; - case QCPAxis::atTop: labelAnchor = QPointF(position, axisRect.top()-distanceToAxis-offset); break; - case QCPAxis::atBottom: labelAnchor = QPointF(position, axisRect.bottom()+distanceToAxis+offset); break; + case QCPAxis::atLeft: + labelAnchor = QPointF( axisRect.left() - distanceToAxis - offset, position ); + break; + case QCPAxis::atRight: + labelAnchor = QPointF( axisRect.right() + distanceToAxis + offset, position ); + break; + case QCPAxis::atTop: + labelAnchor = QPointF( position, axisRect.top() - distanceToAxis - offset ); + break; + case QCPAxis::atBottom: + labelAnchor = QPointF( position, axisRect.bottom() + distanceToAxis + offset ); + break; } - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && !painter->modes().testFlag(QCPPainter::pmNoCaching)) // label caching enabled + if( mParentPlot->plottingHints().testFlag( QCP::phCacheLabels ) && !painter->modes().testFlag( QCPPainter::pmNoCaching ) ) // label caching enabled { - CachedLabel *cachedLabel = mLabelCache.take(text); // attempt to get label from cache - if (!cachedLabel) // no cached label existed, create it + CachedLabel* cachedLabel = mLabelCache.take( text ); // attempt to get label from cache + if( !cachedLabel ) // no cached label existed, create it { cachedLabel = new CachedLabel; - TickLabelData labelData = getTickLabelData(painter->font(), text); - cachedLabel->offset = getTickLabelDrawOffset(labelData)+labelData.rotatedTotalBounds.topLeft(); - if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) + TickLabelData labelData = getTickLabelData( painter->font(), text ); + cachedLabel->offset = getTickLabelDrawOffset( labelData ) + labelData.rotatedTotalBounds.topLeft(); + if( !qFuzzyCompare( 1.0, mParentPlot->bufferDevicePixelRatio() ) ) { - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); + cachedLabel->pixmap = QPixmap( labelData.rotatedTotalBounds.size() * mParentPlot->bufferDevicePixelRatio() ); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); -# else - cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); -# endif +#ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio( mParentPlot->devicePixelRatioF() ); +#else + cachedLabel->pixmap.setDevicePixelRatio( mParentPlot->devicePixelRatio() ); #endif - } else - cachedLabel->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); - cachedLabel->pixmap.fill(Qt::transparent); - QCPPainter cachePainter(&cachedLabel->pixmap); - cachePainter.setPen(painter->pen()); - drawTickLabel(&cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData); +#endif + } + else + cachedLabel->pixmap = QPixmap( labelData.rotatedTotalBounds.size() ); + cachedLabel->pixmap.fill( Qt::transparent ); + QCPPainter cachePainter( &cachedLabel->pixmap ); + cachePainter.setPen( painter->pen() ); + drawTickLabel( &cachePainter, -labelData.rotatedTotalBounds.topLeft().x(), -labelData.rotatedTotalBounds.topLeft().y(), labelData ); } // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) + if( tickLabelSide == QCPAxis::lsOutside ) { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = labelAnchor.x()+cachedLabel->offset.x()+cachedLabel->pixmap.width()/mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x()+cachedLabel->offset.x() < viewportRect.left(); + if( QCPAxis::orientation( type ) == Qt::Horizontal ) + labelClippedByBorder = labelAnchor.x() + cachedLabel->offset.x() + cachedLabel->pixmap.width() / mParentPlot->bufferDevicePixelRatio() > viewportRect.right() || labelAnchor.x() + cachedLabel->offset.x() < viewportRect.left(); else - labelClippedByBorder = labelAnchor.y()+cachedLabel->offset.y()+cachedLabel->pixmap.height()/mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y()+cachedLabel->offset.y() < viewportRect.top(); + labelClippedByBorder = labelAnchor.y() + cachedLabel->offset.y() + cachedLabel->pixmap.height() / mParentPlot->bufferDevicePixelRatio() > viewportRect.bottom() || labelAnchor.y() + cachedLabel->offset.y() < viewportRect.top(); } - if (!labelClippedByBorder) + if( !labelClippedByBorder ) { - painter->drawPixmap(labelAnchor+cachedLabel->offset, cachedLabel->pixmap); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); + painter->drawPixmap( labelAnchor + cachedLabel->offset, cachedLabel->pixmap ); + finalSize = cachedLabel->pixmap.size() / mParentPlot->bufferDevicePixelRatio(); } - mLabelCache.insert(text, cachedLabel); // return label to cache or insert for the first time if newly created - } else // label caching disabled, draw text directly on surface: + mLabelCache.insert( text, cachedLabel ); // return label to cache or insert for the first time if newly created + } + else // label caching disabled, draw text directly on surface: { - TickLabelData labelData = getTickLabelData(painter->font(), text); - QPointF finalPosition = labelAnchor + getTickLabelDrawOffset(labelData); + TickLabelData labelData = getTickLabelData( painter->font(), text ); + QPointF finalPosition = labelAnchor + getTickLabelDrawOffset( labelData ); // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - if (tickLabelSide == QCPAxis::lsOutside) + bool labelClippedByBorder = false; + if( tickLabelSide == QCPAxis::lsOutside ) { - if (QCPAxis::orientation(type) == Qt::Horizontal) - labelClippedByBorder = finalPosition.x()+(labelData.rotatedTotalBounds.width()+labelData.rotatedTotalBounds.left()) > viewportRect.right() || finalPosition.x()+labelData.rotatedTotalBounds.left() < viewportRect.left(); + if( QCPAxis::orientation( type ) == Qt::Horizontal ) + labelClippedByBorder = finalPosition.x() + ( labelData.rotatedTotalBounds.width() + labelData.rotatedTotalBounds.left() ) > viewportRect.right() || finalPosition.x() + labelData.rotatedTotalBounds.left() < viewportRect.left(); else - labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); + labelClippedByBorder = finalPosition.y() + ( labelData.rotatedTotalBounds.height() + labelData.rotatedTotalBounds.top() ) > viewportRect.bottom() || finalPosition.y() + labelData.rotatedTotalBounds.top() < viewportRect.top(); } - if (!labelClippedByBorder) + if( !labelClippedByBorder ) { - drawTickLabel(painter, finalPosition.x(), finalPosition.y(), labelData); + drawTickLabel( painter, finalPosition.x(), finalPosition.y(), labelData ); finalSize = labelData.rotatedTotalBounds.size(); } } - + // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); + if( finalSize.width() > tickLabelsSize->width() ) + tickLabelsSize->setWidth( finalSize.width() ); + if( finalSize.height() > tickLabelsSize->height() ) + tickLabelsSize->setHeight( finalSize.height() ); } /*! \internal @@ -9585,35 +9736,36 @@ void QCPAxisPainterPrivate::placeTickLabel(QCPPainter *painter, double position, directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when QCP::phCacheLabels plotting hint is not set. */ -void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const +void QCPAxisPainterPrivate::drawTickLabel( QCPPainter* painter, double x, double y, const TickLabelData& labelData ) const { // backup painter settings that we're about to change: QTransform oldTransform = painter->transform(); QFont oldFont = painter->font(); - + // transform painter to position/rotation: - painter->translate(x, y); - if (!qFuzzyIsNull(tickLabelRotation)) - painter->rotate(tickLabelRotation); - + painter->translate( x, y ); + if( !qFuzzyIsNull( tickLabelRotation ) ) + painter->rotate( tickLabelRotation ); + // draw text: - if (!labelData.expPart.isEmpty()) // indicator that beautiful powers must be used + if( !labelData.expPart.isEmpty() ) // indicator that beautiful powers must be used { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, 0, 0, Qt::TextDontClip, labelData.basePart); - if (!labelData.suffixPart.isEmpty()) - painter->drawText(labelData.baseBounds.width()+1+labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart); - painter->setFont(labelData.expFont); - painter->drawText(labelData.baseBounds.width()+1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart); - } else - { - painter->setFont(labelData.baseFont); - painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); + painter->setFont( labelData.baseFont ); + painter->drawText( 0, 0, 0, 0, Qt::TextDontClip, labelData.basePart ); + if( !labelData.suffixPart.isEmpty() ) + painter->drawText( labelData.baseBounds.width() + 1 + labelData.expBounds.width(), 0, 0, 0, Qt::TextDontClip, labelData.suffixPart ); + painter->setFont( labelData.expFont ); + painter->drawText( labelData.baseBounds.width() + 1, 0, labelData.expBounds.width(), labelData.expBounds.height(), Qt::TextDontClip, labelData.expPart ); } - + else + { + painter->setFont( labelData.baseFont ); + painter->drawText( 0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart ); + } + // reset painter settings to what it was before: - painter->setTransform(oldTransform); - painter->setFont(oldFont); + painter->setTransform( oldTransform ); + painter->setFont( oldFont ); } /*! \internal @@ -9624,75 +9776,76 @@ void QCPAxisPainterPrivate::drawTickLabel(QCPPainter *painter, double x, double processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. */ -QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(const QFont &font, const QString &text) const +QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData( const QFont& font, const QString& text ) const { TickLabelData result; - + // determine whether beautiful decimal powers should be used bool useBeautifulPowers = false; - int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart - int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart - if (substituteExponent) + int ePos = -1; // first index of exponent part, text before that will be basePart, text until eLast will be expPart + int eLast = -1; // last index of exponent part, rest of text after this will be suffixPart + if( substituteExponent ) { - ePos = text.indexOf(QLatin1Char('e')); - if (ePos > 0 && text.at(ePos-1).isDigit()) + ePos = text.indexOf( QLatin1Char( 'e' ) ); + if( ePos > 0 && text.at( ePos - 1 ).isDigit() ) { eLast = ePos; - while (eLast+1 < text.size() && (text.at(eLast+1) == QLatin1Char('+') || text.at(eLast+1) == QLatin1Char('-') || text.at(eLast+1).isDigit())) + while( eLast + 1 < text.size() && ( text.at( eLast + 1 ) == QLatin1Char( '+' ) || text.at( eLast + 1 ) == QLatin1Char( '-' ) || text.at( eLast + 1 ).isDigit() ) ) ++eLast; - if (eLast > ePos) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power + if( eLast > ePos ) // only if also to right of 'e' is a digit/+/- interpret it as beautifiable power useBeautifulPowers = true; } } - + // calculate text bounding rects and do string preparation for beautiful decimal powers: result.baseFont = font; - if (result.baseFont.pointSizeF() > 0) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line - result.baseFont.setPointSizeF(result.baseFont.pointSizeF()+0.05); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding - if (useBeautifulPowers) + if( result.baseFont.pointSizeF() > 0 ) // might return -1 if specified with setPixelSize, in that case we can't do correction in next line + result.baseFont.setPointSizeF( result.baseFont.pointSizeF() + 0.05 ); // QFontMetrics.boundingRect has a bug for exact point sizes that make the results oscillate due to internal rounding + if( useBeautifulPowers ) { // split text into parts of number/symbol that will be drawn normally and part that will be drawn as exponent: - result.basePart = text.left(ePos); - result.suffixPart = text.mid(eLast+1); // also drawn normally but after exponent + result.basePart = text.left( ePos ); + result.suffixPart = text.mid( eLast + 1 ); // also drawn normally but after exponent // in log scaling, we want to turn "1*10^n" into "10^n", else add multiplication sign and decimal base: - if (abbreviateDecimalPowers && result.basePart == QLatin1String("1")) - result.basePart = QLatin1String("10"); + if( abbreviateDecimalPowers && result.basePart == QLatin1String( "1" ) ) + result.basePart = QLatin1String( "10" ); else - result.basePart += (numberMultiplyCross ? QString(QChar(215)) : QString(QChar(183))) + QLatin1String("10"); - result.expPart = text.mid(ePos+1, eLast-ePos); + result.basePart += ( numberMultiplyCross ? QString( QChar( 215 ) ) : QString( QChar( 183 ) ) ) + QLatin1String( "10" ); + result.expPart = text.mid( ePos + 1, eLast - ePos ); // clip "+" and leading zeros off expPart: - while (result.expPart.length() > 2 && result.expPart.at(1) == QLatin1Char('0')) // length > 2 so we leave one zero when numberFormatChar is 'e' - result.expPart.remove(1, 1); - if (!result.expPart.isEmpty() && result.expPart.at(0) == QLatin1Char('+')) - result.expPart.remove(0, 1); + while( result.expPart.length() > 2 && result.expPart.at( 1 ) == QLatin1Char( '0' ) ) // length > 2 so we leave one zero when numberFormatChar is 'e' + result.expPart.remove( 1, 1 ); + if( !result.expPart.isEmpty() && result.expPart.at( 0 ) == QLatin1Char( '+' ) ) + result.expPart.remove( 0, 1 ); // prepare smaller font for exponent: result.expFont = font; - if (result.expFont.pointSize() > 0) - result.expFont.setPointSize(result.expFont.pointSize()*0.75); + if( result.expFont.pointSize() > 0 ) + result.expFont.setPointSize( result.expFont.pointSize() * 0.75 ); else - result.expFont.setPixelSize(result.expFont.pixelSize()*0.75); + result.expFont.setPixelSize( result.expFont.pixelSize() * 0.75 ); // calculate bounding rects of base part(s), exponent part and total one: - result.baseBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.basePart); - result.expBounds = QFontMetrics(result.expFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.expPart); - if (!result.suffixPart.isEmpty()) - result.suffixBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip, result.suffixPart); - result.totalBounds = result.baseBounds.adjusted(0, 0, result.expBounds.width()+result.suffixBounds.width()+2, 0); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA - } else // useBeautifulPowers == false + result.baseBounds = QFontMetrics( result.baseFont ).boundingRect( 0, 0, 0, 0, Qt::TextDontClip, result.basePart ); + result.expBounds = QFontMetrics( result.expFont ).boundingRect( 0, 0, 0, 0, Qt::TextDontClip, result.expPart ); + if( !result.suffixPart.isEmpty() ) + result.suffixBounds = QFontMetrics( result.baseFont ).boundingRect( 0, 0, 0, 0, Qt::TextDontClip, result.suffixPart ); + result.totalBounds = result.baseBounds.adjusted( 0, 0, result.expBounds.width() + result.suffixBounds.width() + 2, 0 ); // +2 consists of the 1 pixel spacing between base and exponent (see drawTickLabel) and an extra pixel to include AA + } + else // useBeautifulPowers == false { result.basePart = text; - result.totalBounds = QFontMetrics(result.baseFont).boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); + result.totalBounds = QFontMetrics( result.baseFont ).boundingRect( 0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart ); } - result.totalBounds.moveTopLeft(QPoint(0, 0)); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler - + result.totalBounds.moveTopLeft( QPoint( 0, 0 ) ); // want bounding box aligned top left at origin, independent of how it was created, to make further processing simpler + // calculate possibly different bounding rect after rotation: result.rotatedTotalBounds = result.totalBounds; - if (!qFuzzyIsNull(tickLabelRotation)) + if( !qFuzzyIsNull( tickLabelRotation ) ) { QTransform transform; - transform.rotate(tickLabelRotation); - result.rotatedTotalBounds = transform.mapRect(result.rotatedTotalBounds); + transform.rotate( tickLabelRotation ); + result.rotatedTotalBounds = transform.mapRect( result.rotatedTotalBounds ); } - + return result; } @@ -9706,7 +9859,7 @@ QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData(con This function is thus responsible for e.g. centering tick labels under ticks and positioning them appropriately when they are rotated. */ -QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const +QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset( const TickLabelData& labelData ) const { /* calculate label offset from base point at tick (non-trivial, for best visual appearance): short @@ -9718,85 +9871,96 @@ QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &label time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick labels. */ - bool doRotation = !qFuzzyIsNull(tickLabelRotation); - bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. - double radians = tickLabelRotation/180.0*M_PI; - int x=0, y=0; - if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label + bool doRotation = !qFuzzyIsNull( tickLabelRotation ); + bool flip = qFuzzyCompare( qAbs( tickLabelRotation ), 90.0 ); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. + double radians = tickLabelRotation / 180.0 * M_PI; + int x = 0, y = 0; + if( ( type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside ) || ( type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside ) ) // Anchor at right side of tick label { - if (doRotation) + if( doRotation ) { - if (tickLabelRotation > 0) + if( tickLabelRotation > 0 ) { - x = -qCos(radians)*labelData.totalBounds.width(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); - y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; + x = -qCos( radians ) * labelData.totalBounds.width(); + y = flip ? -labelData.totalBounds.width() / 2.0 : -qSin( radians ) * labelData.totalBounds.width() - qCos( radians ) * labelData.totalBounds.height() / 2.0; } - } else + else + { + x = -qCos( -radians ) * labelData.totalBounds.width() - qSin( -radians ) * labelData.totalBounds.height(); + y = flip ? +labelData.totalBounds.width() / 2.0 : +qSin( -radians ) * labelData.totalBounds.width() - qCos( -radians ) * labelData.totalBounds.height() / 2.0; + } + } + else { x = -labelData.totalBounds.width(); - y = -labelData.totalBounds.height()/2.0; + y = -labelData.totalBounds.height() / 2.0; } - } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label + } + else if( ( type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside ) || ( type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside ) ) // Anchor at left side of tick label { - if (doRotation) + if( doRotation ) { - if (tickLabelRotation > 0) + if( tickLabelRotation > 0 ) { - x = +qSin(radians)*labelData.totalBounds.height(); - y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; - } else + x = +qSin( radians ) * labelData.totalBounds.height(); + y = flip ? -labelData.totalBounds.width() / 2.0 : -qCos( radians ) * labelData.totalBounds.height() / 2.0; + } + else { x = 0; - y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; + y = flip ? +labelData.totalBounds.width() / 2.0 : -qCos( -radians ) * labelData.totalBounds.height() / 2.0; } - } else + } + else { x = 0; - y = -labelData.totalBounds.height()/2.0; + y = -labelData.totalBounds.height() / 2.0; } - } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label + } + else if( ( type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside ) || ( type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside ) ) // Anchor at bottom side of tick label { - if (doRotation) + if( doRotation ) { - if (tickLabelRotation > 0) + if( tickLabelRotation > 0 ) { - x = -qCos(radians)*labelData.totalBounds.width()+qSin(radians)*labelData.totalBounds.height()/2.0; - y = -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height(); - } else - { - x = -qSin(-radians)*labelData.totalBounds.height()/2.0; - y = -qCos(-radians)*labelData.totalBounds.height(); + x = -qCos( radians ) * labelData.totalBounds.width() + qSin( radians ) * labelData.totalBounds.height() / 2.0; + y = -qSin( radians ) * labelData.totalBounds.width() - qCos( radians ) * labelData.totalBounds.height(); } - } else + else + { + x = -qSin( -radians ) * labelData.totalBounds.height() / 2.0; + y = -qCos( -radians ) * labelData.totalBounds.height(); + } + } + else { - x = -labelData.totalBounds.width()/2.0; + x = -labelData.totalBounds.width() / 2.0; y = -labelData.totalBounds.height(); } - } else if ((type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside)) // Anchor at top side of tick label + } + else if( ( type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsOutside ) || ( type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsInside ) ) // Anchor at top side of tick label { - if (doRotation) + if( doRotation ) { - if (tickLabelRotation > 0) + if( tickLabelRotation > 0 ) { - x = +qSin(radians)*labelData.totalBounds.height()/2.0; + x = +qSin( radians ) * labelData.totalBounds.height() / 2.0; y = 0; - } else - { - x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; - y = +qSin(-radians)*labelData.totalBounds.width(); } - } else + else + { + x = -qCos( -radians ) * labelData.totalBounds.width() - qSin( -radians ) * labelData.totalBounds.height() / 2.0; + y = +qSin( -radians ) * labelData.totalBounds.width(); + } + } + else { - x = -labelData.totalBounds.width()/2.0; + x = -labelData.totalBounds.width() / 2.0; y = 0; } } - - return QPointF(x, y); + + return QPointF( x, y ); } /*! \internal @@ -9806,29 +9970,29 @@ QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &label margin calculation, the passed \a tickLabelsSize is only expanded, if it's currently set to a smaller width/height. */ -void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const +void QCPAxisPainterPrivate::getMaxTickLabelSize( const QFont& font, const QString& text, QSize* tickLabelsSize ) const { // note: this function must return the same tick label sizes as the placeTickLabel function. QSize finalSize; - if (mParentPlot->plottingHints().testFlag(QCP::phCacheLabels) && mLabelCache.contains(text)) // label caching enabled and have cached label + if( mParentPlot->plottingHints().testFlag( QCP::phCacheLabels ) && mLabelCache.contains( text ) ) // label caching enabled and have cached label { - const CachedLabel *cachedLabel = mLabelCache.object(text); - finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); - } else // label caching disabled or no label with this text cached: + const CachedLabel* cachedLabel = mLabelCache.object( text ); + finalSize = cachedLabel->pixmap.size() / mParentPlot->bufferDevicePixelRatio(); + } + else // label caching disabled or no label with this text cached: { - TickLabelData labelData = getTickLabelData(font, text); + TickLabelData labelData = getTickLabelData( font, text ); finalSize = labelData.rotatedTotalBounds.size(); } - + // expand passed tickLabelsSize if current tick label is larger: - if (finalSize.width() > tickLabelsSize->width()) - tickLabelsSize->setWidth(finalSize.width()); - if (finalSize.height() > tickLabelsSize->height()) - tickLabelsSize->setHeight(finalSize.height()); + if( finalSize.width() > tickLabelsSize->width() ) + tickLabelsSize->setWidth( finalSize.width() ); + if( finalSize.height() > tickLabelsSize->height() ) + tickLabelsSize->setHeight( finalSize.height() ); } /* end of 'src/axis/axis.cpp' */ - /* including file 'src/scatterstyle.cpp', size 17450 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -9917,12 +10081,8 @@ void QCPAxisPainterPrivate::getMaxTickLabelSize(const QFont &font, const QString Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited from the plottable that uses this scatter style. */ -QCPScatterStyle::QCPScatterStyle() : - mSize(6), - mShape(ssNone), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) +QCPScatterStyle::QCPScatterStyle() + : mSize( 6 ), mShape( ssNone ), mPen( Qt::NoPen ), mBrush( Qt::NoBrush ), mPenDefined( false ) { } @@ -9933,12 +10093,8 @@ QCPScatterStyle::QCPScatterStyle() : Since the pen is undefined (\ref isPenDefined returns false), the scatter color will be inherited from the plottable that uses this scatter style. */ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : - mSize(size), - mShape(shape), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPenDefined(false) +QCPScatterStyle::QCPScatterStyle( ScatterShape shape, double size ) + : mSize( size ), mShape( shape ), mPen( Qt::NoPen ), mBrush( Qt::NoBrush ), mPenDefined( false ) { } @@ -9946,12 +10102,8 @@ QCPScatterStyle::QCPScatterStyle(ScatterShape shape, double size) : Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, and size to \a size. No brush is defined, i.e. the scatter point will not be filled. */ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(Qt::NoBrush), - mPenDefined(true) +QCPScatterStyle::QCPScatterStyle( ScatterShape shape, const QColor& color, double size ) + : mSize( size ), mShape( shape ), mPen( QPen( color ) ), mBrush( Qt::NoBrush ), mPenDefined( true ) { } @@ -9959,12 +10111,8 @@ QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, double Creates a new QCPScatterStyle instance with shape set to \a shape, the pen color set to \a color, the brush color to \a fill (with a solid pattern), and size to \a size. */ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size) : - mSize(size), - mShape(shape), - mPen(QPen(color)), - mBrush(QBrush(fill)), - mPenDefined(true) +QCPScatterStyle::QCPScatterStyle( ScatterShape shape, const QColor& color, const QColor& fill, double size ) + : mSize( size ), mShape( shape ), mPen( QPen( color ) ), mBrush( QBrush( fill ) ), mPenDefined( true ) { } @@ -9983,12 +10131,8 @@ QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QColor &color, const instead of just Qt::blue, to clearly point out to the compiler that this constructor is wanted. */ -QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(shape), - mPen(pen), - mBrush(brush), - mPenDefined(pen.style() != Qt::NoPen) +QCPScatterStyle::QCPScatterStyle( ScatterShape shape, const QPen& pen, const QBrush& brush, double size ) + : mSize( size ), mShape( shape ), mPen( pen ), mBrush( brush ), mPenDefined( pen.style() != Qt::NoPen ) { } @@ -9996,13 +10140,8 @@ QCPScatterStyle::QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBru Creates a new QCPScatterStyle instance which will show the specified \a pixmap. The scatter shape is set to \ref ssPixmap. */ -QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : - mSize(5), - mShape(ssPixmap), - mPen(Qt::NoPen), - mBrush(Qt::NoBrush), - mPixmap(pixmap), - mPenDefined(false) +QCPScatterStyle::QCPScatterStyle( const QPixmap& pixmap ) + : mSize( 5 ), mShape( ssPixmap ), mPen( Qt::NoPen ), mBrush( Qt::NoBrush ), mPixmap( pixmap ), mPenDefined( false ) { } @@ -10015,38 +10154,33 @@ QCPScatterStyle::QCPScatterStyle(const QPixmap &pixmap) : factor of \a size/6.0. Since the default \a size is 6, the custom path will appear in its original size by default. To for example double the size of the path, set \a size to 12. */ -QCPScatterStyle::QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush, double size) : - mSize(size), - mShape(ssCustom), - mPen(pen), - mBrush(brush), - mCustomPath(customPath), - mPenDefined(pen.style() != Qt::NoPen) +QCPScatterStyle::QCPScatterStyle( const QPainterPath& customPath, const QPen& pen, const QBrush& brush, double size ) + : mSize( size ), mShape( ssCustom ), mPen( pen ), mBrush( brush ), mCustomPath( customPath ), mPenDefined( pen.style() != Qt::NoPen ) { } /*! Copies the specified \a properties from the \a other scatter style to this scatter style. */ -void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperties properties) +void QCPScatterStyle::setFromOther( const QCPScatterStyle& other, ScatterProperties properties ) { - if (properties.testFlag(spPen)) + if( properties.testFlag( spPen ) ) { - setPen(other.pen()); - if (!other.isPenDefined()) + setPen( other.pen() ); + if( !other.isPenDefined() ) undefinePen(); } - if (properties.testFlag(spBrush)) - setBrush(other.brush()); - if (properties.testFlag(spSize)) - setSize(other.size()); - if (properties.testFlag(spShape)) + if( properties.testFlag( spBrush ) ) + setBrush( other.brush() ); + if( properties.testFlag( spSize ) ) + setSize( other.size() ); + if( properties.testFlag( spShape ) ) { - setShape(other.shape()); - if (other.shape() == ssPixmap) - setPixmap(other.pixmap()); - else if (other.shape() == ssCustom) - setCustomPath(other.customPath()); + setShape( other.shape() ); + if( other.shape() == ssPixmap ) + setPixmap( other.pixmap() ); + else if( other.shape() == ssCustom ) + setCustomPath( other.customPath() ); } } @@ -10055,7 +10189,7 @@ void QCPScatterStyle::setFromOther(const QCPScatterStyle &other, ScatterProperti \see setShape */ -void QCPScatterStyle::setSize(double size) +void QCPScatterStyle::setSize( double size ) { mSize = size; } @@ -10068,7 +10202,7 @@ void QCPScatterStyle::setSize(double size) \see setSize */ -void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) +void QCPScatterStyle::setShape( QCPScatterStyle::ScatterShape shape ) { mShape = shape; } @@ -10082,7 +10216,7 @@ void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) \see setBrush */ -void QCPScatterStyle::setPen(const QPen &pen) +void QCPScatterStyle::setPen( const QPen& pen ) { mPenDefined = true; mPen = pen; @@ -10094,7 +10228,7 @@ void QCPScatterStyle::setPen(const QPen &pen) \see setPen */ -void QCPScatterStyle::setBrush(const QBrush &brush) +void QCPScatterStyle::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -10106,9 +10240,9 @@ void QCPScatterStyle::setBrush(const QBrush &brush) The scatter shape is automatically set to \ref ssPixmap. */ -void QCPScatterStyle::setPixmap(const QPixmap &pixmap) +void QCPScatterStyle::setPixmap( const QPixmap& pixmap ) { - setShape(ssPixmap); + setShape( ssPixmap ); mPixmap = pixmap; } @@ -10117,9 +10251,9 @@ void QCPScatterStyle::setPixmap(const QPixmap &pixmap) The scatter shape is automatically set to \ref ssCustom. */ -void QCPScatterStyle::setCustomPath(const QPainterPath &customPath) +void QCPScatterStyle::setCustomPath( const QPainterPath& customPath ) { - setShape(ssCustom); + setShape( ssCustom ); mCustomPath = customPath; } @@ -10143,10 +10277,10 @@ void QCPScatterStyle::undefinePen() \see drawShape */ -void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const +void QCPScatterStyle::applyTo( QCPPainter* painter, const QPen& defaultPen ) const { - painter->setPen(mPenDefined ? mPen : defaultPen); - painter->setBrush(mBrush); + painter->setPen( mPenDefined ? mPen : defaultPen ); + painter->setBrush( mBrush ); } /*! @@ -10157,146 +10291,130 @@ void QCPScatterStyle::applyTo(QCPPainter *painter, const QPen &defaultPen) const \see applyTo */ -void QCPScatterStyle::drawShape(QCPPainter *painter, const QPointF &pos) const +void QCPScatterStyle::drawShape( QCPPainter* painter, const QPointF& pos ) const { - drawShape(painter, pos.x(), pos.y()); + drawShape( painter, pos.x(), pos.y() ); } /*! \overload Draws the scatter shape with \a painter at position \a x and \a y. */ -void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const +void QCPScatterStyle::drawShape( QCPPainter* painter, double x, double y ) const { - double w = mSize/2.0; - switch (mShape) + double w = mSize / 2.0; + switch( mShape ) { - case ssNone: break; - case ssDot: - { - painter->drawLine(QPointF(x, y), QPointF(x+0.0001, y)); - break; - } - case ssCross: - { - painter->drawLine(QLineF(x-w, y-w, x+w, y+w)); - painter->drawLine(QLineF(x-w, y+w, x+w, y-w)); - break; - } - case ssPlus: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCircle: - { - painter->drawEllipse(QPointF(x , y), w, w); - break; - } - case ssDisc: - { - QBrush b = painter->brush(); - painter->setBrush(painter->pen().color()); - painter->drawEllipse(QPointF(x , y), w, w); - painter->setBrush(b); - break; - } - case ssSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - break; - } - case ssDiamond: - { - QPointF lineArray[4] = {QPointF(x-w, y), - QPointF( x, y-w), - QPointF(x+w, y), - QPointF( x, y+w)}; - painter->drawPolygon(lineArray, 4); - break; - } - case ssStar: - { - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.707, x+w*0.707, y-w*0.707)); - break; - } - case ssTriangle: - { - QPointF lineArray[3] = {QPointF(x-w, y+0.755*w), - QPointF(x+w, y+0.755*w), - QPointF( x, y-0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssTriangleInverted: - { - QPointF lineArray[3] = {QPointF(x-w, y-0.755*w), - QPointF(x+w, y-0.755*w), - QPointF( x, y+0.977*w)}; - painter->drawPolygon(lineArray, 3); - break; - } - case ssCrossSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y-w, x+w*0.95, y+w*0.95)); - painter->drawLine(QLineF(x-w, y+w*0.95, x+w*0.95, y-w)); - break; - } - case ssPlusSquare: - { - painter->drawRect(QRectF(x-w, y-w, mSize, mSize)); - painter->drawLine(QLineF(x-w, y, x+w*0.95, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssCrossCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w*0.707, y-w*0.707, x+w*0.670, y+w*0.670)); - painter->drawLine(QLineF(x-w*0.707, y+w*0.670, x+w*0.670, y-w*0.707)); - break; - } - case ssPlusCircle: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x-w, y, x+w, y)); - painter->drawLine(QLineF( x, y+w, x, y-w)); - break; - } - case ssPeace: - { - painter->drawEllipse(QPointF(x, y), w, w); - painter->drawLine(QLineF(x, y-w, x, y+w)); - painter->drawLine(QLineF(x, y, x-w*0.707, y+w*0.707)); - painter->drawLine(QLineF(x, y, x+w*0.707, y+w*0.707)); - break; - } - case ssPixmap: - { - const double widthHalf = mPixmap.width()*0.5; - const double heightHalf = mPixmap.height()*0.5; -#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) - const QRectF clipRect = painter->clipRegion().boundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); + case ssNone: + break; + case ssDot: { + painter->drawLine( QPointF( x, y ), QPointF( x + 0.0001, y ) ); + break; + } + case ssCross: { + painter->drawLine( QLineF( x - w, y - w, x + w, y + w ) ); + painter->drawLine( QLineF( x - w, y + w, x + w, y - w ) ); + break; + } + case ssPlus: { + painter->drawLine( QLineF( x - w, y, x + w, y ) ); + painter->drawLine( QLineF( x, y + w, x, y - w ) ); + break; + } + case ssCircle: { + painter->drawEllipse( QPointF( x, y ), w, w ); + break; + } + case ssDisc: { + QBrush b = painter->brush(); + painter->setBrush( painter->pen().color() ); + painter->drawEllipse( QPointF( x, y ), w, w ); + painter->setBrush( b ); + break; + } + case ssSquare: { + painter->drawRect( QRectF( x - w, y - w, mSize, mSize ) ); + break; + } + case ssDiamond: { + QPointF lineArray[4] = { QPointF( x - w, y ), + QPointF( x, y - w ), + QPointF( x + w, y ), + QPointF( x, y + w ) }; + painter->drawPolygon( lineArray, 4 ); + break; + } + case ssStar: { + painter->drawLine( QLineF( x - w, y, x + w, y ) ); + painter->drawLine( QLineF( x, y + w, x, y - w ) ); + painter->drawLine( QLineF( x - w * 0.707, y - w * 0.707, x + w * 0.707, y + w * 0.707 ) ); + painter->drawLine( QLineF( x - w * 0.707, y + w * 0.707, x + w * 0.707, y - w * 0.707 ) ); + break; + } + case ssTriangle: { + QPointF lineArray[3] = { QPointF( x - w, y + 0.755 * w ), + QPointF( x + w, y + 0.755 * w ), + QPointF( x, y - 0.977 * w ) }; + painter->drawPolygon( lineArray, 3 ); + break; + } + case ssTriangleInverted: { + QPointF lineArray[3] = { QPointF( x - w, y - 0.755 * w ), + QPointF( x + w, y - 0.755 * w ), + QPointF( x, y + 0.977 * w ) }; + painter->drawPolygon( lineArray, 3 ); + break; + } + case ssCrossSquare: { + painter->drawRect( QRectF( x - w, y - w, mSize, mSize ) ); + painter->drawLine( QLineF( x - w, y - w, x + w * 0.95, y + w * 0.95 ) ); + painter->drawLine( QLineF( x - w, y + w * 0.95, x + w * 0.95, y - w ) ); + break; + } + case ssPlusSquare: { + painter->drawRect( QRectF( x - w, y - w, mSize, mSize ) ); + painter->drawLine( QLineF( x - w, y, x + w * 0.95, y ) ); + painter->drawLine( QLineF( x, y + w, x, y - w ) ); + break; + } + case ssCrossCircle: { + painter->drawEllipse( QPointF( x, y ), w, w ); + painter->drawLine( QLineF( x - w * 0.707, y - w * 0.707, x + w * 0.670, y + w * 0.670 ) ); + painter->drawLine( QLineF( x - w * 0.707, y + w * 0.670, x + w * 0.670, y - w * 0.707 ) ); + break; + } + case ssPlusCircle: { + painter->drawEllipse( QPointF( x, y ), w, w ); + painter->drawLine( QLineF( x - w, y, x + w, y ) ); + painter->drawLine( QLineF( x, y + w, x, y - w ) ); + break; + } + case ssPeace: { + painter->drawEllipse( QPointF( x, y ), w, w ); + painter->drawLine( QLineF( x, y - w, x, y + w ) ); + painter->drawLine( QLineF( x, y, x - w * 0.707, y + w * 0.707 ) ); + painter->drawLine( QLineF( x, y, x + w * 0.707, y + w * 0.707 ) ); + break; + } + case ssPixmap: { + const double widthHalf = mPixmap.width() * 0.5; + const double heightHalf = mPixmap.height() * 0.5; +#if QT_VERSION < QT_VERSION_CHECK( 4, 8, 0 ) + const QRectF clipRect = painter->clipRegion().boundingRect().adjusted( -widthHalf, -heightHalf, widthHalf, heightHalf ); #else - const QRectF clipRect = painter->clipBoundingRect().adjusted(-widthHalf, -heightHalf, widthHalf, heightHalf); + const QRectF clipRect = painter->clipBoundingRect().adjusted( -widthHalf, -heightHalf, widthHalf, heightHalf ); #endif - if (clipRect.contains(x, y)) - painter->drawPixmap(x-widthHalf, y-heightHalf, mPixmap); - break; - } - case ssCustom: - { - QTransform oldTransform = painter->transform(); - painter->translate(x, y); - painter->scale(mSize/6.0, mSize/6.0); - painter->drawPath(mCustomPath); - painter->setTransform(oldTransform); - break; - } + if( clipRect.contains( x, y ) ) + painter->drawPixmap( x - widthHalf, y - heightHalf, mPixmap ); + break; + } + case ssCustom: { + QTransform oldTransform = painter->transform(); + painter->translate( x, y ); + painter->scale( mSize / 6.0, mSize / 6.0 ); + painter->drawPath( mCustomPath ); + painter->setTransform( oldTransform ); + break; + } } } /* end of 'src/scatterstyle.cpp' */ @@ -10339,12 +10457,8 @@ void QCPScatterStyle::drawShape(QCPPainter *painter, double x, double y) const /*! Creates a new QCPSelectionDecorator instance with default values */ -QCPSelectionDecorator::QCPSelectionDecorator() : - mPen(QColor(80, 80, 255), 2.5), - mBrush(Qt::NoBrush), - mScatterStyle(), - mUsedScatterProperties(QCPScatterStyle::spNone), - mPlottable(0) +QCPSelectionDecorator::QCPSelectionDecorator() + : mPen( QColor( 80, 80, 255 ), 2.5 ), mBrush( Qt::NoBrush ), mScatterStyle(), mUsedScatterProperties( QCPScatterStyle::spNone ), mPlottable( 0 ) { } @@ -10355,7 +10469,7 @@ QCPSelectionDecorator::~QCPSelectionDecorator() /*! Sets the pen that will be used by the parent plottable to draw selected data segments. */ -void QCPSelectionDecorator::setPen(const QPen &pen) +void QCPSelectionDecorator::setPen( const QPen& pen ) { mPen = pen; } @@ -10363,7 +10477,7 @@ void QCPSelectionDecorator::setPen(const QPen &pen) /*! Sets the brush that will be used by the parent plottable to draw selected data segments. */ -void QCPSelectionDecorator::setBrush(const QBrush &brush) +void QCPSelectionDecorator::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -10375,10 +10489,10 @@ void QCPSelectionDecorator::setBrush(const QBrush &brush) \a usedProperties specifies which parts of the passed \a scatterStyle will be used by the plottable. The used properties can also be changed via \ref setUsedScatterProperties. */ -void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties) +void QCPSelectionDecorator::setScatterStyle( const QCPScatterStyle& scatterStyle, QCPScatterStyle::ScatterProperties usedProperties ) { mScatterStyle = scatterStyle; - setUsedScatterProperties(usedProperties); + setUsedScatterProperties( usedProperties ); } /*! @@ -10388,7 +10502,7 @@ void QCPSelectionDecorator::setScatterStyle(const QCPScatterStyle &scatterStyle, \see QCPScatterStyle::ScatterProperty */ -void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties) +void QCPSelectionDecorator::setUsedScatterProperties( const QCPScatterStyle::ScatterProperties& properties ) { mUsedScatterProperties = properties; } @@ -10398,9 +10512,9 @@ void QCPSelectionDecorator::setUsedScatterProperties(const QCPScatterStyle::Scat \see applyBrush, getFinalScatterStyle */ -void QCPSelectionDecorator::applyPen(QCPPainter *painter) const +void QCPSelectionDecorator::applyPen( QCPPainter* painter ) const { - painter->setPen(mPen); + painter->setPen( mPen ); } /*! @@ -10408,9 +10522,9 @@ void QCPSelectionDecorator::applyPen(QCPPainter *painter) const \see applyPen, getFinalScatterStyle */ -void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const +void QCPSelectionDecorator::applyBrush( QCPPainter* painter ) const { - painter->setBrush(mBrush); + painter->setBrush( mBrush ); } /*! @@ -10421,17 +10535,17 @@ void QCPSelectionDecorator::applyBrush(QCPPainter *painter) const \see applyPen, applyBrush, setScatterStyle */ -QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const +QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle( const QCPScatterStyle& unselectedStyle ) const { - QCPScatterStyle result(unselectedStyle); - result.setFromOther(mScatterStyle, mUsedScatterProperties); - + QCPScatterStyle result( unselectedStyle ); + result.setFromOther( mScatterStyle, mUsedScatterProperties ); + // if style shall inherit pen from plottable (has no own pen defined), give it the selected // plottable pen explicitly, so it doesn't use the unselected plottable pen when used in the // plottable: - if (!result.isPenDefined()) - result.setPen(mPen); - + if( !result.isPenDefined() ) + result.setPen( mPen ); + return result; } @@ -10439,11 +10553,11 @@ QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle(const QCPScatterStyl Copies all properties (e.g. color, fill, scatter style) of the \a other selection decorator to this selection decorator. */ -void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) +void QCPSelectionDecorator::copyFrom( const QCPSelectionDecorator* other ) { - setPen(other->pen()); - setBrush(other->brush()); - setScatterStyle(other->scatterStyle(), other->usedScatterProperties()); + setPen( other->pen() ); + setBrush( other->brush() ); + setScatterStyle( other->scatterStyle(), other->usedScatterProperties() ); } /*! @@ -10454,10 +10568,10 @@ void QCPSelectionDecorator::copyFrom(const QCPSelectionDecorator *other) The default base class implementation of \ref QCPSelectionDecorator has no special decoration, so this method does nothing. */ -void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +void QCPSelectionDecorator::drawDecoration( QCPPainter* painter, QCPDataSelection selection ) { - Q_UNUSED(painter) - Q_UNUSED(selection) + Q_UNUSED( painter ) + Q_UNUSED( selection ) } /*! \internal @@ -10469,20 +10583,20 @@ void QCPSelectionDecorator::drawDecoration(QCPPainter *painter, QCPDataSelection If the selection decorator was already added to a different plottable before, this method aborts the registration and returns false. */ -bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottable) +bool QCPSelectionDecorator::registerWithPlottable( QCPAbstractPlottable* plottable ) { - if (!mPlottable) + if( !mPlottable ) { mPlottable = plottable; return true; - } else + } + else { - qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast(mPlottable); + qDebug() << Q_FUNC_INFO << "This selection decorator is already registered with plottable:" << reinterpret_cast( mPlottable ); return false; } } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractPlottable //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -10698,30 +10812,21 @@ bool QCPSelectionDecorator::registerWithPlottable(QCPAbstractPlottable *plottabl You probably want one of the subclasses like \ref QCPGraph or \ref QCPCurve instead. */ -QCPAbstractPlottable::QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis->axisRect()), - mName(), - mAntialiasedFill(true), - mAntialiasedScatters(true), - mPen(Qt::black), - mBrush(Qt::NoBrush), - mKeyAxis(keyAxis), - mValueAxis(valueAxis), - mSelectable(QCP::stWhole), - mSelectionDecorator(0) +QCPAbstractPlottable::QCPAbstractPlottable( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPLayerable( keyAxis->parentPlot(), QString(), keyAxis->axisRect() ), mName(), mAntialiasedFill( true ), mAntialiasedScatters( true ), mPen( Qt::black ), mBrush( Qt::NoBrush ), mKeyAxis( keyAxis ), mValueAxis( valueAxis ), mSelectable( QCP::stWhole ), mSelectionDecorator( 0 ) { - if (keyAxis->parentPlot() != valueAxis->parentPlot()) + if( keyAxis->parentPlot() != valueAxis->parentPlot() ) qDebug() << Q_FUNC_INFO << "Parent plot of keyAxis is not the same as that of valueAxis."; - if (keyAxis->orientation() == valueAxis->orientation()) + if( keyAxis->orientation() == valueAxis->orientation() ) qDebug() << Q_FUNC_INFO << "keyAxis and valueAxis must be orthogonal to each other."; - - mParentPlot->registerPlottable(this); - setSelectionDecorator(new QCPSelectionDecorator); + + mParentPlot->registerPlottable( this ); + setSelectionDecorator( new QCPSelectionDecorator ); } QCPAbstractPlottable::~QCPAbstractPlottable() { - if (mSelectionDecorator) + if( mSelectionDecorator ) { delete mSelectionDecorator; mSelectionDecorator = 0; @@ -10732,7 +10837,7 @@ QCPAbstractPlottable::~QCPAbstractPlottable() The name is the textual representation of this plottable as it is displayed in the legend (\ref QCPLegend). It may contain any UTF-8 characters, including newlines. */ -void QCPAbstractPlottable::setName(const QString &name) +void QCPAbstractPlottable::setName( const QString& name ) { mName = name; } @@ -10743,7 +10848,7 @@ void QCPAbstractPlottable::setName(const QString &name) Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref QCustomPlot::setNotAntialiasedElements. */ -void QCPAbstractPlottable::setAntialiasedFill(bool enabled) +void QCPAbstractPlottable::setAntialiasedFill( bool enabled ) { mAntialiasedFill = enabled; } @@ -10754,7 +10859,7 @@ void QCPAbstractPlottable::setAntialiasedFill(bool enabled) Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref QCustomPlot::setNotAntialiasedElements. */ -void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) +void QCPAbstractPlottable::setAntialiasedScatters( bool enabled ) { mAntialiasedScatters = enabled; } @@ -10767,7 +10872,7 @@ void QCPAbstractPlottable::setAntialiasedScatters(bool enabled) \see setBrush */ -void QCPAbstractPlottable::setPen(const QPen &pen) +void QCPAbstractPlottable::setPen( const QPen& pen ) { mPen = pen; } @@ -10781,7 +10886,7 @@ void QCPAbstractPlottable::setPen(const QPen &pen) \see setPen */ -void QCPAbstractPlottable::setBrush(const QBrush &brush) +void QCPAbstractPlottable::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -10797,7 +10902,7 @@ void QCPAbstractPlottable::setBrush(const QBrush &brush) \see setValueAxis */ -void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) +void QCPAbstractPlottable::setKeyAxis( QCPAxis* axis ) { mKeyAxis = axis; } @@ -10813,12 +10918,11 @@ void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) \see setKeyAxis */ -void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) +void QCPAbstractPlottable::setValueAxis( QCPAxis* axis ) { mValueAxis = axis; } - /*! Sets which data ranges of this plottable are selected. Selected data ranges are drawn differently (e.g. color) in the plot. This can be controlled via the selection decorator (see \ref @@ -10837,14 +10941,14 @@ void QCPAbstractPlottable::setValueAxis(QCPAxis *axis) \see setSelectable, selectTest */ -void QCPAbstractPlottable::setSelection(QCPDataSelection selection) +void QCPAbstractPlottable::setSelection( QCPDataSelection selection ) { - selection.enforceType(mSelectable); - if (mSelection != selection) + selection.enforceType( mSelectable ); + if( mSelection != selection ) { mSelection = selection; - emit selectionChanged(selected()); - emit selectionChanged(mSelection); + emit selectionChanged( selected() ); + emit selectionChanged( mSelection ); } } @@ -10857,17 +10961,18 @@ void QCPAbstractPlottable::setSelection(QCPDataSelection selection) The currently set decorator can be accessed via \ref selectionDecorator. */ -void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorator) +void QCPAbstractPlottable::setSelectionDecorator( QCPSelectionDecorator* decorator ) { - if (decorator) + if( decorator ) { - if (decorator->registerWithPlottable(this)) + if( decorator->registerWithPlottable( this ) ) { - if (mSelectionDecorator) // delete old decorator if necessary + if( mSelectionDecorator ) // delete old decorator if necessary delete mSelectionDecorator; mSelectionDecorator = decorator; } - } else if (mSelectionDecorator) // just clear decorator + } + else if( mSelectionDecorator ) // just clear decorator { delete mSelectionDecorator; mSelectionDecorator = 0; @@ -10884,23 +10989,22 @@ void QCPAbstractPlottable::setSelectionDecorator(QCPSelectionDecorator *decorato \see setSelection, QCP::SelectionType */ -void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) +void QCPAbstractPlottable::setSelectable( QCP::SelectionType selectable ) { - if (mSelectable != selectable) + if( mSelectable != selectable ) { mSelectable = selectable; QCPDataSelection oldSelection = mSelection; - mSelection.enforceType(mSelectable); - emit selectableChanged(mSelectable); - if (mSelection != oldSelection) + mSelection.enforceType( mSelectable ); + emit selectableChanged( mSelectable ); + if( mSelection != oldSelection ) { - emit selectionChanged(selected()); - emit selectionChanged(mSelection); + emit selectionChanged( selected() ); + emit selectionChanged( mSelection ); } } } - /*! Convenience function for transforming a key/value pair to pixels on the QCustomPlot surface, taking the orientations of the axes associated with this plottable into account (e.g. whether key @@ -10910,20 +11014,25 @@ void QCPAbstractPlottable::setSelectable(QCP::SelectionType selectable) \see pixelsToCoords, QCPAxis::coordToPixel */ -void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, double &y) const +void QCPAbstractPlottable::coordsToPixels( double key, double value, double& x, double& y ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - x = keyAxis->coordToPixel(key); - y = valueAxis->coordToPixel(value); - } else + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + if( keyAxis->orientation() == Qt::Horizontal ) { - y = keyAxis->coordToPixel(key); - x = valueAxis->coordToPixel(value); + x = keyAxis->coordToPixel( key ); + y = valueAxis->coordToPixel( value ); + } + else + { + y = keyAxis->coordToPixel( key ); + x = valueAxis->coordToPixel( value ); } } @@ -10931,16 +11040,20 @@ void QCPAbstractPlottable::coordsToPixels(double key, double value, double &x, d Transforms the given \a key and \a value to pixel coordinates and returns them in a QPointF. */ -const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) const +const QPointF QCPAbstractPlottable::coordsToPixels( double key, double value ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(key), valueAxis->coordToPixel(value)); + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QPointF(); + } + + if( keyAxis->orientation() == Qt::Horizontal ) + return QPointF( keyAxis->coordToPixel( key ), valueAxis->coordToPixel( value ) ); else - return QPointF(valueAxis->coordToPixel(value), keyAxis->coordToPixel(key)); + return QPointF( valueAxis->coordToPixel( value ), keyAxis->coordToPixel( key ) ); } /*! @@ -10952,20 +11065,25 @@ const QPointF QCPAbstractPlottable::coordsToPixels(double key, double value) con \see coordsToPixels, QCPAxis::coordToPixel */ -void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, double &value) const +void QCPAbstractPlottable::pixelsToCoords( double x, double y, double& key, double& value ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - key = keyAxis->pixelToCoord(x); - value = valueAxis->pixelToCoord(y); - } else + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + if( keyAxis->orientation() == Qt::Horizontal ) { - key = keyAxis->pixelToCoord(y); - value = valueAxis->pixelToCoord(x); + key = keyAxis->pixelToCoord( x ); + value = valueAxis->pixelToCoord( y ); + } + else + { + key = keyAxis->pixelToCoord( y ); + value = valueAxis->pixelToCoord( x ); } } @@ -10973,9 +11091,9 @@ void QCPAbstractPlottable::pixelsToCoords(double x, double y, double &key, doubl Returns the pixel input \a pixelPos as plot coordinates \a key and \a value. */ -void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const +void QCPAbstractPlottable::pixelsToCoords( const QPointF& pixelPos, double& key, double& value ) const { - pixelsToCoords(pixelPos.x(), pixelPos.y(), key, value); + pixelsToCoords( pixelPos.x(), pixelPos.y(), key, value ); } /*! @@ -10991,10 +11109,10 @@ void QCPAbstractPlottable::pixelsToCoords(const QPointF &pixelPos, double &key, \see rescaleKeyAxis, rescaleValueAxis, QCustomPlot::rescaleAxes, QCPAxis::rescale */ -void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const +void QCPAbstractPlottable::rescaleAxes( bool onlyEnlarge ) const { - rescaleKeyAxis(onlyEnlarge); - rescaleValueAxis(onlyEnlarge); + rescaleKeyAxis( onlyEnlarge ); + rescaleValueAxis( onlyEnlarge ); } /*! @@ -11002,35 +11120,40 @@ void QCPAbstractPlottable::rescaleAxes(bool onlyEnlarge) const See \ref rescaleAxes for detailed behaviour. */ -void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const +void QCPAbstractPlottable::rescaleKeyAxis( bool onlyEnlarge ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (keyAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getKeyRange(foundRange, signDomain); - if (foundRange) + QCPAxis* keyAxis = mKeyAxis.data(); + if( !keyAxis ) { - if (onlyEnlarge) - newRange.expand(keyAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + qDebug() << Q_FUNC_INFO << "invalid key axis"; + return; + } + + QCP::SignDomain signDomain = QCP::sdBoth; + if( keyAxis->scaleType() == QCPAxis::stLogarithmic ) + signDomain = ( keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive ); + + bool foundRange; + QCPRange newRange = getKeyRange( foundRange, signDomain ); + if( foundRange ) + { + if( onlyEnlarge ) + newRange.expand( keyAxis->range() ); + if( !QCPRange::validRange( newRange ) ) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (keyAxis->scaleType() == QCPAxis::stLinear) + double center = ( newRange.lower + newRange.upper ) * 0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if( keyAxis->scaleType() == QCPAxis::stLinear ) { - newRange.lower = center-keyAxis->range().size()/2.0; - newRange.upper = center+keyAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic + newRange.lower = center - keyAxis->range().size() / 2.0; + newRange.upper = center + keyAxis->range().size() / 2.0; + } + else // scaleType() == stLogarithmic { - newRange.lower = center/qSqrt(keyAxis->range().upper/keyAxis->range().lower); - newRange.upper = center*qSqrt(keyAxis->range().upper/keyAxis->range().lower); + newRange.lower = center / qSqrt( keyAxis->range().upper / keyAxis->range().lower ); + newRange.upper = center * qSqrt( keyAxis->range().upper / keyAxis->range().lower ); } } - keyAxis->setRange(newRange); + keyAxis->setRange( newRange ); } } @@ -11044,36 +11167,41 @@ void QCPAbstractPlottable::rescaleKeyAxis(bool onlyEnlarge) const See \ref rescaleAxes for detailed behaviour. */ -void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const +void QCPAbstractPlottable::rescaleValueAxis( bool onlyEnlarge, bool inKeyRange ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - QCP::SignDomain signDomain = QCP::sdBoth; - if (valueAxis->scaleType() == QCPAxis::stLogarithmic) - signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); - - bool foundRange; - QCPRange newRange = getValueRange(foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange()); - if (foundRange) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - if (onlyEnlarge) - newRange.expand(valueAxis->range()); - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + QCP::SignDomain signDomain = QCP::sdBoth; + if( valueAxis->scaleType() == QCPAxis::stLogarithmic ) + signDomain = ( valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive ); + + bool foundRange; + QCPRange newRange = getValueRange( foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange() ); + if( foundRange ) + { + if( onlyEnlarge ) + newRange.expand( valueAxis->range() ); + if( !QCPRange::validRange( newRange ) ) // likely due to range being zero (plottable has only constant data in this axis dimension), shift current range to at least center the plottable { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (valueAxis->scaleType() == QCPAxis::stLinear) + double center = ( newRange.lower + newRange.upper ) * 0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if( valueAxis->scaleType() == QCPAxis::stLinear ) { - newRange.lower = center-valueAxis->range().size()/2.0; - newRange.upper = center+valueAxis->range().size()/2.0; - } else // scaleType() == stLogarithmic + newRange.lower = center - valueAxis->range().size() / 2.0; + newRange.upper = center + valueAxis->range().size() / 2.0; + } + else // scaleType() == stLogarithmic { - newRange.lower = center/qSqrt(valueAxis->range().upper/valueAxis->range().lower); - newRange.upper = center*qSqrt(valueAxis->range().upper/valueAxis->range().lower); + newRange.lower = center / qSqrt( valueAxis->range().upper / valueAxis->range().lower ); + newRange.upper = center * qSqrt( valueAxis->range().upper / valueAxis->range().lower ); } } - valueAxis->setRange(newRange); + valueAxis->setRange( newRange ); } } @@ -11091,24 +11219,25 @@ void QCPAbstractPlottable::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) c \see removeFromLegend, QCPLegend::addItem */ -bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) +bool QCPAbstractPlottable::addToLegend( QCPLegend* legend ) { - if (!legend) + if( !legend ) { qDebug() << Q_FUNC_INFO << "passed legend is null"; return false; } - if (legend->parentPlot() != mParentPlot) + if( legend->parentPlot() != mParentPlot ) { qDebug() << Q_FUNC_INFO << "passed legend isn't in the same QCustomPlot as this plottable"; return false; } - - if (!legend->hasItemWithPlottable(this)) + + if( !legend->hasItemWithPlottable( this ) ) { - legend->addItem(new QCPPlottableLegendItem(legend, this)); + legend->addItem( new QCPPlottableLegendItem( legend, this ) ); return true; - } else + } + else return false; } @@ -11120,10 +11249,10 @@ bool QCPAbstractPlottable::addToLegend(QCPLegend *legend) */ bool QCPAbstractPlottable::addToLegend() { - if (!mParentPlot || !mParentPlot->legend) + if( !mParentPlot || !mParentPlot->legend ) return false; else - return addToLegend(mParentPlot->legend); + return addToLegend( mParentPlot->legend ); } /*! \overload @@ -11136,16 +11265,16 @@ bool QCPAbstractPlottable::addToLegend() \see addToLegend, QCPLegend::removeItem */ -bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const +bool QCPAbstractPlottable::removeFromLegend( QCPLegend* legend ) const { - if (!legend) + if( !legend ) { qDebug() << Q_FUNC_INFO << "passed legend is null"; return false; } - - if (QCPPlottableLegendItem *lip = legend->itemWithPlottable(this)) - return legend->removeItem(lip); + + if( QCPPlottableLegendItem* lip = legend->itemWithPlottable( this ) ) + return legend->removeItem( lip ); else return false; } @@ -11158,16 +11287,16 @@ bool QCPAbstractPlottable::removeFromLegend(QCPLegend *legend) const */ bool QCPAbstractPlottable::removeFromLegend() const { - if (!mParentPlot || !mParentPlot->legend) + if( !mParentPlot || !mParentPlot->legend ) return false; else - return removeFromLegend(mParentPlot->legend); + return removeFromLegend( mParentPlot->legend ); } /* inherits documentation from base class */ QRect QCPAbstractPlottable::clipRect() const { - if (mKeyAxis && mValueAxis) + if( mKeyAxis && mValueAxis ) return mKeyAxis.data()->axisRect()->rect() & mValueAxis.data()->axisRect()->rect(); else return QRect(); @@ -11194,9 +11323,9 @@ QCP::Interaction QCPAbstractPlottable::selectionCategory() const \see setAntialiased, applyFillAntialiasingHint, applyScattersAntialiasingHint */ -void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPAbstractPlottable::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); + applyAntialiasingHint( painter, mAntialiased, QCP::aePlottables ); } /*! \internal @@ -11210,9 +11339,9 @@ void QCPAbstractPlottable::applyDefaultAntialiasingHint(QCPPainter *painter) con \see setAntialiased, applyDefaultAntialiasingHint, applyScattersAntialiasingHint */ -void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const +void QCPAbstractPlottable::applyFillAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); + applyAntialiasingHint( painter, mAntialiasedFill, QCP::aeFills ); } /*! \internal @@ -11226,56 +11355,57 @@ void QCPAbstractPlottable::applyFillAntialiasingHint(QCPPainter *painter) const \see setAntialiased, applyFillAntialiasingHint, applyDefaultAntialiasingHint */ -void QCPAbstractPlottable::applyScattersAntialiasingHint(QCPPainter *painter) const +void QCPAbstractPlottable::applyScattersAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); + applyAntialiasingHint( painter, mAntialiasedScatters, QCP::aeScatters ); } /* inherits documentation from base class */ -void QCPAbstractPlottable::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPAbstractPlottable::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - - if (mSelectable != QCP::stNone) + Q_UNUSED( event ) + + if( mSelectable != QCP::stNone ) { QCPDataSelection newSelection = details.value(); QCPDataSelection selectionBefore = mSelection; - if (additive) + if( additive ) { - if (mSelectable == QCP::stWhole) // in whole selection mode, we toggle to no selection even if currently unselected point was hit + if( mSelectable == QCP::stWhole ) // in whole selection mode, we toggle to no selection even if currently unselected point was hit { - if (selected()) - setSelection(QCPDataSelection()); + if( selected() ) + setSelection( QCPDataSelection() ); else - setSelection(newSelection); - } else // in all other selection modes we toggle selections of homogeneously selected/unselected segments - { - if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection - setSelection(mSelection-newSelection); - else - setSelection(mSelection+newSelection); + setSelection( newSelection ); } - } else - setSelection(newSelection); - if (selectionStateChanged) + else // in all other selection modes we toggle selections of homogeneously selected/unselected segments + { + if( mSelection.contains( newSelection ) ) // if entire newSelection is already selected, toggle selection + setSelection( mSelection - newSelection ); + else + setSelection( mSelection + newSelection ); + } + } + else + setSelection( newSelection ); + if( selectionStateChanged ) *selectionStateChanged = mSelection != selectionBefore; } } /* inherits documentation from base class */ -void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) +void QCPAbstractPlottable::deselectEvent( bool* selectionStateChanged ) { - if (mSelectable != QCP::stNone) + if( mSelectable != QCP::stNone ) { QCPDataSelection selectionBefore = mSelection; - setSelection(QCPDataSelection()); - if (selectionStateChanged) + setSelection( QCPDataSelection() ); + if( selectionStateChanged ) *selectionStateChanged = mSelection != selectionBefore; } } /* end of 'src/plottable.cpp' */ - /* including file 'src/item.cpp', size 49271 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -11323,26 +11453,23 @@ void QCPAbstractPlottable::deselectEvent(bool *selectionStateChanged) you want to make a new item subclass. Use \ref QCPAbstractItem::createAnchor instead, as explained in the subclassing section of the QCPAbstractItem documentation. */ -QCPItemAnchor::QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId) : - mName(name), - mParentPlot(parentPlot), - mParentItem(parentItem), - mAnchorId(anchorId) +QCPItemAnchor::QCPItemAnchor( QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString& name, int anchorId ) + : mName( name ), mParentPlot( parentPlot ), mParentItem( parentItem ), mAnchorId( anchorId ) { } QCPItemAnchor::~QCPItemAnchor() { // unregister as parent at children: - foreach (QCPItemPosition *child, mChildrenX.toList()) + foreach( QCPItemPosition* child, mChildrenX.toList() ) { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + if( child->parentAnchorX() == this ) + child->setParentAnchorX( 0 ); // this acts back on this anchor and child removes itself from mChildrenX } - foreach (QCPItemPosition *child, mChildrenY.toList()) + foreach( QCPItemPosition* child, mChildrenY.toList() ) { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + if( child->parentAnchorY() == this ) + child->setParentAnchorY( 0 ); // this acts back on this anchor and child removes itself from mChildrenY } } @@ -11354,17 +11481,19 @@ QCPItemAnchor::~QCPItemAnchor() */ QPointF QCPItemAnchor::pixelPosition() const { - if (mParentItem) + if( mParentItem ) { - if (mAnchorId > -1) + if( mAnchorId > -1 ) { - return mParentItem->anchorPixelPosition(mAnchorId); - } else + return mParentItem->anchorPixelPosition( mAnchorId ); + } + else { qDebug() << Q_FUNC_INFO << "no valid anchor id set:" << mAnchorId; return QPointF(); } - } else + } + else { qDebug() << Q_FUNC_INFO << "no parent item set"; return QPointF(); @@ -11379,12 +11508,12 @@ QPointF QCPItemAnchor::pixelPosition() const Note that this function does not change the parent setting in \a pos. */ -void QCPItemAnchor::addChildX(QCPItemPosition *pos) +void QCPItemAnchor::addChildX( QCPItemPosition* pos ) { - if (!mChildrenX.contains(pos)) - mChildrenX.insert(pos); + if( !mChildrenX.contains( pos ) ) + mChildrenX.insert( pos ); else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast( pos ); } /*! \internal @@ -11393,10 +11522,10 @@ void QCPItemAnchor::addChildX(QCPItemPosition *pos) Note that this function does not change the parent setting in \a pos. */ -void QCPItemAnchor::removeChildX(QCPItemPosition *pos) +void QCPItemAnchor::removeChildX( QCPItemPosition* pos ) { - if (!mChildrenX.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); + if( !mChildrenX.remove( pos ) ) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast( pos ); } /*! \internal @@ -11407,12 +11536,12 @@ void QCPItemAnchor::removeChildX(QCPItemPosition *pos) Note that this function does not change the parent setting in \a pos. */ -void QCPItemAnchor::addChildY(QCPItemPosition *pos) +void QCPItemAnchor::addChildY( QCPItemPosition* pos ) { - if (!mChildrenY.contains(pos)) - mChildrenY.insert(pos); + if( !mChildrenY.contains( pos ) ) + mChildrenY.insert( pos ); else - qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast(pos); + qDebug() << Q_FUNC_INFO << "provided pos is child already" << reinterpret_cast( pos ); } /*! \internal @@ -11421,13 +11550,12 @@ void QCPItemAnchor::addChildY(QCPItemPosition *pos) Note that this function does not change the parent setting in \a pos. */ -void QCPItemAnchor::removeChildY(QCPItemPosition *pos) +void QCPItemAnchor::removeChildY( QCPItemPosition* pos ) { - if (!mChildrenY.remove(pos)) - qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast(pos); + if( !mChildrenY.remove( pos ) ) + qDebug() << Q_FUNC_INFO << "provided pos isn't child" << reinterpret_cast( pos ); } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemPosition //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11496,14 +11624,8 @@ void QCPItemAnchor::removeChildY(QCPItemPosition *pos) you want to make a new item subclass. Use \ref QCPAbstractItem::createPosition instead, as explained in the subclassing section of the QCPAbstractItem documentation. */ -QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : - QCPItemAnchor(parentPlot, parentItem, name), - mPositionTypeX(ptAbsolute), - mPositionTypeY(ptAbsolute), - mKey(0), - mValue(0), - mParentAnchorX(0), - mParentAnchorY(0) +QCPItemPosition::QCPItemPosition( QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString& name ) + : QCPItemAnchor( parentPlot, parentItem, name ), mPositionTypeX( ptAbsolute ), mPositionTypeY( ptAbsolute ), mKey( 0 ), mValue( 0 ), mParentAnchorX( 0 ), mParentAnchorY( 0 ) { } @@ -11512,25 +11634,25 @@ QCPItemPosition::~QCPItemPosition() // unregister as parent at children: // Note: this is done in ~QCPItemAnchor again, but it's important QCPItemPosition does it itself, because only then // the setParentAnchor(0) call the correct QCPItemPosition::pixelPosition function instead of QCPItemAnchor::pixelPosition - foreach (QCPItemPosition *child, mChildrenX.toList()) + foreach( QCPItemPosition* child, mChildrenX.toList() ) { - if (child->parentAnchorX() == this) - child->setParentAnchorX(0); // this acts back on this anchor and child removes itself from mChildrenX + if( child->parentAnchorX() == this ) + child->setParentAnchorX( 0 ); // this acts back on this anchor and child removes itself from mChildrenX } - foreach (QCPItemPosition *child, mChildrenY.toList()) + foreach( QCPItemPosition* child, mChildrenY.toList() ) { - if (child->parentAnchorY() == this) - child->setParentAnchorY(0); // this acts back on this anchor and child removes itself from mChildrenY + if( child->parentAnchorY() == this ) + child->setParentAnchorY( 0 ); // this acts back on this anchor and child removes itself from mChildrenY } // unregister as child in parent: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); + if( mParentAnchorX ) + mParentAnchorX->removeChildX( this ); + if( mParentAnchorY ) + mParentAnchorY->removeChildY( this ); } /* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPItemPosition::axisRect() const +QCPAxisRect* QCPItemPosition::axisRect() const { return mAxisRect.data(); } @@ -11560,10 +11682,10 @@ QCPAxisRect *QCPItemPosition::axisRect() const This method sets the type for both X and Y directions. It is also possible to set different types for X and Y, see \ref setTypeX, \ref setTypeY. */ -void QCPItemPosition::setType(QCPItemPosition::PositionType type) +void QCPItemPosition::setType( QCPItemPosition::PositionType type ) { - setTypeX(type); - setTypeY(type); + setTypeX( type ); + setTypeY( type ); } /*! @@ -11573,26 +11695,26 @@ void QCPItemPosition::setType(QCPItemPosition::PositionType type) \see setType, setTypeY */ -void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) +void QCPItemPosition::setTypeX( QCPItemPosition::PositionType type ) { - if (mPositionTypeX != type) + if( mPositionTypeX != type ) { // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. bool retainPixelPosition = true; - if ((mPositionTypeX == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + if( ( mPositionTypeX == ptPlotCoords || type == ptPlotCoords ) && ( !mKeyAxis || !mValueAxis ) ) retainPixelPosition = false; - if ((mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + if( ( mPositionTypeX == ptAxisRectRatio || type == ptAxisRectRatio ) && ( !mAxisRect ) ) retainPixelPosition = false; - + QPointF pixel; - if (retainPixelPosition) + if( retainPixelPosition ) pixel = pixelPosition(); - + mPositionTypeX = type; - - if (retainPixelPosition) - setPixelPosition(pixel); + + if( retainPixelPosition ) + setPixelPosition( pixel ); } } @@ -11603,26 +11725,26 @@ void QCPItemPosition::setTypeX(QCPItemPosition::PositionType type) \see setType, setTypeX */ -void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) +void QCPItemPosition::setTypeY( QCPItemPosition::PositionType type ) { - if (mPositionTypeY != type) + if( mPositionTypeY != type ) { // if switching from or to coordinate type that isn't valid (e.g. because axes or axis rect // were deleted), don't try to recover the pixelPosition() because it would output a qDebug warning. bool retainPixelPosition = true; - if ((mPositionTypeY == ptPlotCoords || type == ptPlotCoords) && (!mKeyAxis || !mValueAxis)) + if( ( mPositionTypeY == ptPlotCoords || type == ptPlotCoords ) && ( !mKeyAxis || !mValueAxis ) ) retainPixelPosition = false; - if ((mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio) && (!mAxisRect)) + if( ( mPositionTypeY == ptAxisRectRatio || type == ptAxisRectRatio ) && ( !mAxisRect ) ) retainPixelPosition = false; - + QPointF pixel; - if (retainPixelPosition) + if( retainPixelPosition ) pixel = pixelPosition(); - + mPositionTypeY = type; - - if (retainPixelPosition) - setPixelPosition(pixel); + + if( retainPixelPosition ) + setPixelPosition( pixel ); } } @@ -11644,10 +11766,10 @@ void QCPItemPosition::setTypeY(QCPItemPosition::PositionType type) This method sets the parent anchor for both X and Y directions. It is also possible to set different parents for X and Y, see \ref setParentAnchorX, \ref setParentAnchorY. */ -bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +bool QCPItemPosition::setParentAnchor( QCPItemAnchor* parentAnchor, bool keepPixelPosition ) { - bool successX = setParentAnchorX(parentAnchor, keepPixelPosition); - bool successY = setParentAnchorY(parentAnchor, keepPixelPosition); + bool successX = setParentAnchorX( parentAnchor, keepPixelPosition ); + bool successY = setParentAnchorY( parentAnchor, keepPixelPosition ); return successX && successY; } @@ -11658,61 +11780,62 @@ bool QCPItemPosition::setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixe \see setParentAnchor, setParentAnchorY */ -bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +bool QCPItemPosition::setParentAnchorX( QCPItemAnchor* parentAnchor, bool keepPixelPosition ) { // make sure self is not assigned as parent: - if (parentAnchor == this) + if( parentAnchor == this ) { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast( parentAnchor ); return false; } // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) + QCPItemAnchor* currentParent = parentAnchor; + while( currentParent ) { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + if( QCPItemPosition* currentParentPos = currentParent->toQCPItemPosition() ) { // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) + if( currentParentPos == this ) { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast( parentAnchor ); return false; } currentParent = currentParentPos->parentAnchorX(); - } else + } + else { // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the // same, to prevent a position being child of an anchor which itself depends on the position, // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) + if( currentParent->mParentItem == mParentItem ) { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast( parentAnchor ); return false; } break; } } - + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorX && mPositionTypeX == ptPlotCoords) - setTypeX(ptAbsolute); - + if( !mParentAnchorX && mPositionTypeX == ptPlotCoords ) + setTypeX( ptAbsolute ); + // save pixel position: QPointF pixelP; - if (keepPixelPosition) + if( keepPixelPosition ) pixelP = pixelPosition(); // unregister at current parent anchor: - if (mParentAnchorX) - mParentAnchorX->removeChildX(this); + if( mParentAnchorX ) + mParentAnchorX->removeChildX( this ); // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildX(this); + if( parentAnchor ) + parentAnchor->addChildX( this ); mParentAnchorX = parentAnchor; // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); + if( keepPixelPosition ) + setPixelPosition( pixelP ); else - setCoords(0, coords().y()); + setCoords( 0, coords().y() ); return true; } @@ -11723,61 +11846,62 @@ bool QCPItemPosition::setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPix \see setParentAnchor, setParentAnchorX */ -bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition) +bool QCPItemPosition::setParentAnchorY( QCPItemAnchor* parentAnchor, bool keepPixelPosition ) { // make sure self is not assigned as parent: - if (parentAnchor == this) + if( parentAnchor == this ) { - qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't set self as parent anchor" << reinterpret_cast( parentAnchor ); return false; } // make sure no recursive parent-child-relationships are created: - QCPItemAnchor *currentParent = parentAnchor; - while (currentParent) + QCPItemAnchor* currentParent = parentAnchor; + while( currentParent ) { - if (QCPItemPosition *currentParentPos = currentParent->toQCPItemPosition()) + if( QCPItemPosition* currentParentPos = currentParent->toQCPItemPosition() ) { // is a QCPItemPosition, might have further parent, so keep iterating - if (currentParentPos == this) + if( currentParentPos == this ) { - qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't create recursive parent-child-relationship" << reinterpret_cast( parentAnchor ); return false; } currentParent = currentParentPos->parentAnchorY(); - } else + } + else { // is a QCPItemAnchor, can't have further parent. Now make sure the parent items aren't the // same, to prevent a position being child of an anchor which itself depends on the position, // because they're both on the same item: - if (currentParent->mParentItem == mParentItem) + if( currentParent->mParentItem == mParentItem ) { - qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast(parentAnchor); + qDebug() << Q_FUNC_INFO << "can't set parent to be an anchor which itself depends on this position" << reinterpret_cast( parentAnchor ); return false; } break; } } - + // if previously no parent set and PosType is still ptPlotCoords, set to ptAbsolute: - if (!mParentAnchorY && mPositionTypeY == ptPlotCoords) - setTypeY(ptAbsolute); - + if( !mParentAnchorY && mPositionTypeY == ptPlotCoords ) + setTypeY( ptAbsolute ); + // save pixel position: QPointF pixelP; - if (keepPixelPosition) + if( keepPixelPosition ) pixelP = pixelPosition(); // unregister at current parent anchor: - if (mParentAnchorY) - mParentAnchorY->removeChildY(this); + if( mParentAnchorY ) + mParentAnchorY->removeChildY( this ); // register at new parent anchor: - if (parentAnchor) - parentAnchor->addChildY(this); + if( parentAnchor ) + parentAnchor->addChildY( this ); mParentAnchorY = parentAnchor; // restore pixel position under new parent: - if (keepPixelPosition) - setPixelPosition(pixelP); + if( keepPixelPosition ) + setPixelPosition( pixelP ); else - setCoords(coords().x(), 0); + setCoords( coords().x(), 0 ); return true; } @@ -11798,7 +11922,7 @@ bool QCPItemPosition::setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPix \see setPixelPosition */ -void QCPItemPosition::setCoords(double key, double value) +void QCPItemPosition::setCoords( double key, double value ) { mKey = key; mValue = value; @@ -11809,9 +11933,9 @@ void QCPItemPosition::setCoords(double key, double value) Sets the coordinates as a QPointF \a pos where pos.x has the meaning of \a key and pos.y the meaning of \a value of the \ref setCoords(double key, double value) method. */ -void QCPItemPosition::setCoords(const QPointF &pos) +void QCPItemPosition::setCoords( const QPointF& pos ) { - setCoords(pos.x(), pos.y()); + setCoords( pos.x(), pos.y() ); } /*! @@ -11823,95 +11947,89 @@ void QCPItemPosition::setCoords(const QPointF &pos) QPointF QCPItemPosition::pixelPosition() const { QPointF result; - + // determine X: - switch (mPositionTypeX) + switch( mPositionTypeX ) { - case ptAbsolute: - { - result.rx() = mKey; - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - result.rx() = mKey*mParentPlot->viewport().width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mParentPlot->viewport().left(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.rx() = mKey*mAxisRect.data()->width(); - if (mParentAnchorX) - result.rx() += mParentAnchorX->pixelPosition().x(); - else - result.rx() += mAxisRect.data()->left(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - result.rx() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } + case ptAbsolute: { + result.rx() = mKey; + if( mParentAnchorX ) + result.rx() += mParentAnchorX->pixelPosition().x(); + break; } - + case ptViewportRatio: { + result.rx() = mKey * mParentPlot->viewport().width(); + if( mParentAnchorX ) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mParentPlot->viewport().left(); + break; + } + case ptAxisRectRatio: { + if( mAxisRect ) + { + result.rx() = mKey * mAxisRect.data()->width(); + if( mParentAnchorX ) + result.rx() += mParentAnchorX->pixelPosition().x(); + else + result.rx() += mAxisRect.data()->left(); + } + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: { + if( mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal ) + result.rx() = mKeyAxis.data()->coordToPixel( mKey ); + else if( mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal ) + result.rx() = mValueAxis.data()->coordToPixel( mValue ); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + // determine Y: - switch (mPositionTypeY) + switch( mPositionTypeY ) { - case ptAbsolute: - { - result.ry() = mValue; - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - result.ry() = mValue*mParentPlot->viewport().height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mParentPlot->viewport().top(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - result.ry() = mValue*mAxisRect.data()->height(); - if (mParentAnchorY) - result.ry() += mParentAnchorY->pixelPosition().y(); - else - result.ry() += mAxisRect.data()->top(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - result.ry() = mKeyAxis.data()->coordToPixel(mKey); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - result.ry() = mValueAxis.data()->coordToPixel(mValue); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } + case ptAbsolute: { + result.ry() = mValue; + if( mParentAnchorY ) + result.ry() += mParentAnchorY->pixelPosition().y(); + break; } - + case ptViewportRatio: { + result.ry() = mValue * mParentPlot->viewport().height(); + if( mParentAnchorY ) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mParentPlot->viewport().top(); + break; + } + case ptAxisRectRatio: { + if( mAxisRect ) + { + result.ry() = mValue * mAxisRect.data()->height(); + if( mParentAnchorY ) + result.ry() += mParentAnchorY->pixelPosition().y(); + else + result.ry() += mAxisRect.data()->top(); + } + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: { + if( mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical ) + result.ry() = mKeyAxis.data()->coordToPixel( mKey ); + else if( mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical ) + result.ry() = mValueAxis.data()->coordToPixel( mValue ); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + return result; } @@ -11920,7 +12038,7 @@ QPointF QCPItemPosition::pixelPosition() const coordinates set with \ref setCoords relate to. By default they are set to the initial xAxis and yAxis of the QCustomPlot. */ -void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) +void QCPItemPosition::setAxes( QCPAxis* keyAxis, QCPAxis* valueAxis ) { mKeyAxis = keyAxis; mValueAxis = valueAxis; @@ -11931,7 +12049,7 @@ void QCPItemPosition::setAxes(QCPAxis *keyAxis, QCPAxis *valueAxis) coordinates set with \ref setCoords relate to. By default this is set to the main axis rect of the QCustomPlot. */ -void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) +void QCPItemPosition::setAxisRect( QCPAxisRect* axisRect ) { mAxisRect = axisRect; } @@ -11946,98 +12064,91 @@ void QCPItemPosition::setAxisRect(QCPAxisRect *axisRect) \see pixelPosition, setCoords */ -void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) +void QCPItemPosition::setPixelPosition( const QPointF& pixelPosition ) { double x = pixelPosition.x(); double y = pixelPosition.y(); - - switch (mPositionTypeX) - { - case ptAbsolute: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mParentPlot->viewport().left(); - x /= (double)mParentPlot->viewport().width(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorX) - x -= mParentAnchorX->pixelPosition().x(); - else - x -= mAxisRect.data()->left(); - x /= (double)mAxisRect.data()->width(); - } else - qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal) - x = mKeyAxis.data()->pixelToCoord(x); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal) - y = mValueAxis.data()->pixelToCoord(x); - else - qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; - break; - } - } - - switch (mPositionTypeY) - { - case ptAbsolute: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - break; - } - case ptViewportRatio: - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mParentPlot->viewport().top(); - y /= (double)mParentPlot->viewport().height(); - break; - } - case ptAxisRectRatio: - { - if (mAxisRect) - { - if (mParentAnchorY) - y -= mParentAnchorY->pixelPosition().y(); - else - y -= mAxisRect.data()->top(); - y /= (double)mAxisRect.data()->height(); - } else - qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; - break; - } - case ptPlotCoords: - { - if (mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical) - x = mKeyAxis.data()->pixelToCoord(y); - else if (mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical) - y = mValueAxis.data()->pixelToCoord(y); - else - qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; - break; - } - } - - setCoords(x, y); -} + switch( mPositionTypeX ) + { + case ptAbsolute: { + if( mParentAnchorX ) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: { + if( mParentAnchorX ) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mParentPlot->viewport().left(); + x /= (double)mParentPlot->viewport().width(); + break; + } + case ptAxisRectRatio: { + if( mAxisRect ) + { + if( mParentAnchorX ) + x -= mParentAnchorX->pixelPosition().x(); + else + x -= mAxisRect.data()->left(); + x /= (double)mAxisRect.data()->width(); + } + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: { + if( mKeyAxis && mKeyAxis.data()->orientation() == Qt::Horizontal ) + x = mKeyAxis.data()->pixelToCoord( x ); + else if( mValueAxis && mValueAxis.data()->orientation() == Qt::Horizontal ) + y = mValueAxis.data()->pixelToCoord( x ); + else + qDebug() << Q_FUNC_INFO << "Item position type x is ptPlotCoords, but no axes were defined"; + break; + } + } + + switch( mPositionTypeY ) + { + case ptAbsolute: { + if( mParentAnchorY ) + y -= mParentAnchorY->pixelPosition().y(); + break; + } + case ptViewportRatio: { + if( mParentAnchorY ) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mParentPlot->viewport().top(); + y /= (double)mParentPlot->viewport().height(); + break; + } + case ptAxisRectRatio: { + if( mAxisRect ) + { + if( mParentAnchorY ) + y -= mParentAnchorY->pixelPosition().y(); + else + y -= mAxisRect.data()->top(); + y /= (double)mAxisRect.data()->height(); + } + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptAxisRectRatio, but no axis rect was defined"; + break; + } + case ptPlotCoords: { + if( mKeyAxis && mKeyAxis.data()->orientation() == Qt::Vertical ) + x = mKeyAxis.data()->pixelToCoord( y ); + else if( mValueAxis && mValueAxis.data()->orientation() == Qt::Vertical ) + y = mValueAxis.data()->pixelToCoord( y ); + else + qDebug() << Q_FUNC_INFO << "Item position type y is ptPlotCoords, but no axes were defined"; + break; + } + } + + setCoords( x, y ); +} //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractItem @@ -12211,30 +12322,27 @@ void QCPItemPosition::setPixelPosition(const QPointF &pixelPosition) /*! Base class constructor which initializes base class members. */ -QCPAbstractItem::QCPAbstractItem(QCustomPlot *parentPlot) : - QCPLayerable(parentPlot), - mClipToAxisRect(false), - mSelectable(true), - mSelected(false) +QCPAbstractItem::QCPAbstractItem( QCustomPlot* parentPlot ) + : QCPLayerable( parentPlot ), mClipToAxisRect( false ), mSelectable( true ), mSelected( false ) { - parentPlot->registerItem(this); - + parentPlot->registerItem( this ); + QList rects = parentPlot->axisRects(); - if (rects.size() > 0) + if( rects.size() > 0 ) { - setClipToAxisRect(true); - setClipAxisRect(rects.first()); + setClipToAxisRect( true ); + setClipAxisRect( rects.first() ); } } QCPAbstractItem::~QCPAbstractItem() { // don't delete mPositions because every position is also an anchor and thus in mAnchors - qDeleteAll(mAnchors); + qDeleteAll( mAnchors ); } /* can't make this a header inline function, because QPointer breaks with forward declared types, see QTBUG-29588 */ -QCPAxisRect *QCPAbstractItem::clipAxisRect() const +QCPAxisRect* QCPAbstractItem::clipAxisRect() const { return mClipAxisRect.data(); } @@ -12245,11 +12353,11 @@ QCPAxisRect *QCPAbstractItem::clipAxisRect() const \see setClipAxisRect */ -void QCPAbstractItem::setClipToAxisRect(bool clip) +void QCPAbstractItem::setClipToAxisRect( bool clip ) { mClipToAxisRect = clip; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); + if( mClipToAxisRect ) + setParentLayerable( mClipAxisRect.data() ); } /*! @@ -12258,11 +12366,11 @@ void QCPAbstractItem::setClipToAxisRect(bool clip) \see setClipToAxisRect */ -void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) +void QCPAbstractItem::setClipAxisRect( QCPAxisRect* rect ) { mClipAxisRect = rect; - if (mClipToAxisRect) - setParentLayerable(mClipAxisRect.data()); + if( mClipToAxisRect ) + setParentLayerable( mClipAxisRect.data() ); } /*! @@ -12274,12 +12382,12 @@ void QCPAbstractItem::setClipAxisRect(QCPAxisRect *rect) \see QCustomPlot::setInteractions, setSelected */ -void QCPAbstractItem::setSelectable(bool selectable) +void QCPAbstractItem::setSelectable( bool selectable ) { - if (mSelectable != selectable) + if( mSelectable != selectable ) { mSelectable = selectable; - emit selectableChanged(mSelectable); + emit selectableChanged( mSelectable ); } } @@ -12297,12 +12405,12 @@ void QCPAbstractItem::setSelectable(bool selectable) \see setSelectable, selectTest */ -void QCPAbstractItem::setSelected(bool selected) +void QCPAbstractItem::setSelected( bool selected ) { - if (mSelected != selected) + if( mSelected != selected ) { mSelected = selected; - emit selectionChanged(mSelected); + emit selectionChanged( mSelected ); } } @@ -12316,12 +12424,12 @@ void QCPAbstractItem::setSelected(bool selected) \see positions, anchor */ -QCPItemPosition *QCPAbstractItem::position(const QString &name) const +QCPItemPosition* QCPAbstractItem::position( const QString& name ) const { - for (int i=0; iname() == name) - return mPositions.at(i); + if( mPositions.at( i )->name() == name ) + return mPositions.at( i ); } qDebug() << Q_FUNC_INFO << "position with name not found:" << name; return 0; @@ -12337,12 +12445,12 @@ QCPItemPosition *QCPAbstractItem::position(const QString &name) const \see anchors, position */ -QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const +QCPItemAnchor* QCPAbstractItem::anchor( const QString& name ) const { - for (int i=0; iname() == name) - return mAnchors.at(i); + if( mAnchors.at( i )->name() == name ) + return mAnchors.at( i ); } qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; return 0; @@ -12356,11 +12464,11 @@ QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const \see anchor, position */ -bool QCPAbstractItem::hasAnchor(const QString &name) const +bool QCPAbstractItem::hasAnchor( const QString& name ) const { - for (int i=0; iname() == name) + if( mAnchors.at( i )->name() == name ) return true; } return false; @@ -12377,7 +12485,7 @@ bool QCPAbstractItem::hasAnchor(const QString &name) const */ QRect QCPAbstractItem::clipRect() const { - if (mClipToAxisRect && mClipAxisRect) + if( mClipToAxisRect && mClipAxisRect ) return mClipAxisRect.data()->rect(); else return mParentPlot->viewport(); @@ -12396,9 +12504,9 @@ QRect QCPAbstractItem::clipRect() const \see setAntialiased */ -void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPAbstractItem::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeItems); + applyAntialiasingHint( painter, mAntialiased, QCP::aeItems ); } /*! \internal @@ -12414,28 +12522,28 @@ void QCPAbstractItem::applyDefaultAntialiasingHint(QCPPainter *painter) const rect, in your \ref selectTest reimplementation. Finally, return the minimum (non -1) of all four returned values. */ -double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const +double QCPAbstractItem::rectDistance( const QRectF& rect, const QPointF& pos, bool filledRect ) const { double result = -1; // distance to border: QList lines; - lines << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) - << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); - double minDistSqr = (std::numeric_limits::max)(); - for (int i=0; i::max )(); + for( int i = 0; i < lines.size(); ++i ) { - double distSqr = QCPVector2D(pos).distanceSquaredToLine(lines.at(i).p1(), lines.at(i).p2()); - if (distSqr < minDistSqr) + double distSqr = QCPVector2D( pos ).distanceSquaredToLine( lines.at( i ).p1(), lines.at( i ).p2() ); + if( distSqr < minDistSqr ) minDistSqr = distSqr; } - result = qSqrt(minDistSqr); - + result = qSqrt( minDistSqr ); + // filled rect, allow click inside to count as hit: - if (filledRect && result > mParentPlot->selectionTolerance()*0.99) + if( filledRect && result > mParentPlot->selectionTolerance() * 0.99 ) { - if (rect.contains(pos)) - result = mParentPlot->selectionTolerance()*0.99; + if( rect.contains( pos ) ) + result = mParentPlot->selectionTolerance() * 0.99; } return result; } @@ -12450,7 +12558,7 @@ double QCPAbstractItem::rectDistance(const QRectF &rect, const QPointF &pos, boo \see createAnchor */ -QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const +QPointF QCPAbstractItem::anchorPixelPosition( int anchorId ) const { qDebug() << Q_FUNC_INFO << "called on item which shouldn't have any anchors (this method not reimplemented). anchorId" << anchorId; return QPointF(); @@ -12470,18 +12578,18 @@ QPointF QCPAbstractItem::anchorPixelPosition(int anchorId) const \see createAnchor */ -QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) +QCPItemPosition* QCPAbstractItem::createPosition( const QString& name ) { - if (hasAnchor(name)) + if( hasAnchor( name ) ) qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemPosition *newPosition = new QCPItemPosition(mParentPlot, this, name); - mPositions.append(newPosition); - mAnchors.append(newPosition); // every position is also an anchor - newPosition->setAxes(mParentPlot->xAxis, mParentPlot->yAxis); - newPosition->setType(QCPItemPosition::ptPlotCoords); - if (mParentPlot->axisRect()) - newPosition->setAxisRect(mParentPlot->axisRect()); - newPosition->setCoords(0, 0); + QCPItemPosition* newPosition = new QCPItemPosition( mParentPlot, this, name ); + mPositions.append( newPosition ); + mAnchors.append( newPosition ); // every position is also an anchor + newPosition->setAxes( mParentPlot->xAxis, mParentPlot->yAxis ); + newPosition->setType( QCPItemPosition::ptPlotCoords ); + if( mParentPlot->axisRect() ) + newPosition->setAxisRect( mParentPlot->axisRect() ); + newPosition->setCoords( 0, 0 ); return newPosition; } @@ -12504,37 +12612,37 @@ QCPItemPosition *QCPAbstractItem::createPosition(const QString &name) \see createPosition */ -QCPItemAnchor *QCPAbstractItem::createAnchor(const QString &name, int anchorId) +QCPItemAnchor* QCPAbstractItem::createAnchor( const QString& name, int anchorId ) { - if (hasAnchor(name)) + if( hasAnchor( name ) ) qDebug() << Q_FUNC_INFO << "anchor/position with name exists already:" << name; - QCPItemAnchor *newAnchor = new QCPItemAnchor(mParentPlot, this, name, anchorId); - mAnchors.append(newAnchor); + QCPItemAnchor* newAnchor = new QCPItemAnchor( mParentPlot, this, name, anchorId ); + mAnchors.append( newAnchor ); return newAnchor; } /* inherits documentation from base class */ -void QCPAbstractItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPAbstractItem::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) + Q_UNUSED( event ) + Q_UNUSED( details ) + if( mSelectable ) { bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) + setSelected( additive ? !mSelected : true ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } /* inherits documentation from base class */ -void QCPAbstractItem::deselectEvent(bool *selectionStateChanged) +void QCPAbstractItem::deselectEvent( bool* selectionStateChanged ) { - if (mSelectable) + if( mSelectable ) { bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) + setSelected( false ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } @@ -12546,7 +12654,6 @@ QCP::Interaction QCPAbstractItem::selectionCategory() const } /* end of 'src/item.cpp' */ - /* including file 'src/core.cpp', size 126207 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -12856,101 +12963,95 @@ QCP::Interaction QCPAbstractItem::selectionCategory() const /*! Constructs a QCustomPlot and sets reasonable default values. */ -QCustomPlot::QCustomPlot(QWidget *parent) : - QWidget(parent), - xAxis(0), - yAxis(0), - xAxis2(0), - yAxis2(0), - legend(0), - mBufferDevicePixelRatio(1.0), // will be adapted to primary screen below - mPlotLayout(0), - mAutoAddPlottableToLegend(true), - mAntialiasedElements(QCP::aeNone), - mNotAntialiasedElements(QCP::aeNone), - mInteractions(0), - mSelectionTolerance(8), - mNoAntialiasingOnDrag(false), - mBackgroundBrush(Qt::white, Qt::SolidPattern), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mCurrentLayer(0), - mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), - mMultiSelectModifier(Qt::ControlModifier), - mSelectionRectMode(QCP::srmNone), - mSelectionRect(0), - mOpenGl(false), - mMouseHasMoved(false), - mMouseEventLayerable(0), - mMouseSignalLayerable(0), - mReplotting(false), - mReplotQueued(false), - mOpenGlMultisamples(16), - mOpenGlAntialiasedElementsBackup(QCP::aeNone), - mOpenGlCacheLabelsBackup(true) +QCustomPlot::QCustomPlot( QWidget* parent ) + : QWidget( parent ), xAxis( 0 ), yAxis( 0 ), xAxis2( 0 ), yAxis2( 0 ), legend( 0 ), mBufferDevicePixelRatio( 1.0 ), // will be adapted to primary screen below + mPlotLayout( 0 ) + , mAutoAddPlottableToLegend( true ) + , mAntialiasedElements( QCP::aeNone ) + , mNotAntialiasedElements( QCP::aeNone ) + , mInteractions( 0 ) + , mSelectionTolerance( 8 ) + , mNoAntialiasingOnDrag( false ) + , mBackgroundBrush( Qt::white, Qt::SolidPattern ) + , mBackgroundScaled( true ) + , mBackgroundScaledMode( Qt::KeepAspectRatioByExpanding ) + , mCurrentLayer( 0 ) + , mPlottingHints( QCP::phCacheLabels | QCP::phImmediateRefresh ) + , mMultiSelectModifier( Qt::ControlModifier ) + , mSelectionRectMode( QCP::srmNone ) + , mSelectionRect( 0 ) + , mOpenGl( false ) + , mMouseHasMoved( false ) + , mMouseEventLayerable( 0 ) + , mMouseSignalLayerable( 0 ) + , mReplotting( false ) + , mReplotQueued( false ) + , mOpenGlMultisamples( 16 ) + , mOpenGlAntialiasedElementsBackup( QCP::aeNone ) + , mOpenGlCacheLabelsBackup( true ) { - setAttribute(Qt::WA_NoMousePropagation); - setAttribute(Qt::WA_OpaquePaintEvent); - setFocusPolicy(Qt::ClickFocus); - setMouseTracking(true); + setAttribute( Qt::WA_NoMousePropagation ); + setAttribute( Qt::WA_OpaquePaintEvent ); + setFocusPolicy( Qt::ClickFocus ); + setMouseTracking( true ); QLocale currentLocale = locale(); - currentLocale.setNumberOptions(QLocale::OmitGroupSeparator); - setLocale(currentLocale); + currentLocale.setNumberOptions( QLocale::OmitGroupSeparator ); + setLocale( currentLocale ); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -# ifdef QCP_DEVICEPIXELRATIO_FLOAT - setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); -# else - setBufferDevicePixelRatio(QWidget::devicePixelRatio()); -# endif +#ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio( QWidget::devicePixelRatioF() ); +#else + setBufferDevicePixelRatio( QWidget::devicePixelRatio() ); #endif - +#endif + mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag( QCP::phCacheLabels ); // create initial layers: - mLayers.append(new QCPLayer(this, QLatin1String("background"))); - mLayers.append(new QCPLayer(this, QLatin1String("grid"))); - mLayers.append(new QCPLayer(this, QLatin1String("main"))); - mLayers.append(new QCPLayer(this, QLatin1String("axes"))); - mLayers.append(new QCPLayer(this, QLatin1String("legend"))); - mLayers.append(new QCPLayer(this, QLatin1String("overlay"))); + mLayers.append( new QCPLayer( this, QLatin1String( "background" ) ) ); + mLayers.append( new QCPLayer( this, QLatin1String( "grid" ) ) ); + mLayers.append( new QCPLayer( this, QLatin1String( "main" ) ) ); + mLayers.append( new QCPLayer( this, QLatin1String( "axes" ) ) ); + mLayers.append( new QCPLayer( this, QLatin1String( "legend" ) ) ); + mLayers.append( new QCPLayer( this, QLatin1String( "overlay" ) ) ); updateLayerIndices(); - setCurrentLayer(QLatin1String("main")); - layer(QLatin1String("overlay"))->setMode(QCPLayer::lmBuffered); - + setCurrentLayer( QLatin1String( "main" ) ); + layer( QLatin1String( "overlay" ) )->setMode( QCPLayer::lmBuffered ); + // create initial layout, axis rect and legend: mPlotLayout = new QCPLayoutGrid; - mPlotLayout->initializeParentPlot(this); - mPlotLayout->setParent(this); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry - mPlotLayout->setLayer(QLatin1String("main")); - QCPAxisRect *defaultAxisRect = new QCPAxisRect(this, true); - mPlotLayout->addElement(0, 0, defaultAxisRect); - xAxis = defaultAxisRect->axis(QCPAxis::atBottom); - yAxis = defaultAxisRect->axis(QCPAxis::atLeft); - xAxis2 = defaultAxisRect->axis(QCPAxis::atTop); - yAxis2 = defaultAxisRect->axis(QCPAxis::atRight); + mPlotLayout->initializeParentPlot( this ); + mPlotLayout->setParent( this ); // important because if parent is QWidget, QCPLayout::sizeConstraintsChanged will call QWidget::updateGeometry + mPlotLayout->setLayer( QLatin1String( "main" ) ); + QCPAxisRect* defaultAxisRect = new QCPAxisRect( this, true ); + mPlotLayout->addElement( 0, 0, defaultAxisRect ); + xAxis = defaultAxisRect->axis( QCPAxis::atBottom ); + yAxis = defaultAxisRect->axis( QCPAxis::atLeft ); + xAxis2 = defaultAxisRect->axis( QCPAxis::atTop ); + yAxis2 = defaultAxisRect->axis( QCPAxis::atRight ); legend = new QCPLegend; - legend->setVisible(false); - defaultAxisRect->insetLayout()->addElement(legend, Qt::AlignRight|Qt::AlignTop); - defaultAxisRect->insetLayout()->setMargins(QMargins(12, 12, 12, 12)); - - defaultAxisRect->setLayer(QLatin1String("background")); - xAxis->setLayer(QLatin1String("axes")); - yAxis->setLayer(QLatin1String("axes")); - xAxis2->setLayer(QLatin1String("axes")); - yAxis2->setLayer(QLatin1String("axes")); - xAxis->grid()->setLayer(QLatin1String("grid")); - yAxis->grid()->setLayer(QLatin1String("grid")); - xAxis2->grid()->setLayer(QLatin1String("grid")); - yAxis2->grid()->setLayer(QLatin1String("grid")); - legend->setLayer(QLatin1String("legend")); - + legend->setVisible( false ); + defaultAxisRect->insetLayout()->addElement( legend, Qt::AlignRight | Qt::AlignTop ); + defaultAxisRect->insetLayout()->setMargins( QMargins( 12, 12, 12, 12 ) ); + + defaultAxisRect->setLayer( QLatin1String( "background" ) ); + xAxis->setLayer( QLatin1String( "axes" ) ); + yAxis->setLayer( QLatin1String( "axes" ) ); + xAxis2->setLayer( QLatin1String( "axes" ) ); + yAxis2->setLayer( QLatin1String( "axes" ) ); + xAxis->grid()->setLayer( QLatin1String( "grid" ) ); + yAxis->grid()->setLayer( QLatin1String( "grid" ) ); + xAxis2->grid()->setLayer( QLatin1String( "grid" ) ); + yAxis2->grid()->setLayer( QLatin1String( "grid" ) ); + legend->setLayer( QLatin1String( "legend" ) ); + // create selection rect instance: - mSelectionRect = new QCPSelectionRect(this); - mSelectionRect->setLayer(QLatin1String("overlay")); - - setViewport(rect()); // needs to be called after mPlotLayout has been created - - replot(rpQueuedReplot); + mSelectionRect = new QCPSelectionRect( this ); + mSelectionRect->setLayer( QLatin1String( "overlay" ) ); + + setViewport( rect() ); // needs to be called after mPlotLayout has been created + + replot( rpQueuedReplot ); } QCustomPlot::~QCustomPlot() @@ -12958,14 +13059,14 @@ QCustomPlot::~QCustomPlot() clearPlottables(); clearItems(); - if (mPlotLayout) + if( mPlotLayout ) { delete mPlotLayout; mPlotLayout = 0; } - + mCurrentLayer = 0; - qDeleteAll(mLayers); // don't use removeLayer, because it would prevent the last layer to be removed + qDeleteAll( mLayers ); // don't use removeLayer, because it would prevent the last layer to be removed mLayers.clear(); } @@ -12986,12 +13087,12 @@ QCustomPlot::~QCustomPlot() \see setNotAntialiasedElements */ -void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements) +void QCustomPlot::setAntialiasedElements( const QCP::AntialiasedElements& antialiasedElements ) { mAntialiasedElements = antialiasedElements; - + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + if( ( mNotAntialiasedElements & mAntialiasedElements ) != 0 ) mNotAntialiasedElements |= ~mAntialiasedElements; } @@ -13002,15 +13103,15 @@ void QCustomPlot::setAntialiasedElements(const QCP::AntialiasedElements &antiali \see setNotAntialiasedElement */ -void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled) +void QCustomPlot::setAntialiasedElement( QCP::AntialiasedElement antialiasedElement, bool enabled ) { - if (!enabled && mAntialiasedElements.testFlag(antialiasedElement)) + if( !enabled && mAntialiasedElements.testFlag( antialiasedElement ) ) mAntialiasedElements &= ~antialiasedElement; - else if (enabled && !mAntialiasedElements.testFlag(antialiasedElement)) + else if( enabled && !mAntialiasedElements.testFlag( antialiasedElement ) ) mAntialiasedElements |= antialiasedElement; - + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + if( ( mNotAntialiasedElements & mAntialiasedElements ) != 0 ) mNotAntialiasedElements |= ~mAntialiasedElements; } @@ -13032,12 +13133,12 @@ void QCustomPlot::setAntialiasedElement(QCP::AntialiasedElement antialiasedEleme \see setAntialiasedElements */ -void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) +void QCustomPlot::setNotAntialiasedElements( const QCP::AntialiasedElements& notAntialiasedElements ) { mNotAntialiasedElements = notAntialiasedElements; - + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + if( ( mNotAntialiasedElements & mAntialiasedElements ) != 0 ) mAntialiasedElements |= ~mNotAntialiasedElements; } @@ -13048,15 +13149,15 @@ void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬A \see setAntialiasedElement */ -void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled) +void QCustomPlot::setNotAntialiasedElement( QCP::AntialiasedElement notAntialiasedElement, bool enabled ) { - if (!enabled && mNotAntialiasedElements.testFlag(notAntialiasedElement)) + if( !enabled && mNotAntialiasedElements.testFlag( notAntialiasedElement ) ) mNotAntialiasedElements &= ~notAntialiasedElement; - else if (enabled && !mNotAntialiasedElements.testFlag(notAntialiasedElement)) + else if( enabled && !mNotAntialiasedElements.testFlag( notAntialiasedElement ) ) mNotAntialiasedElements |= notAntialiasedElement; - + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if ((mNotAntialiasedElements & mAntialiasedElements) != 0) + if( ( mNotAntialiasedElements & mAntialiasedElements ) != 0 ) mAntialiasedElements |= ~mNotAntialiasedElements; } @@ -13066,7 +13167,7 @@ void QCustomPlot::setNotAntialiasedElement(QCP::AntialiasedElement notAntialiase \see addGraph, QCPLegend::addItem */ -void QCustomPlot::setAutoAddPlottableToLegend(bool on) +void QCustomPlot::setAutoAddPlottableToLegend( bool on ) { mAutoAddPlottableToLegend = on; } @@ -13125,7 +13226,7 @@ void QCustomPlot::setAutoAddPlottableToLegend(bool on) \see setInteraction, setSelectionTolerance */ -void QCustomPlot::setInteractions(const QCP::Interactions &interactions) +void QCustomPlot::setInteractions( const QCP::Interactions& interactions ) { mInteractions = interactions; } @@ -13137,11 +13238,11 @@ void QCustomPlot::setInteractions(const QCP::Interactions &interactions) \see setInteractions */ -void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabled) +void QCustomPlot::setInteraction( const QCP::Interaction& interaction, bool enabled ) { - if (!enabled && mInteractions.testFlag(interaction)) + if( !enabled && mInteractions.testFlag( interaction ) ) mInteractions &= ~interaction; - else if (enabled && !mInteractions.testFlag(interaction)) + else if( enabled && !mInteractions.testFlag( interaction ) ) mInteractions |= interaction; } @@ -13158,7 +13259,7 @@ void QCustomPlot::setInteraction(const QCP::Interaction &interaction, bool enabl \see setInteractions, QCPLayerable::selectTest */ -void QCustomPlot::setSelectionTolerance(int pixels) +void QCustomPlot::setSelectionTolerance( int pixels ) { mSelectionTolerance = pixels; } @@ -13172,7 +13273,7 @@ void QCustomPlot::setSelectionTolerance(int pixels) \see setAntialiasedElements, setNotAntialiasedElements */ -void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) +void QCustomPlot::setNoAntialiasingOnDrag( bool enabled ) { mNoAntialiasingOnDrag = enabled; } @@ -13182,7 +13283,7 @@ void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) \see setPlottingHint */ -void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) +void QCustomPlot::setPlottingHints( const QCP::PlottingHints& hints ) { mPlottingHints = hints; } @@ -13192,16 +13293,16 @@ void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) \see setPlottingHints */ -void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) +void QCustomPlot::setPlottingHint( QCP::PlottingHint hint, bool enabled ) { QCP::PlottingHints newHints = mPlottingHints; - if (!enabled) + if( !enabled ) newHints &= ~hint; else newHints |= hint; - - if (newHints != mPlottingHints) - setPlottingHints(newHints); + + if( newHints != mPlottingHints ) + setPlottingHints( newHints ); } /*! @@ -13214,7 +13315,7 @@ void QCustomPlot::setPlottingHint(QCP::PlottingHint hint, bool enabled) \see setInteractions */ -void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) +void QCustomPlot::setMultiSelectModifier( Qt::KeyboardModifier modifier ) { mMultiSelectModifier = modifier; } @@ -13239,26 +13340,26 @@ void QCustomPlot::setMultiSelectModifier(Qt::KeyboardModifier modifier) \see setInteractions, setSelectionRect, QCPSelectionRect */ -void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) +void QCustomPlot::setSelectionRectMode( QCP::SelectionRectMode mode ) { - if (mSelectionRect) + if( mSelectionRect ) { - if (mode == QCP::srmNone) - mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect - + if( mode == QCP::srmNone ) + mSelectionRect->cancel(); // when switching to none, we immediately want to abort a potentially active selection rect + // disconnect old connections: - if (mSelectionRectMode == QCP::srmSelect) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - disconnect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); - + if( mSelectionRectMode == QCP::srmSelect ) + disconnect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectSelection( QRect, QMouseEvent* ) ) ); + else if( mSelectionRectMode == QCP::srmZoom ) + disconnect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectZoom( QRect, QMouseEvent* ) ) ); + // establish new ones: - if (mode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + if( mode == QCP::srmSelect ) + connect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectSelection( QRect, QMouseEvent* ) ) ); + else if( mode == QCP::srmZoom ) + connect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectZoom( QRect, QMouseEvent* ) ) ); } - + mSelectionRectMode = mode; } @@ -13272,20 +13373,20 @@ void QCustomPlot::setSelectionRectMode(QCP::SelectionRectMode mode) \see setSelectionRectMode */ -void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) +void QCustomPlot::setSelectionRect( QCPSelectionRect* selectionRect ) { - if (mSelectionRect) + if( mSelectionRect ) delete mSelectionRect; - + mSelectionRect = selectionRect; - - if (mSelectionRect) + + if( mSelectionRect ) { // establish connections with new selection rect: - if (mSelectionRectMode == QCP::srmSelect) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectSelection(QRect,QMouseEvent*))); - else if (mSelectionRectMode == QCP::srmZoom) - connect(mSelectionRect, SIGNAL(accepted(QRect,QMouseEvent*)), this, SLOT(processRectZoom(QRect,QMouseEvent*))); + if( mSelectionRectMode == QCP::srmSelect ) + connect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectSelection( QRect, QMouseEvent* ) ) ); + else if( mSelectionRectMode == QCP::srmZoom ) + connect( mSelectionRect, SIGNAL( accepted( QRect, QMouseEvent* ) ), this, SLOT( processRectZoom( QRect, QMouseEvent* ) ) ); } } @@ -13325,40 +13426,42 @@ void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) QT variable in the qmake project files. For Qt versions 5.0 and higher, QCustomPlot switches to a newer OpenGL interface which is already in the "gui" module. */ -void QCustomPlot::setOpenGl(bool enabled, int multisampling) +void QCustomPlot::setOpenGl( bool enabled, int multisampling ) { - mOpenGlMultisamples = qMax(0, multisampling); + mOpenGlMultisamples = qMax( 0, multisampling ); #ifdef QCUSTOMPLOT_USE_OPENGL mOpenGl = enabled; - if (mOpenGl) + if( mOpenGl ) { - if (setupOpenGl()) + if( setupOpenGl() ) { // backup antialiasing override and labelcaching setting so we can restore upon disabling OpenGL mOpenGlAntialiasedElementsBackup = mAntialiasedElements; - mOpenGlCacheLabelsBackup = mPlottingHints.testFlag(QCP::phCacheLabels); + mOpenGlCacheLabelsBackup = mPlottingHints.testFlag( QCP::phCacheLabels ); // set antialiasing override to antialias all (aligns gl pixel grid properly), and disable label caching (would use software rasterizer for pixmap caches): - setAntialiasedElements(QCP::aeAll); - setPlottingHint(QCP::phCacheLabels, false); - } else + setAntialiasedElements( QCP::aeAll ); + setPlottingHint( QCP::phCacheLabels, false ); + } + else { qDebug() << Q_FUNC_INFO << "Failed to enable OpenGL, continuing plotting without hardware acceleration."; mOpenGl = false; } - } else + } + else { // restore antialiasing override and labelcaching to what it was before enabling OpenGL, if nobody changed it in the meantime: - if (mAntialiasedElements == QCP::aeAll) - setAntialiasedElements(mOpenGlAntialiasedElementsBackup); - if (!mPlottingHints.testFlag(QCP::phCacheLabels)) - setPlottingHint(QCP::phCacheLabels, mOpenGlCacheLabelsBackup); + if( mAntialiasedElements == QCP::aeAll ) + setAntialiasedElements( mOpenGlAntialiasedElementsBackup ); + if( !mPlottingHints.testFlag( QCP::phCacheLabels ) ) + setPlottingHint( QCP::phCacheLabels, mOpenGlCacheLabelsBackup ); freeOpenGl(); } // recreate all paint buffers: mPaintBuffers.clear(); setupPaintBuffers(); #else - Q_UNUSED(enabled) + Q_UNUSED( enabled ) qDebug() << Q_FUNC_INFO << "QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)"; #endif } @@ -13379,11 +13482,11 @@ void QCustomPlot::setOpenGl(bool enabled, int multisampling) This function is used to allow arbitrary size exports with \ref toPixmap, \ref savePng, \ref savePdf, etc. by temporarily changing the viewport size. */ -void QCustomPlot::setViewport(const QRect &rect) +void QCustomPlot::setViewport( const QRect& rect ) { mViewport = rect; - if (mPlotLayout) - mPlotLayout->setOuterRect(mViewport); + if( mPlotLayout ) + mPlotLayout->setOuterRect( mViewport ); } /*! @@ -13397,15 +13500,15 @@ void QCustomPlot::setViewport(const QRect &rect) when QCustomPlot is being used with older Qt versions, outputs an according qDebug message and leaves the internal buffer device pixel ratio at 1.0. */ -void QCustomPlot::setBufferDevicePixelRatio(double ratio) +void QCustomPlot::setBufferDevicePixelRatio( double ratio ) { - if (!qFuzzyCompare(ratio, mBufferDevicePixelRatio)) + if( !qFuzzyCompare( ratio, mBufferDevicePixelRatio ) ) { #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED mBufferDevicePixelRatio = ratio; - for (int i=0; isetDevicePixelRatio(mBufferDevicePixelRatio); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here + for( int i = 0; i < mPaintBuffers.size(); ++i ) + mPaintBuffers.at( i )->setDevicePixelRatio( mBufferDevicePixelRatio ); + // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here #else qDebug() << Q_FUNC_INFO << "Device pixel ratios not supported for Qt versions before 5.4"; mBufferDevicePixelRatio = 1.0; @@ -13428,7 +13531,7 @@ void QCustomPlot::setBufferDevicePixelRatio(double ratio) \see setBackgroundScaled, setBackgroundScaledMode */ -void QCustomPlot::setBackground(const QPixmap &pm) +void QCustomPlot::setBackground( const QPixmap& pm ) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -13447,7 +13550,7 @@ void QCustomPlot::setBackground(const QPixmap &pm) \see setBackgroundScaled, setBackgroundScaledMode */ -void QCustomPlot::setBackground(const QBrush &brush) +void QCustomPlot::setBackground( const QBrush& brush ) { mBackgroundBrush = brush; } @@ -13459,7 +13562,7 @@ void QCustomPlot::setBackground(const QBrush &brush) \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode */ -void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +void QCustomPlot::setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatioMode mode ) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -13477,7 +13580,7 @@ void QCustomPlot::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioM \see setBackground, setBackgroundScaledMode */ -void QCustomPlot::setBackgroundScaled(bool scaled) +void QCustomPlot::setBackgroundScaled( bool scaled ) { mBackgroundScaled = scaled; } @@ -13488,7 +13591,7 @@ void QCustomPlot::setBackgroundScaled(bool scaled) \see setBackground, setBackgroundScaled */ -void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) +void QCustomPlot::setBackgroundScaledMode( Qt::AspectRatioMode mode ) { mBackgroundScaledMode = mode; } @@ -13501,12 +13604,13 @@ void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) \see plottableCount */ -QCPAbstractPlottable *QCustomPlot::plottable(int index) +QCPAbstractPlottable* QCustomPlot::plottable( int index ) { - if (index >= 0 && index < mPlottables.size()) + if( index >= 0 && index < mPlottables.size() ) { - return mPlottables.at(index); - } else + return mPlottables.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return 0; @@ -13520,12 +13624,13 @@ QCPAbstractPlottable *QCustomPlot::plottable(int index) \see plottableCount */ -QCPAbstractPlottable *QCustomPlot::plottable() +QCPAbstractPlottable* QCustomPlot::plottable() { - if (!mPlottables.isEmpty()) + if( !mPlottables.isEmpty() ) { return mPlottables.last(); - } else + } + else return 0; } @@ -13537,22 +13642,22 @@ QCPAbstractPlottable *QCustomPlot::plottable() \see clearPlottables */ -bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) +bool QCustomPlot::removePlottable( QCPAbstractPlottable* plottable ) { - if (!mPlottables.contains(plottable)) + if( !mPlottables.contains( plottable ) ) { - qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast(plottable); + qDebug() << Q_FUNC_INFO << "plottable not in list:" << reinterpret_cast( plottable ); return false; } - + // remove plottable from legend: plottable->removeFromLegend(); // special handling for QCPGraphs to maintain the simple graph interface: - if (QCPGraph *graph = qobject_cast(plottable)) - mGraphs.removeOne(graph); + if( QCPGraph* graph = qobject_cast( plottable ) ) + mGraphs.removeOne( graph ); // remove plottable: delete plottable; - mPlottables.removeOne(plottable); + mPlottables.removeOne( plottable ); return true; } @@ -13560,10 +13665,10 @@ bool QCustomPlot::removePlottable(QCPAbstractPlottable *plottable) Removes and deletes the plottable by its \a index. */ -bool QCustomPlot::removePlottable(int index) +bool QCustomPlot::removePlottable( int index ) { - if (index >= 0 && index < mPlottables.size()) - return removePlottable(mPlottables[index]); + if( index >= 0 && index < mPlottables.size() ) + return removePlottable( mPlottables[index] ); else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; @@ -13582,8 +13687,8 @@ bool QCustomPlot::removePlottable(int index) int QCustomPlot::clearPlottables() { int c = mPlottables.size(); - for (int i=c-1; i >= 0; --i) - removePlottable(mPlottables[i]); + for( int i = c - 1; i >= 0; --i ) + removePlottable( mPlottables[i] ); return c; } @@ -13607,10 +13712,10 @@ int QCustomPlot::plottableCount() const QList QCustomPlot::selectedPlottables() const { QList result; - foreach (QCPAbstractPlottable *plottable, mPlottables) + foreach( QCPAbstractPlottable* plottable, mPlottables ) { - if (plottable->selected()) - result.append(plottable); + if( plottable->selected() ) + result.append( plottable ); } return result; } @@ -13627,35 +13732,35 @@ QList QCustomPlot::selectedPlottables() const \see itemAt, layoutElementAt */ -QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable) const +QCPAbstractPlottable* QCustomPlot::plottableAt( const QPointF& pos, bool onlySelectable ) const { - QCPAbstractPlottable *resultPlottable = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractPlottable *plottable, mPlottables) + QCPAbstractPlottable* resultPlottable = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach( QCPAbstractPlottable* plottable, mPlottables ) { - if (onlySelectable && !plottable->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable + if( onlySelectable && !plottable->selectable() ) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPabstractPlottable::selectable continue; - if ((plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect()).contains(pos.toPoint())) // only consider clicks inside the rect that is spanned by the plottable's key/value axes + if( ( plottable->keyAxis()->axisRect()->rect() & plottable->valueAxis()->axisRect()->rect() ).contains( pos.toPoint() ) ) // only consider clicks inside the rect that is spanned by the plottable's key/value axes { - double currentDistance = plottable->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) + double currentDistance = plottable->selectTest( pos, false ); + if( currentDistance >= 0 && currentDistance < resultDistance ) { resultPlottable = plottable; resultDistance = currentDistance; } } } - + return resultPlottable; } /*! Returns whether this QCustomPlot instance contains the \a plottable. */ -bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const +bool QCustomPlot::hasPlottable( QCPAbstractPlottable* plottable ) const { - return mPlottables.contains(plottable); + return mPlottables.contains( plottable ); } /*! @@ -13666,12 +13771,13 @@ bool QCustomPlot::hasPlottable(QCPAbstractPlottable *plottable) const \see graphCount, addGraph */ -QCPGraph *QCustomPlot::graph(int index) const +QCPGraph* QCustomPlot::graph( int index ) const { - if (index >= 0 && index < mGraphs.size()) + if( index >= 0 && index < mGraphs.size() ) { - return mGraphs.at(index); - } else + return mGraphs.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return 0; @@ -13685,12 +13791,13 @@ QCPGraph *QCustomPlot::graph(int index) const \see graphCount, addGraph */ -QCPGraph *QCustomPlot::graph() const +QCPGraph* QCustomPlot::graph() const { - if (!mGraphs.isEmpty()) + if( !mGraphs.isEmpty() ) { return mGraphs.last(); - } else + } + else return 0; } @@ -13706,23 +13813,25 @@ QCPGraph *QCustomPlot::graph() const \see graph, graphCount, removeGraph, clearGraphs */ -QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) +QCPGraph* QCustomPlot::addGraph( QCPAxis* keyAxis, QCPAxis* valueAxis ) { - if (!keyAxis) keyAxis = xAxis; - if (!valueAxis) valueAxis = yAxis; - if (!keyAxis || !valueAxis) + if( !keyAxis ) + keyAxis = xAxis; + if( !valueAxis ) + valueAxis = yAxis; + if( !keyAxis || !valueAxis ) { qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)"; return 0; } - if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this) + if( keyAxis->parentPlot() != this || valueAxis->parentPlot() != this ) { qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent"; return 0; } - - QCPGraph *newGraph = new QCPGraph(keyAxis, valueAxis); - newGraph->setName(QLatin1String("Graph ")+QString::number(mGraphs.size())); + + QCPGraph* newGraph = new QCPGraph( keyAxis, valueAxis ); + newGraph->setName( QLatin1String( "Graph " ) + QString::number( mGraphs.size() ) ); return newGraph; } @@ -13736,19 +13845,19 @@ QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) \see clearGraphs */ -bool QCustomPlot::removeGraph(QCPGraph *graph) +bool QCustomPlot::removeGraph( QCPGraph* graph ) { - return removePlottable(graph); + return removePlottable( graph ); } /*! \overload Removes and deletes the graph by its \a index. */ -bool QCustomPlot::removeGraph(int index) +bool QCustomPlot::removeGraph( int index ) { - if (index >= 0 && index < mGraphs.size()) - return removeGraph(mGraphs[index]); + if( index >= 0 && index < mGraphs.size() ) + return removeGraph( mGraphs[index] ); else return false; } @@ -13764,8 +13873,8 @@ bool QCustomPlot::removeGraph(int index) int QCustomPlot::clearGraphs() { int c = mGraphs.size(); - for (int i=c-1; i >= 0; --i) - removeGraph(mGraphs[i]); + for( int i = c - 1; i >= 0; --i ) + removeGraph( mGraphs[i] ); return c; } @@ -13790,10 +13899,10 @@ int QCustomPlot::graphCount() const QList QCustomPlot::selectedGraphs() const { QList result; - foreach (QCPGraph *graph, mGraphs) + foreach( QCPGraph* graph, mGraphs ) { - if (graph->selected()) - result.append(graph); + if( graph->selected() ) + result.append( graph ); } return result; } @@ -13806,12 +13915,13 @@ QList QCustomPlot::selectedGraphs() const \see itemCount */ -QCPAbstractItem *QCustomPlot::item(int index) const +QCPAbstractItem* QCustomPlot::item( int index ) const { - if (index >= 0 && index < mItems.size()) + if( index >= 0 && index < mItems.size() ) { - return mItems.at(index); - } else + return mItems.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return 0; @@ -13825,12 +13935,13 @@ QCPAbstractItem *QCustomPlot::item(int index) const \see itemCount */ -QCPAbstractItem *QCustomPlot::item() const +QCPAbstractItem* QCustomPlot::item() const { - if (!mItems.isEmpty()) + if( !mItems.isEmpty() ) { return mItems.last(); - } else + } + else return 0; } @@ -13841,16 +13952,17 @@ QCPAbstractItem *QCustomPlot::item() const \see clearItems */ -bool QCustomPlot::removeItem(QCPAbstractItem *item) +bool QCustomPlot::removeItem( QCPAbstractItem* item ) { - if (mItems.contains(item)) + if( mItems.contains( item ) ) { delete item; - mItems.removeOne(item); + mItems.removeOne( item ); return true; - } else + } + else { - qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast(item); + qDebug() << Q_FUNC_INFO << "item not in list:" << reinterpret_cast( item ); return false; } } @@ -13859,10 +13971,10 @@ bool QCustomPlot::removeItem(QCPAbstractItem *item) Removes and deletes the item by its \a index. */ -bool QCustomPlot::removeItem(int index) +bool QCustomPlot::removeItem( int index ) { - if (index >= 0 && index < mItems.size()) - return removeItem(mItems[index]); + if( index >= 0 && index < mItems.size() ) + return removeItem( mItems[index] ); else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; @@ -13880,8 +13992,8 @@ bool QCustomPlot::removeItem(int index) int QCustomPlot::clearItems() { int c = mItems.size(); - for (int i=c-1; i >= 0; --i) - removeItem(mItems[i]); + for( int i = c - 1; i >= 0; --i ) + removeItem( mItems[i] ); return c; } @@ -13903,10 +14015,10 @@ int QCustomPlot::itemCount() const QList QCustomPlot::selectedItems() const { QList result; - foreach (QCPAbstractItem *item, mItems) + foreach( QCPAbstractItem* item, mItems ) { - if (item->selected()) - result.append(item); + if( item->selected() ) + result.append( item ); } return result; } @@ -13924,26 +14036,26 @@ QList QCustomPlot::selectedItems() const \see plottableAt, layoutElementAt */ -QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const +QCPAbstractItem* QCustomPlot::itemAt( const QPointF& pos, bool onlySelectable ) const { - QCPAbstractItem *resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach (QCPAbstractItem *item, mItems) + QCPAbstractItem* resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach( QCPAbstractItem* item, mItems ) { - if (onlySelectable && !item->selectable()) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + if( onlySelectable && !item->selectable() ) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable continue; - if (!item->clipToAxisRect() || item->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it + if( !item->clipToAxisRect() || item->clipRect().contains( pos.toPoint() ) ) // only consider clicks inside axis cliprect of the item if actually clipped to it { - double currentDistance = item->selectTest(pos, false); - if (currentDistance >= 0 && currentDistance < resultDistance) + double currentDistance = item->selectTest( pos, false ); + if( currentDistance >= 0 && currentDistance < resultDistance ) { resultItem = item; resultDistance = currentDistance; } } } - + return resultItem; } @@ -13952,9 +14064,9 @@ QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) co \see item */ -bool QCustomPlot::hasItem(QCPAbstractItem *item) const +bool QCustomPlot::hasItem( QCPAbstractItem* item ) const { - return mItems.contains(item); + return mItems.contains( item ); } /*! @@ -13965,11 +14077,11 @@ bool QCustomPlot::hasItem(QCPAbstractItem *item) const \see addLayer, moveLayer, removeLayer */ -QCPLayer *QCustomPlot::layer(const QString &name) const +QCPLayer* QCustomPlot::layer( const QString& name ) const { - foreach (QCPLayer *layer, mLayers) + foreach( QCPLayer* layer, mLayers ) { - if (layer->name() == name) + if( layer->name() == name ) return layer; } return 0; @@ -13981,12 +14093,13 @@ QCPLayer *QCustomPlot::layer(const QString &name) const \see addLayer, moveLayer, removeLayer */ -QCPLayer *QCustomPlot::layer(int index) const +QCPLayer* QCustomPlot::layer( int index ) const { - if (index >= 0 && index < mLayers.size()) + if( index >= 0 && index < mLayers.size() ) { - return mLayers.at(index); - } else + return mLayers.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return 0; @@ -13996,7 +14109,7 @@ QCPLayer *QCustomPlot::layer(int index) const /*! Returns the layer that is set as current layer (see \ref setCurrentLayer). */ -QCPLayer *QCustomPlot::currentLayer() const +QCPLayer* QCustomPlot::currentLayer() const { return mCurrentLayer; } @@ -14011,12 +14124,13 @@ QCPLayer *QCustomPlot::currentLayer() const \see addLayer, moveLayer, removeLayer, QCPLayerable::setLayer */ -bool QCustomPlot::setCurrentLayer(const QString &name) +bool QCustomPlot::setCurrentLayer( const QString& name ) { - if (QCPLayer *newCurrentLayer = layer(name)) + if( QCPLayer* newCurrentLayer = layer( name ) ) { - return setCurrentLayer(newCurrentLayer); - } else + return setCurrentLayer( newCurrentLayer ); + } + else { qDebug() << Q_FUNC_INFO << "layer with name doesn't exist:" << name; return false; @@ -14031,14 +14145,14 @@ bool QCustomPlot::setCurrentLayer(const QString &name) \see addLayer, moveLayer, removeLayer */ -bool QCustomPlot::setCurrentLayer(QCPLayer *layer) +bool QCustomPlot::setCurrentLayer( QCPLayer* layer ) { - if (!mLayers.contains(layer)) + if( !mLayers.contains( layer ) ) { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast( layer ); return false; } - + mCurrentLayer = layer; return true; } @@ -14066,25 +14180,25 @@ int QCustomPlot::layerCount() const \see layer, moveLayer, removeLayer */ -bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +bool QCustomPlot::addLayer( const QString& name, QCPLayer* otherLayer, QCustomPlot::LayerInsertMode insertMode ) { - if (!otherLayer) + if( !otherLayer ) otherLayer = mLayers.last(); - if (!mLayers.contains(otherLayer)) + if( !mLayers.contains( otherLayer ) ) { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast( otherLayer ); return false; } - if (layer(name)) + if( layer( name ) ) { qDebug() << Q_FUNC_INFO << "A layer exists already with the name" << name; return false; } - - QCPLayer *newLayer = new QCPLayer(this, name); - mLayers.insert(otherLayer->index() + (insertMode==limAbove ? 1:0), newLayer); + + QCPLayer* newLayer = new QCPLayer( this, name ); + mLayers.insert( otherLayer->index() + ( insertMode == limAbove ? 1 : 0 ), newLayer ); updateLayerIndices(); - setupPaintBuffers(); // associates new layer with the appropriate paint buffer + setupPaintBuffers(); // associates new layer with the appropriate paint buffer return true; } @@ -14102,42 +14216,43 @@ bool QCustomPlot::addLayer(const QString &name, QCPLayer *otherLayer, QCustomPlo \see layer, addLayer, moveLayer */ -bool QCustomPlot::removeLayer(QCPLayer *layer) +bool QCustomPlot::removeLayer( QCPLayer* layer ) { - if (!mLayers.contains(layer)) + if( !mLayers.contains( layer ) ) { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast( layer ); return false; } - if (mLayers.size() < 2) + if( mLayers.size() < 2 ) { qDebug() << Q_FUNC_INFO << "can't remove last layer"; return false; } - + // append all children of this layer to layer below (if this is lowest layer, prepend to layer above) int removedIndex = layer->index(); - bool isFirstLayer = removedIndex==0; - QCPLayer *targetLayer = isFirstLayer ? mLayers.at(removedIndex+1) : mLayers.at(removedIndex-1); + bool isFirstLayer = removedIndex == 0; + QCPLayer* targetLayer = isFirstLayer ? mLayers.at( removedIndex + 1 ) : mLayers.at( removedIndex - 1 ); QList children = layer->children(); - if (isFirstLayer) // prepend in reverse order (so order relative to each other stays the same) + if( isFirstLayer ) // prepend in reverse order (so order relative to each other stays the same) { - for (int i=children.size()-1; i>=0; --i) - children.at(i)->moveToLayer(targetLayer, true); - } else // append normally + for( int i = children.size() - 1; i >= 0; --i ) + children.at( i )->moveToLayer( targetLayer, true ); + } + else // append normally { - for (int i=0; imoveToLayer(targetLayer, false); + for( int i = 0; i < children.size(); ++i ) + children.at( i )->moveToLayer( targetLayer, false ); } // if removed layer is current layer, change current layer to layer below/above: - if (layer == mCurrentLayer) - setCurrentLayer(targetLayer); + if( layer == mCurrentLayer ) + setCurrentLayer( targetLayer ); // invalidate the paint buffer that was responsible for this layer: - if (!layer->mPaintBuffer.isNull()) + if( !layer->mPaintBuffer.isNull() ) layer->mPaintBuffer.data()->setInvalidated(); // remove layer: delete layer; - mLayers.removeOne(layer); + mLayers.removeOne( layer ); updateLayerIndices(); return true; } @@ -14151,30 +14266,30 @@ bool QCustomPlot::removeLayer(QCPLayer *layer) \see layer, addLayer, moveLayer */ -bool QCustomPlot::moveLayer(QCPLayer *layer, QCPLayer *otherLayer, QCustomPlot::LayerInsertMode insertMode) +bool QCustomPlot::moveLayer( QCPLayer* layer, QCPLayer* otherLayer, QCustomPlot::LayerInsertMode insertMode ) { - if (!mLayers.contains(layer)) + if( !mLayers.contains( layer ) ) { - qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast(layer); + qDebug() << Q_FUNC_INFO << "layer not a layer of this QCustomPlot:" << reinterpret_cast( layer ); return false; } - if (!mLayers.contains(otherLayer)) + if( !mLayers.contains( otherLayer ) ) { - qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast(otherLayer); + qDebug() << Q_FUNC_INFO << "otherLayer not a layer of this QCustomPlot:" << reinterpret_cast( otherLayer ); return false; } - - if (layer->index() > otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 1:0)); - else if (layer->index() < otherLayer->index()) - mLayers.move(layer->index(), otherLayer->index() + (insertMode==limAbove ? 0:-1)); - + + if( layer->index() > otherLayer->index() ) + mLayers.move( layer->index(), otherLayer->index() + ( insertMode == limAbove ? 1 : 0 ) ); + else if( layer->index() < otherLayer->index() ) + mLayers.move( layer->index(), otherLayer->index() + ( insertMode == limAbove ? 0 : -1 ) ); + // invalidate the paint buffers that are responsible for the layers: - if (!layer->mPaintBuffer.isNull()) + if( !layer->mPaintBuffer.isNull() ) layer->mPaintBuffer.data()->setInvalidated(); - if (!otherLayer->mPaintBuffer.isNull()) + if( !otherLayer->mPaintBuffer.isNull() ) otherLayer->mPaintBuffer.data()->setInvalidated(); - + updateLayerIndices(); return true; } @@ -14212,13 +14327,14 @@ int QCustomPlot::axisRectCount() const \see axisRectCount, axisRects, QCPLayoutGrid::setFillOrder */ -QCPAxisRect *QCustomPlot::axisRect(int index) const +QCPAxisRect* QCustomPlot::axisRect( int index ) const { const QList rectList = axisRects(); - if (index >= 0 && index < rectList.size()) + if( index >= 0 && index < rectList.size() ) { - return rectList.at(index); - } else + return rectList.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "invalid axis rect index" << index; return 0; @@ -14240,22 +14356,22 @@ QList QCustomPlot::axisRects() const { QList result; QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) + if( mPlotLayout ) + elementStack.push( mPlotLayout ); + + while( !elementStack.isEmpty() ) { - foreach (QCPLayoutElement *element, elementStack.pop()->elements(false)) + foreach( QCPLayoutElement* element, elementStack.pop()->elements( false ) ) { - if (element) + if( element ) { - elementStack.push(element); - if (QCPAxisRect *ar = qobject_cast(element)) - result.append(ar); + elementStack.push( element ); + if( QCPAxisRect* ar = qobject_cast( element ) ) + result.append( ar ); } } } - + return result; } @@ -14268,16 +14384,16 @@ QList QCustomPlot::axisRects() const \see itemAt, plottableAt */ -QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const +QCPLayoutElement* QCustomPlot::layoutElementAt( const QPointF& pos ) const { - QCPLayoutElement *currentElement = mPlotLayout; + QCPLayoutElement* currentElement = mPlotLayout; bool searchSubElements = true; - while (searchSubElements && currentElement) + while( searchSubElements && currentElement ) { searchSubElements = false; - foreach (QCPLayoutElement *subElement, currentElement->elements(false)) + foreach( QCPLayoutElement* subElement, currentElement->elements( false ) ) { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + if( subElement && subElement->realVisibility() && subElement->selectTest( pos, false ) >= 0 ) { currentElement = subElement; searchSubElements = true; @@ -14298,21 +14414,21 @@ QCPLayoutElement *QCustomPlot::layoutElementAt(const QPointF &pos) const \see layoutElementAt */ -QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const +QCPAxisRect* QCustomPlot::axisRectAt( const QPointF& pos ) const { - QCPAxisRect *result = 0; - QCPLayoutElement *currentElement = mPlotLayout; + QCPAxisRect* result = 0; + QCPLayoutElement* currentElement = mPlotLayout; bool searchSubElements = true; - while (searchSubElements && currentElement) + while( searchSubElements && currentElement ) { searchSubElements = false; - foreach (QCPLayoutElement *subElement, currentElement->elements(false)) + foreach( QCPLayoutElement* subElement, currentElement->elements( false ) ) { - if (subElement && subElement->realVisibility() && subElement->selectTest(pos, false) >= 0) + if( subElement && subElement->realVisibility() && subElement->selectTest( pos, false ) >= 0 ) { currentElement = subElement; searchSubElements = true; - if (QCPAxisRect *ar = qobject_cast(currentElement)) + if( QCPAxisRect* ar = qobject_cast( currentElement ) ) result = ar; break; } @@ -14331,15 +14447,15 @@ QCPAxisRect *QCustomPlot::axisRectAt(const QPointF &pos) const QList QCustomPlot::selectedAxes() const { QList result, allAxes; - foreach (QCPAxisRect *rect, axisRects()) + foreach( QCPAxisRect* rect, axisRects() ) allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) + + foreach( QCPAxis* axis, allAxes ) { - if (axis->selectedParts() != QCPAxis::spNone) - result.append(axis); + if( axis->selectedParts() != QCPAxis::spNone ) + result.append( axis ); } - + return result; } @@ -14353,27 +14469,27 @@ QList QCustomPlot::selectedAxes() const QList QCustomPlot::selectedLegends() const { QList result; - + QStack elementStack; - if (mPlotLayout) - elementStack.push(mPlotLayout); - - while (!elementStack.isEmpty()) + if( mPlotLayout ) + elementStack.push( mPlotLayout ); + + while( !elementStack.isEmpty() ) { - foreach (QCPLayoutElement *subElement, elementStack.pop()->elements(false)) + foreach( QCPLayoutElement* subElement, elementStack.pop()->elements( false ) ) { - if (subElement) + if( subElement ) { - elementStack.push(subElement); - if (QCPLegend *leg = qobject_cast(subElement)) + elementStack.push( subElement ); + if( QCPLegend* leg = qobject_cast( subElement ) ) { - if (leg->selectedParts() != QCPLegend::spNone) - result.append(leg); + if( leg->selectedParts() != QCPLegend::spNone ) + result.append( leg ); } } } } - + return result; } @@ -14388,10 +14504,10 @@ QList QCustomPlot::selectedLegends() const */ void QCustomPlot::deselectAll() { - foreach (QCPLayer *layer, mLayers) + foreach( QCPLayer* layer, mLayers ) { - foreach (QCPLayerable *layerable, layer->children()) - layerable->deselectEvent(0); + foreach( QCPLayerable* layerable, layer->children() ) + layerable->deselectEvent( 0 ); } } @@ -14420,37 +14536,37 @@ void QCustomPlot::deselectAll() replot only that specific layer via \ref QCPLayer::replot. See the documentation there for details. */ -void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) +void QCustomPlot::replot( QCustomPlot::RefreshPriority refreshPriority ) { - if (refreshPriority == QCustomPlot::rpQueuedReplot) + if( refreshPriority == QCustomPlot::rpQueuedReplot ) { - if (!mReplotQueued) + if( !mReplotQueued ) { mReplotQueued = true; - QTimer::singleShot(0, this, SLOT(replot())); + QTimer::singleShot( 0, this, SLOT( replot() ) ); } return; } - - if (mReplotting) // incase signals loop back to replot slot + + if( mReplotting ) // incase signals loop back to replot slot return; mReplotting = true; mReplotQueued = false; emit beforeReplot(); - + updateLayout(); // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: setupPaintBuffers(); - foreach (QCPLayer *layer, mLayers) + foreach( QCPLayer* layer, mLayers ) layer->drawToPaintBuffer(); - for (int i=0; isetInvalidated(false); - - if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) + for( int i = 0; i < mPaintBuffers.size(); ++i ) + mPaintBuffers.at( i )->setInvalidated( false ); + + if( ( refreshPriority == rpRefreshHint && mPlottingHints.testFlag( QCP::phImmediateRefresh ) ) || refreshPriority == rpImmediateRefresh ) repaint(); else update(); - + emit afterReplot(); mReplotting = false; } @@ -14463,14 +14579,14 @@ void QCustomPlot::replot(QCustomPlot::RefreshPriority refreshPriority) \see QCPAbstractPlottable::rescaleAxes, QCPAxis::rescale */ -void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) +void QCustomPlot::rescaleAxes( bool onlyVisiblePlottables ) { QList allAxes; - foreach (QCPAxisRect *rect, axisRects()) + foreach( QCPAxisRect* rect, axisRects() ) allAxes << rect->axes(); - - foreach (QCPAxis *axis, allAxes) - axis->rescale(onlyVisiblePlottables); + + foreach( QCPAxis* axis, allAxes ) + axis->rescale( onlyVisiblePlottables ); } /*! @@ -14510,66 +14626,67 @@ void QCustomPlot::rescaleAxes(bool onlyVisiblePlottables) \see savePng, saveBmp, saveJpg, saveRastered */ -bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::ExportPen exportPen, const QString &pdfCreator, const QString &pdfTitle) +bool QCustomPlot::savePdf( const QString& fileName, int width, int height, QCP::ExportPen exportPen, const QString& pdfCreator, const QString& pdfTitle ) { bool success = false; #ifdef QT_NO_PRINTER - Q_UNUSED(fileName) - Q_UNUSED(exportPen) - Q_UNUSED(width) - Q_UNUSED(height) - Q_UNUSED(pdfCreator) - Q_UNUSED(pdfTitle) + Q_UNUSED( fileName ) + Q_UNUSED( exportPen ) + Q_UNUSED( width ) + Q_UNUSED( height ) + Q_UNUSED( pdfCreator ) + Q_UNUSED( pdfTitle ) qDebug() << Q_FUNC_INFO << "Qt was built without printer support (QT_NO_PRINTER). PDF not created."; #else int newWidth, newHeight; - if (width == 0 || height == 0) + if( width == 0 || height == 0 ) { newWidth = this->width(); newHeight = this->height(); - } else + } + else { newWidth = width; newHeight = height; } - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFileName(fileName); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.printEngine()->setProperty(QPrintEngine::PPK_Creator, pdfCreator); - printer.printEngine()->setProperty(QPrintEngine::PPK_DocumentName, pdfTitle); + + QPrinter printer( QPrinter::ScreenResolution ); + printer.setOutputFileName( fileName ); + printer.setOutputFormat( QPrinter::PdfFormat ); + printer.setColorMode( QPrinter::Color ); + printer.printEngine()->setProperty( QPrintEngine::PPK_Creator, pdfCreator ); + printer.printEngine()->setProperty( QPrintEngine::PPK_DocumentName, pdfTitle ); QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); -#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) - printer.setFullPage(true); - printer.setPaperSize(viewport().size(), QPrinter::DevicePixel); + setViewport( QRect( 0, 0, newWidth, newHeight ) ); +#if QT_VERSION < QT_VERSION_CHECK( 5, 3, 0 ) + printer.setFullPage( true ); + printer.setPaperSize( viewport().size(), QPrinter::DevicePixel ); #else QPageLayout pageLayout; - pageLayout.setMode(QPageLayout::FullPageMode); - pageLayout.setOrientation(QPageLayout::Portrait); - pageLayout.setMargins(QMarginsF(0, 0, 0, 0)); - pageLayout.setPageSize(QPageSize(viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch)); - printer.setPageLayout(pageLayout); + pageLayout.setMode( QPageLayout::FullPageMode ); + pageLayout.setOrientation( QPageLayout::Portrait ); + pageLayout.setMargins( QMarginsF( 0, 0, 0, 0 ) ); + pageLayout.setPageSize( QPageSize( viewport().size(), QPageSize::Point, QString(), QPageSize::ExactMatch ) ); + printer.setPageLayout( pageLayout ); #endif QCPPainter printpainter; - if (printpainter.begin(&printer)) + if( printpainter.begin( &printer ) ) { - printpainter.setMode(QCPPainter::pmVectorized); - printpainter.setMode(QCPPainter::pmNoCaching); - printpainter.setMode(QCPPainter::pmNonCosmetic, exportPen==QCP::epNoCosmetic); - printpainter.setWindow(mViewport); - if (mBackgroundBrush.style() != Qt::NoBrush && + printpainter.setMode( QCPPainter::pmVectorized ); + printpainter.setMode( QCPPainter::pmNoCaching ); + printpainter.setMode( QCPPainter::pmNonCosmetic, exportPen == QCP::epNoCosmetic ); + printpainter.setWindow( mViewport ); + if( mBackgroundBrush.style() != Qt::NoBrush && mBackgroundBrush.color() != Qt::white && mBackgroundBrush.color() != Qt::transparent && - mBackgroundBrush.color().alpha() > 0) // draw pdf background color if not white/transparent - printpainter.fillRect(viewport(), mBackgroundBrush); - draw(&printpainter); + mBackgroundBrush.color().alpha() > 0 ) // draw pdf background color if not white/transparent + printpainter.fillRect( viewport(), mBackgroundBrush ); + draw( &printpainter ); printpainter.end(); success = true; } - setViewport(oldViewport); -#endif // QT_NO_PRINTER + setViewport( oldViewport ); +#endif // QT_NO_PRINTER return success; } @@ -14618,9 +14735,9 @@ bool QCustomPlot::savePdf(const QString &fileName, int width, int height, QCP::E \see savePdf, saveBmp, saveJpg, saveRastered */ -bool QCustomPlot::savePng(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +bool QCustomPlot::savePng( const QString& fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit ) { - return saveRastered(fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit); + return saveRastered( fileName, width, height, scale, "PNG", quality, resolution, resolutionUnit ); } /*! @@ -14665,9 +14782,9 @@ bool QCustomPlot::savePng(const QString &fileName, int width, int height, double \see savePdf, savePng, saveBmp, saveRastered */ -bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +bool QCustomPlot::saveJpg( const QString& fileName, int width, int height, double scale, int quality, int resolution, QCP::ResolutionUnit resolutionUnit ) { - return saveRastered(fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit); + return saveRastered( fileName, width, height, scale, "JPG", quality, resolution, resolutionUnit ); } /*! @@ -14709,9 +14826,9 @@ bool QCustomPlot::saveJpg(const QString &fileName, int width, int height, double \see savePdf, savePng, saveJpg, saveRastered */ -bool QCustomPlot::saveBmp(const QString &fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit) +bool QCustomPlot::saveBmp( const QString& fileName, int width, int height, double scale, int resolution, QCP::ResolutionUnit resolutionUnit ) { - return saveRastered(fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit); + return saveRastered( fileName, width, height, scale, "BMP", -1, resolution, resolutionUnit ); } /*! \internal @@ -14742,18 +14859,18 @@ QSize QCustomPlot::sizeHint() const Event handler for when the QCustomPlot widget needs repainting. This does not cause a \ref replot, but draws the internal buffer on the widget surface. */ -void QCustomPlot::paintEvent(QPaintEvent *event) +void QCustomPlot::paintEvent( QPaintEvent* event ) { - Q_UNUSED(event); - QCPPainter painter(this); - if (painter.isActive()) + Q_UNUSED( event ); + QCPPainter painter( this ); + if( painter.isActive() ) { - painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem - if (mBackgroundBrush.style() != Qt::NoBrush) - painter.fillRect(mViewport, mBackgroundBrush); - drawBackground(&painter); - for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex) - mPaintBuffers.at(bufferIndex)->draw(&painter); + painter.setRenderHint( QPainter::HighQualityAntialiasing ); // to make Antialiasing look good if using the OpenGL graphicssystem + if( mBackgroundBrush.style() != Qt::NoBrush ) + painter.fillRect( mViewport, mBackgroundBrush ); + drawBackground( &painter ); + for( int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex ) + mPaintBuffers.at( bufferIndex )->draw( &painter ); } } @@ -14762,12 +14879,12 @@ void QCustomPlot::paintEvent(QPaintEvent *event) Event handler for a resize of the QCustomPlot widget. The viewport (which becomes the outer rect of mPlotLayout) is resized appropriately. Finally a \ref replot is performed. */ -void QCustomPlot::resizeEvent(QResizeEvent *event) +void QCustomPlot::resizeEvent( QResizeEvent* event ) { - Q_UNUSED(event) + Q_UNUSED( event ) // resize and repaint the buffer: - setViewport(rect()); - replot(rpQueuedRefresh); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) + setViewport( rect() ); + replot( rpQueuedRefresh ); // queued refresh is important here, to prevent painting issues in some contexts (e.g. MDI subwindow) } /*! \internal @@ -14779,47 +14896,48 @@ void QCustomPlot::resizeEvent(QResizeEvent *event) \see mousePressEvent, mouseReleaseEvent */ -void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) +void QCustomPlot::mouseDoubleClickEvent( QMouseEvent* event ) { - emit mouseDoubleClick(event); + emit mouseDoubleClick( event ); mMouseHasMoved = false; mMousePressPos = event->pos(); - + // determine layerable under the cursor (this event is called instead of the second press event in a double-click): QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - for (int i=0; i candidates = layerableListAt( mMousePressPos, false, &details ); + for( int i = 0; i < candidates.size(); ++i ) { - event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->mouseDoubleClickEvent(event, details.at(i)); - if (event->isAccepted()) + event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at( i )->mouseDoubleClickEvent( event, details.at( i ) ); + if( event->isAccepted() ) { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); + mMouseEventLayerable = candidates.at( i ); + mMouseEventLayerableDetails = details.at( i ); break; } } - + // emit specialized object double click signals: - if (!candidates.isEmpty()) + if( !candidates.isEmpty() ) { - if (QCPAbstractPlottable *ap = qobject_cast(candidates.first())) + if( QCPAbstractPlottable* ap = qobject_cast( candidates.first() ) ) { int dataIndex = 0; - if (!details.first().value().isEmpty()) + if( !details.first().value().isEmpty() ) dataIndex = details.first().value().dataRange().begin(); - emit plottableDoubleClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(candidates.first())) - emit axisDoubleClick(ax, details.first().value(), event); - else if (QCPAbstractItem *ai = qobject_cast(candidates.first())) - emit itemDoubleClick(ai, event); - else if (QCPLegend *lg = qobject_cast(candidates.first())) - emit legendDoubleClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(candidates.first())) - emit legendDoubleClick(li->parentLegend(), li, event); + emit plottableDoubleClick( ap, dataIndex, event ); + } + else if( QCPAxis* ax = qobject_cast( candidates.first() ) ) + emit axisDoubleClick( ax, details.first().value(), event ); + else if( QCPAbstractItem* ai = qobject_cast( candidates.first() ) ) + emit itemDoubleClick( ai, event ); + else if( QCPLegend* lg = qobject_cast( candidates.first() ) ) + emit legendDoubleClick( lg, 0, event ); + else if( QCPAbstractLegendItem* li = qobject_cast( candidates.first() ) ) + emit legendDoubleClick( li->parentLegend(), li, event ); } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. } /*! \internal @@ -14831,42 +14949,43 @@ void QCustomPlot::mouseDoubleClickEvent(QMouseEvent *event) \see mouseMoveEvent, mouseReleaseEvent */ -void QCustomPlot::mousePressEvent(QMouseEvent *event) +void QCustomPlot::mousePressEvent( QMouseEvent* event ) { - emit mousePress(event); + emit mousePress( event ); // save some state to tell in releaseEvent whether it was a click: mMouseHasMoved = false; mMousePressPos = event->pos(); - - if (mSelectionRect && mSelectionRectMode != QCP::srmNone) + + if( mSelectionRect && mSelectionRectMode != QCP::srmNone ) { - if (mSelectionRectMode != QCP::srmZoom || qobject_cast(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rect - mSelectionRect->startSelection(event); - } else + if( mSelectionRectMode != QCP::srmZoom || qobject_cast( axisRectAt( mMousePressPos ) ) ) // in zoom mode only activate selection rect if on an axis rect + mSelectionRect->startSelection( event ); + } + else { // no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor: QList details; - QList candidates = layerableListAt(mMousePressPos, false, &details); - if (!candidates.isEmpty()) + QList candidates = layerableListAt( mMousePressPos, false, &details ); + if( !candidates.isEmpty() ) { - mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) + mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event) mMouseSignalLayerableDetails = details.first(); } // forward event to topmost candidate which accepts the event: - for (int i=0; iaccept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list - candidates.at(i)->mousePressEvent(event, details.at(i)); - if (event->isAccepted()) + event->accept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in list + candidates.at( i )->mousePressEvent( event, details.at( i ) ); + if( event->isAccepted() ) { - mMouseEventLayerable = candidates.at(i); - mMouseEventLayerableDetails = details.at(i); + mMouseEventLayerable = candidates.at( i ); + mMouseEventLayerableDetails = details.at( i ); break; } } } - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. } /*! \internal @@ -14881,19 +15000,19 @@ void QCustomPlot::mousePressEvent(QMouseEvent *event) \see mousePressEvent, mouseReleaseEvent */ -void QCustomPlot::mouseMoveEvent(QMouseEvent *event) +void QCustomPlot::mouseMoveEvent( QMouseEvent* event ) { - emit mouseMove(event); - - if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3) - mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release - - if (mSelectionRect && mSelectionRect->isActive()) - mSelectionRect->moveSelection(event); - else if (mMouseEventLayerable) // call event of affected layerable: - mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. + emit mouseMove( event ); + + if( !mMouseHasMoved && ( mMousePressPos - event->pos() ).manhattanLength() > 3 ) + mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse release + + if( mSelectionRect && mSelectionRect->isActive() ) + mSelectionRect->moveSelection( event ); + else if( mMouseEventLayerable ) // call event of affected layerable: + mMouseEventLayerable->mouseMoveEvent( event, mMousePressPos ); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. } /*! \internal @@ -14910,53 +15029,55 @@ void QCustomPlot::mouseMoveEvent(QMouseEvent *event) \see mousePressEvent, mouseMoveEvent */ -void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) +void QCustomPlot::mouseReleaseEvent( QMouseEvent* event ) { - emit mouseRelease(event); - - if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click + emit mouseRelease( event ); + + if( !mMouseHasMoved ) // mouse hasn't moved (much) between press and release, so handle as click { - if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it here + if( mSelectionRect && mSelectionRect->isActive() ) // a simple click shouldn't successfully finish a selection rect, so cancel it here mSelectionRect->cancel(); - if (event->button() == Qt::LeftButton) - processPointSelection(event); - + if( event->button() == Qt::LeftButton ) + processPointSelection( event ); + // emit specialized click signals of QCustomPlot instance: - if (QCPAbstractPlottable *ap = qobject_cast(mMouseSignalLayerable)) + if( QCPAbstractPlottable* ap = qobject_cast( mMouseSignalLayerable ) ) { int dataIndex = 0; - if (!mMouseSignalLayerableDetails.value().isEmpty()) + if( !mMouseSignalLayerableDetails.value().isEmpty() ) dataIndex = mMouseSignalLayerableDetails.value().dataRange().begin(); - emit plottableClick(ap, dataIndex, event); - } else if (QCPAxis *ax = qobject_cast(mMouseSignalLayerable)) - emit axisClick(ax, mMouseSignalLayerableDetails.value(), event); - else if (QCPAbstractItem *ai = qobject_cast(mMouseSignalLayerable)) - emit itemClick(ai, event); - else if (QCPLegend *lg = qobject_cast(mMouseSignalLayerable)) - emit legendClick(lg, 0, event); - else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) - emit legendClick(li->parentLegend(), li, event); + emit plottableClick( ap, dataIndex, event ); + } + else if( QCPAxis* ax = qobject_cast( mMouseSignalLayerable ) ) + emit axisClick( ax, mMouseSignalLayerableDetails.value(), event ); + else if( QCPAbstractItem* ai = qobject_cast( mMouseSignalLayerable ) ) + emit itemClick( ai, event ); + else if( QCPLegend* lg = qobject_cast( mMouseSignalLayerable ) ) + emit legendClick( lg, 0, event ); + else if( QCPAbstractLegendItem* li = qobject_cast( mMouseSignalLayerable ) ) + emit legendClick( li->parentLegend(), li, event ); mMouseSignalLayerable = 0; } - - if (mSelectionRect && mSelectionRect->isActive()) // Note: if a click was detected above, the selection rect is canceled there + + if( mSelectionRect && mSelectionRect->isActive() ) // Note: if a click was detected above, the selection rect is canceled there { // finish selection rect, the appropriate action will be taken via signal-slot connection: - mSelectionRect->endSelection(event); - } else + mSelectionRect->endSelection( event ); + } + else { // call event of affected layerable: - if (mMouseEventLayerable) + if( mMouseEventLayerable ) { - mMouseEventLayerable->mouseReleaseEvent(event, mMousePressPos); + mMouseEventLayerable->mouseReleaseEvent( event, mMousePressPos ); mMouseEventLayerable = 0; } } - - if (noAntialiasingOnDrag()) - replot(rpQueuedReplot); - - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. + + if( noAntialiasingOnDrag() ) + replot( rpQueuedReplot ); + + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. } /*! \internal @@ -14964,19 +15085,19 @@ void QCustomPlot::mouseReleaseEvent(QMouseEvent *event) Event handler for mouse wheel events. First, the \ref mouseWheel signal is emitted. Then determines the affected layerable and forwards the event to it. */ -void QCustomPlot::wheelEvent(QWheelEvent *event) +void QCustomPlot::wheelEvent( QWheelEvent* event ) { - emit mouseWheel(event); + emit mouseWheel( event ); // forward event to layerable under cursor: - QList candidates = layerableListAt(event->pos(), false); - for (int i=0; i candidates = layerableListAt( event->pos(), false ); + for( int i = 0; i < candidates.size(); ++i ) { - event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidates.at(i)->wheelEvent(event); - if (event->isAccepted()) + event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list + candidates.at( i )->wheelEvent( event ); + if( event->isAccepted() ) break; } - event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. + event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event. } /*! \internal @@ -14989,17 +15110,17 @@ void QCustomPlot::wheelEvent(QWheelEvent *event) \ref setBackground(const QBrush &brush)), this is up to the respective functions calling this method. */ -void QCustomPlot::draw(QCPPainter *painter) +void QCustomPlot::draw( QCPPainter* painter ) { updateLayout(); - + // draw viewport background pixmap: - drawBackground(painter); + drawBackground( painter ); // draw all layered objects (grid, axes, plottables, items, legend,...): - foreach (QCPLayer *layer, mLayers) - layer->draw(painter); - + foreach( QCPLayer* layer, mLayers ) + layer->draw( painter ); + /* Debug code to draw all layout element rects foreach (QCPLayoutElement* el, findChildren()) { @@ -15023,9 +15144,9 @@ void QCustomPlot::draw(QCPPainter *painter) void QCustomPlot::updateLayout() { // run through layout phases: - mPlotLayout->update(QCPLayoutElement::upPreparation); - mPlotLayout->update(QCPLayoutElement::upMargins); - mPlotLayout->update(QCPLayoutElement::upLayout); + mPlotLayout->update( QCPLayoutElement::upPreparation ); + mPlotLayout->update( QCPLayoutElement::upMargins ); + mPlotLayout->update( QCPLayoutElement::upLayout ); } /*! \internal @@ -15045,24 +15166,25 @@ void QCustomPlot::updateLayout() \see setBackground, setBackgroundScaled, setBackgroundScaledMode */ -void QCustomPlot::drawBackground(QCPPainter *painter) +void QCustomPlot::drawBackground( QCPPainter* painter ) { // Note: background color is handled in individual replot/save functions // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) + if( !mBackgroundPixmap.isNull() ) { - if (mBackgroundScaled) + if( mBackgroundScaled ) { // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mViewport.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mViewport.topLeft(), mScaledBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height()) & mScaledBackgroundPixmap.rect()); - } else + QSize scaledSize( mBackgroundPixmap.size() ); + scaledSize.scale( mViewport.size(), mBackgroundScaledMode ); + if( mScaledBackgroundPixmap.size() != scaledSize ) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled( mViewport.size(), mBackgroundScaledMode, Qt::SmoothTransformation ); + painter->drawPixmap( mViewport.topLeft(), mScaledBackgroundPixmap, QRect( 0, 0, mViewport.width(), mViewport.height() ) & mScaledBackgroundPixmap.rect() ); + } + else { - painter->drawPixmap(mViewport.topLeft(), mBackgroundPixmap, QRect(0, 0, mViewport.width(), mViewport.height())); + painter->drawPixmap( mViewport.topLeft(), mBackgroundPixmap, QRect( 0, 0, mViewport.width(), mViewport.height() ) ); } } } @@ -15089,38 +15211,39 @@ void QCustomPlot::drawBackground(QCPPainter *painter) void QCustomPlot::setupPaintBuffers() { int bufferIndex = 0; - if (mPaintBuffers.isEmpty()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - - for (int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex) + if( mPaintBuffers.isEmpty() ) + mPaintBuffers.append( QSharedPointer( createPaintBuffer() ) ); + + for( int layerIndex = 0; layerIndex < mLayers.size(); ++layerIndex ) { - QCPLayer *layer = mLayers.at(layerIndex); - if (layer->mode() == QCPLayer::lmLogical) + QCPLayer* layer = mLayers.at( layerIndex ); + if( layer->mode() == QCPLayer::lmLogical ) { - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - } else if (layer->mode() == QCPLayer::lmBuffered) + layer->mPaintBuffer = mPaintBuffers.at( bufferIndex ).toWeakRef(); + } + else if( layer->mode() == QCPLayer::lmBuffered ) { ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); - layer->mPaintBuffer = mPaintBuffers.at(bufferIndex).toWeakRef(); - if (layerIndex < mLayers.size()-1 && mLayers.at(layerIndex+1)->mode() == QCPLayer::lmLogical) // not last layer, and next one is logical, so prepare another buffer for next layerables + if( bufferIndex >= mPaintBuffers.size() ) + mPaintBuffers.append( QSharedPointer( createPaintBuffer() ) ); + layer->mPaintBuffer = mPaintBuffers.at( bufferIndex ).toWeakRef(); + if( layerIndex < mLayers.size() - 1 && mLayers.at( layerIndex + 1 )->mode() == QCPLayer::lmLogical ) // not last layer, and next one is logical, so prepare another buffer for next layerables { ++bufferIndex; - if (bufferIndex >= mPaintBuffers.size()) - mPaintBuffers.append(QSharedPointer(createPaintBuffer())); + if( bufferIndex >= mPaintBuffers.size() ) + mPaintBuffers.append( QSharedPointer( createPaintBuffer() ) ); } } } // remove unneeded buffers: - while (mPaintBuffers.size()-1 > bufferIndex) + while( mPaintBuffers.size() - 1 > bufferIndex ) mPaintBuffers.removeLast(); // resize buffers to viewport size and clear contents: - for (int i=0; isetSize(viewport().size()); // won't do anything if already correct size - mPaintBuffers.at(i)->clear(Qt::transparent); - mPaintBuffers.at(i)->setInvalidated(); + mPaintBuffers.at( i )->setSize( viewport().size() ); // won't do anything if already correct size + mPaintBuffers.at( i )->clear( Qt::transparent ); + mPaintBuffers.at( i )->setInvalidated(); } } @@ -15132,20 +15255,21 @@ void QCustomPlot::setupPaintBuffers() backends (subclasses of \ref QCPAbstractPaintBuffer) are created, initialized with the proper size and device pixel ratio, and returned. */ -QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() +QCPAbstractPaintBuffer* QCustomPlot::createPaintBuffer() { - if (mOpenGl) + if( mOpenGl ) { -#if defined(QCP_OPENGL_FBO) - return new QCPPaintBufferGlFbo(viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice); -#elif defined(QCP_OPENGL_PBUFFER) - return new QCPPaintBufferGlPbuffer(viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples); +#if defined( QCP_OPENGL_FBO ) + return new QCPPaintBufferGlFbo( viewport().size(), mBufferDevicePixelRatio, mGlContext, mGlPaintDevice ); +#elif defined( QCP_OPENGL_PBUFFER ) + return new QCPPaintBufferGlPbuffer( viewport().size(), mBufferDevicePixelRatio, mOpenGlMultisamples ); #else qDebug() << Q_FUNC_INFO << "OpenGL enabled even though no support for it compiled in, this shouldn't have happened. Falling back to pixmap paint buffer."; - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); + return new QCPPaintBufferPixmap( viewport().size(), mBufferDevicePixelRatio ); #endif - } else - return new QCPPaintBufferPixmap(viewport().size(), mBufferDevicePixelRatio); + } + else + return new QCPPaintBufferPixmap( viewport().size(), mBufferDevicePixelRatio ); } /*! @@ -15161,9 +15285,9 @@ QCPAbstractPaintBuffer *QCustomPlot::createPaintBuffer() */ bool QCustomPlot::hasInvalidatedPaintBuffers() { - for (int i=0; iinvalidated()) + if( mPaintBuffers.at( i )->invalidated() ) return true; } return false; @@ -15187,42 +15311,42 @@ bool QCustomPlot::setupOpenGl() #ifdef QCP_OPENGL_FBO freeOpenGl(); QSurfaceFormat proposedSurfaceFormat; - proposedSurfaceFormat.setSamples(mOpenGlMultisamples); + proposedSurfaceFormat.setSamples( mOpenGlMultisamples ); #ifdef QCP_OPENGL_OFFSCREENSURFACE - QOffscreenSurface *surface = new QOffscreenSurface; + QOffscreenSurface* surface = new QOffscreenSurface; #else - QWindow *surface = new QWindow; - surface->setSurfaceType(QSurface::OpenGLSurface); + QWindow* surface = new QWindow; + surface->setSurfaceType( QSurface::OpenGLSurface ); #endif - surface->setFormat(proposedSurfaceFormat); + surface->setFormat( proposedSurfaceFormat ); surface->create(); - mGlSurface = QSharedPointer(surface); - mGlContext = QSharedPointer(new QOpenGLContext); - mGlContext->setFormat(mGlSurface->format()); - if (!mGlContext->create()) + mGlSurface = QSharedPointer( surface ); + mGlContext = QSharedPointer( new QOpenGLContext ); + mGlContext->setFormat( mGlSurface->format() ); + if( !mGlContext->create() ) { qDebug() << Q_FUNC_INFO << "Failed to create OpenGL context"; mGlContext.clear(); mGlSurface.clear(); return false; } - if (!mGlContext->makeCurrent(mGlSurface.data())) // context needs to be current to create paint device + if( !mGlContext->makeCurrent( mGlSurface.data() ) ) // context needs to be current to create paint device { qDebug() << Q_FUNC_INFO << "Failed to make opengl context current"; mGlContext.clear(); mGlSurface.clear(); return false; } - if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + if( !QOpenGLFramebufferObject::hasOpenGLFramebufferObjects() ) { qDebug() << Q_FUNC_INFO << "OpenGL of this system doesn't support frame buffer objects"; mGlContext.clear(); mGlSurface.clear(); return false; } - mGlPaintDevice = QSharedPointer(new QOpenGLPaintDevice); + mGlPaintDevice = QSharedPointer( new QOpenGLPaintDevice ); return true; -#elif defined(QCP_OPENGL_PBUFFER) +#elif defined( QCP_OPENGL_PBUFFER ) return QGLFormat::hasOpenGL(); #else return false; @@ -15254,17 +15378,17 @@ void QCustomPlot::freeOpenGl() This method is used by \ref QCPAxisRect::removeAxis to report removed axes to the QCustomPlot so it may clear its QCustomPlot::xAxis, yAxis, xAxis2 and yAxis2 members accordingly. */ -void QCustomPlot::axisRemoved(QCPAxis *axis) +void QCustomPlot::axisRemoved( QCPAxis* axis ) { - if (xAxis == axis) + if( xAxis == axis ) xAxis = 0; - if (xAxis2 == axis) + if( xAxis2 == axis ) xAxis2 = 0; - if (yAxis == axis) + if( yAxis == axis ) yAxis = 0; - if (yAxis2 == axis) + if( yAxis2 == axis ) yAxis2 = 0; - + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers } @@ -15273,9 +15397,9 @@ void QCustomPlot::axisRemoved(QCPAxis *axis) This method is used by the QCPLegend destructor to report legend removal to the QCustomPlot so it may clear its QCustomPlot::legend member accordingly. */ -void QCustomPlot::legendRemoved(QCPLegend *legend) +void QCustomPlot::legendRemoved( QCPLegend* legend ) { - if (this->legend == legend) + if( this->legend == legend ) this->legend = 0; } @@ -15296,77 +15420,78 @@ void QCustomPlot::legendRemoved(QCPLegend *legend) \see processRectZoom */ -void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) +void QCustomPlot::processRectSelection( QRect rect, QMouseEvent* event ) { bool selectionStateChanged = false; - - if (mInteractions.testFlag(QCP::iSelectPlottables)) + + if( mInteractions.testFlag( QCP::iSelectPlottables ) ) { - QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size - QRectF rectF(rect.normalized()); - if (QCPAxisRect *affectedAxisRect = axisRectAt(rectF.topLeft())) + QMap > potentialSelections; // map key is number of selected data points, so we have selections sorted by size + QRectF rectF( rect.normalized() ); + if( QCPAxisRect* affectedAxisRect = axisRectAt( rectF.topLeft() ) ) { // determine plottables that were hit by the rect and thus are candidates for selection: - foreach (QCPAbstractPlottable *plottable, affectedAxisRect->plottables()) + foreach( QCPAbstractPlottable* plottable, affectedAxisRect->plottables() ) { - if (QCPPlottableInterface1D *plottableInterface = plottable->interface1D()) + if( QCPPlottableInterface1D* plottableInterface = plottable->interface1D() ) { - QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); - if (!dataSel.isEmpty()) - potentialSelections.insertMulti(dataSel.dataPointCount(), QPair(plottable, dataSel)); + QCPDataSelection dataSel = plottableInterface->selectTestRect( rectF, true ); + if( !dataSel.isEmpty() ) + potentialSelections.insertMulti( dataSel.dataPointCount(), QPair( plottable, dataSel ) ); } } - - if (!mInteractions.testFlag(QCP::iMultiSelect)) + + if( !mInteractions.testFlag( QCP::iMultiSelect ) ) { // only leave plottable with most selected points in map, since we will only select a single plottable: - if (!potentialSelections.isEmpty()) + if( !potentialSelections.isEmpty() ) { QMap >::iterator it = potentialSelections.begin(); - while (it != potentialSelections.end()-1) // erase all except last element - it = potentialSelections.erase(it); + while( it != potentialSelections.end() - 1 ) // erase all except last element + it = potentialSelections.erase( it ); } } - - bool additive = event->modifiers().testFlag(mMultiSelectModifier); + + bool additive = event->modifiers().testFlag( mMultiSelectModifier ); // deselect all other layerables if not additive selection: - if (!additive) + if( !additive ) { // emit deselection except to those plottables who will be selected afterwards: - foreach (QCPLayer *layer, mLayers) + foreach( QCPLayer* layer, mLayers ) { - foreach (QCPLayerable *layerable, layer->children()) + foreach( QCPLayerable* layerable, layer->children() ) { - if ((potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable) && mInteractions.testFlag(layerable->selectionCategory())) + if( ( potentialSelections.isEmpty() || potentialSelections.constBegin()->first != layerable ) && mInteractions.testFlag( layerable->selectionCategory() ) ) { bool selChanged = false; - layerable->deselectEvent(&selChanged); + layerable->deselectEvent( &selChanged ); selectionStateChanged |= selChanged; } } } } - + // go through selections in reverse (largest selection first) and emit select events: QMap >::const_iterator it = potentialSelections.constEnd(); - while (it != potentialSelections.constBegin()) + while( it != potentialSelections.constBegin() ) { --it; - if (mInteractions.testFlag(it.value().first->selectionCategory())) + if( mInteractions.testFlag( it.value().first->selectionCategory() ) ) { bool selChanged = false; - it.value().first->selectEvent(event, additive, QVariant::fromValue(it.value().second), &selChanged); + it.value().first->selectEvent( event, additive, QVariant::fromValue( it.value().second ), &selChanged ); selectionStateChanged |= selChanged; } } } } - - if (selectionStateChanged) + + if( selectionStateChanged ) { emit selectionChangedByUser(); - replot(rpQueuedReplot); - } else if (mSelectionRect) + replot( rpQueuedReplot ); + } + else if( mSelectionRect ) mSelectionRect->layer()->replot(); } @@ -15381,16 +15506,16 @@ void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) \see processRectSelection */ -void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) +void QCustomPlot::processRectZoom( QRect rect, QMouseEvent* event ) { - Q_UNUSED(event) - if (QCPAxisRect *axisRect = axisRectAt(rect.topLeft())) + Q_UNUSED( event ) + if( QCPAxisRect* axisRect = axisRectAt( rect.topLeft() ) ) { - QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); - affectedAxes.removeAll(static_cast(0)); - axisRect->zoom(QRectF(rect), affectedAxes); + QList affectedAxes = QList() << axisRect->rangeZoomAxes( Qt::Horizontal ) << axisRect->rangeZoomAxes( Qt::Vertical ); + affectedAxes.removeAll( static_cast( 0 ) ); + axisRect->zoom( QRectF( rect ), affectedAxes ); } - replot(rpQueuedReplot); // always replot to make selection rect disappear + replot( rpQueuedReplot ); // always replot to make selection rect disappear } /*! \internal @@ -15410,39 +15535,39 @@ void QCustomPlot::processRectZoom(QRect rect, QMouseEvent *event) \see processRectSelection, QCPLayerable::selectTest */ -void QCustomPlot::processPointSelection(QMouseEvent *event) +void QCustomPlot::processPointSelection( QMouseEvent* event ) { QVariant details; - QCPLayerable *clickedLayerable = layerableAt(event->pos(), true, &details); + QCPLayerable* clickedLayerable = layerableAt( event->pos(), true, &details ); bool selectionStateChanged = false; - bool additive = mInteractions.testFlag(QCP::iMultiSelect) && event->modifiers().testFlag(mMultiSelectModifier); + bool additive = mInteractions.testFlag( QCP::iMultiSelect ) && event->modifiers().testFlag( mMultiSelectModifier ); // deselect all other layerables if not additive selection: - if (!additive) + if( !additive ) { - foreach (QCPLayer *layer, mLayers) + foreach( QCPLayer* layer, mLayers ) { - foreach (QCPLayerable *layerable, layer->children()) + foreach( QCPLayerable* layerable, layer->children() ) { - if (layerable != clickedLayerable && mInteractions.testFlag(layerable->selectionCategory())) + if( layerable != clickedLayerable && mInteractions.testFlag( layerable->selectionCategory() ) ) { bool selChanged = false; - layerable->deselectEvent(&selChanged); + layerable->deselectEvent( &selChanged ); selectionStateChanged |= selChanged; } } } } - if (clickedLayerable && mInteractions.testFlag(clickedLayerable->selectionCategory())) + if( clickedLayerable && mInteractions.testFlag( clickedLayerable->selectionCategory() ) ) { // a layerable was actually clicked, call its selectEvent: bool selChanged = false; - clickedLayerable->selectEvent(event, additive, details, &selChanged); + clickedLayerable->selectEvent( event, additive, details, &selChanged ); selectionStateChanged |= selChanged; } - if (selectionStateChanged) + if( selectionStateChanged ) { emit selectionChangedByUser(); - replot(rpQueuedReplot); + replot( rpQueuedReplot ); } } @@ -15457,25 +15582,25 @@ void QCustomPlot::processPointSelection(QMouseEvent *event) This method is called automatically in the QCPAbstractPlottable base class constructor. */ -bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) +bool QCustomPlot::registerPlottable( QCPAbstractPlottable* plottable ) { - if (mPlottables.contains(plottable)) + if( mPlottables.contains( plottable ) ) { - qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast(plottable); + qDebug() << Q_FUNC_INFO << "plottable already added to this QCustomPlot:" << reinterpret_cast( plottable ); return false; } - if (plottable->parentPlot() != this) + if( plottable->parentPlot() != this ) { - qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast(plottable); + qDebug() << Q_FUNC_INFO << "plottable not created with this QCustomPlot as parent:" << reinterpret_cast( plottable ); return false; } - - mPlottables.append(plottable); + + mPlottables.append( plottable ); // possibly add plottable to legend: - if (mAutoAddPlottableToLegend) + if( mAutoAddPlottableToLegend ) plottable->addToLegend(); - if (!plottable->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - plottable->setLayer(currentLayer()); + if( !plottable->layer() ) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + plottable->setLayer( currentLayer() ); return true; } @@ -15488,24 +15613,23 @@ bool QCustomPlot::registerPlottable(QCPAbstractPlottable *plottable) This graph specific registration happens in addition to the call to \ref registerPlottable by the QCPAbstractPlottable base class. */ -bool QCustomPlot::registerGraph(QCPGraph *graph) +bool QCustomPlot::registerGraph( QCPGraph* graph ) { - if (!graph) + if( !graph ) { qDebug() << Q_FUNC_INFO << "passed graph is zero"; return false; } - if (mGraphs.contains(graph)) + if( mGraphs.contains( graph ) ) { qDebug() << Q_FUNC_INFO << "graph already registered with this QCustomPlot"; return false; } - - mGraphs.append(graph); + + mGraphs.append( graph ); return true; } - /*! \internal Registers the specified item with this QCustomPlot. QCustomPlot takes ownership of the item. @@ -15515,22 +15639,22 @@ bool QCustomPlot::registerGraph(QCPGraph *graph) This method is called automatically in the QCPAbstractItem base class constructor. */ -bool QCustomPlot::registerItem(QCPAbstractItem *item) +bool QCustomPlot::registerItem( QCPAbstractItem* item ) { - if (mItems.contains(item)) + if( mItems.contains( item ) ) { - qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast(item); + qDebug() << Q_FUNC_INFO << "item already added to this QCustomPlot:" << reinterpret_cast( item ); return false; } - if (item->parentPlot() != this) + if( item->parentPlot() != this ) { - qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast(item); + qDebug() << Q_FUNC_INFO << "item not created with this QCustomPlot as parent:" << reinterpret_cast( item ); return false; } - - mItems.append(item); - if (!item->layer()) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) - item->setLayer(currentLayer()); + + mItems.append( item ); + if( !item->layer() ) // usually the layer is already set in the constructor of the item (via QCPLayerable constructor) + item->setLayer( currentLayer() ); return true; } @@ -15542,8 +15666,8 @@ bool QCustomPlot::registerItem(QCPAbstractItem *item) */ void QCustomPlot::updateLayerIndices() const { - for (int i=0; imIndex = i; + for( int i = 0; i < mLayers.size(); ++i ) + mLayers.at( i )->mIndex = i; } /*! \internal @@ -15561,13 +15685,13 @@ void QCustomPlot::updateLayerIndices() const \see layerableListAt, layoutElementAt, axisRectAt */ -QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails) const +QCPLayerable* QCustomPlot::layerableAt( const QPointF& pos, bool onlySelectable, QVariant* selectionDetails ) const { QList details; - QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : 0); - if (selectionDetails && !details.isEmpty()) + QList candidates = layerableListAt( pos, onlySelectable, selectionDetails ? &details : 0 ); + if( selectionDetails && !details.isEmpty() ) *selectionDetails = details.first(); - if (!candidates.isEmpty()) + if( !candidates.isEmpty() ) return candidates.first(); else return 0; @@ -15591,23 +15715,23 @@ QCPLayerable *QCustomPlot::layerableAt(const QPointF &pos, bool onlySelectable, \see layerableAt, layoutElementAt, axisRectAt */ -QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails) const +QList QCustomPlot::layerableListAt( const QPointF& pos, bool onlySelectable, QList* selectionDetails ) const { QList result; - for (int layerIndex=mLayers.size()-1; layerIndex>=0; --layerIndex) + for( int layerIndex = mLayers.size() - 1; layerIndex >= 0; --layerIndex ) { - const QList layerables = mLayers.at(layerIndex)->children(); - for (int i=layerables.size()-1; i>=0; --i) + const QList layerables = mLayers.at( layerIndex )->children(); + for( int i = layerables.size() - 1; i >= 0; --i ) { - if (!layerables.at(i)->realVisibility()) + if( !layerables.at( i )->realVisibility() ) continue; QVariant details; - double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : 0); - if (dist >= 0 && dist < selectionTolerance()) + double dist = layerables.at( i )->selectTest( pos, onlySelectable, selectionDetails ? &details : 0 ); + if( dist >= 0 && dist < selectionTolerance() ) { - result.append(layerables.at(i)); - if (selectionDetails) - selectionDetails->append(details); + result.append( layerables.at( i ) ); + if( selectionDetails ) + selectionDetails->append( details ); } } } @@ -15632,21 +15756,27 @@ QList QCustomPlot::layerableListAt(const QPointF &pos, bool onlyS \see saveBmp, saveJpg, savePng, savePdf */ -bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit) +bool QCustomPlot::saveRastered( const QString& fileName, int width, int height, double scale, const char* format, int quality, int resolution, QCP::ResolutionUnit resolutionUnit ) { - QImage buffer = toPixmap(width, height, scale).toImage(); - + QImage buffer = toPixmap( width, height, scale ).toImage(); + int dotsPerMeter = 0; - switch (resolutionUnit) + switch( resolutionUnit ) { - case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; - case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; - case QCP::ruDotsPerInch: dotsPerMeter = resolution/0.0254; break; + case QCP::ruDotsPerMeter: + dotsPerMeter = resolution; + break; + case QCP::ruDotsPerCentimeter: + dotsPerMeter = resolution * 100; + break; + case QCP::ruDotsPerInch: + dotsPerMeter = resolution / 0.0254; + break; } - buffer.setDotsPerMeterX(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - buffer.setDotsPerMeterY(dotsPerMeter); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools - if (!buffer.isNull()) - return buffer.save(fileName, format, quality); + buffer.setDotsPerMeterX( dotsPerMeter ); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + buffer.setDotsPerMeterY( dotsPerMeter ); // this is saved together with some image formats, e.g. PNG, and is relevant when opening image in other tools + if( !buffer.isNull() ) + return buffer.save( fileName, format, quality ); else return false; } @@ -15659,43 +15789,45 @@ bool QCustomPlot::saveRastered(const QString &fileName, int width, int height, d \see toPainter, saveRastered, saveBmp, savePng, saveJpg, savePdf */ -QPixmap QCustomPlot::toPixmap(int width, int height, double scale) +QPixmap QCustomPlot::toPixmap( int width, int height, double scale ) { // this method is somewhat similar to toPainter. Change something here, and a change in toPainter might be necessary, too. int newWidth, newHeight; - if (width == 0 || height == 0) + if( width == 0 || height == 0 ) { newWidth = this->width(); newHeight = this->height(); - } else + } + else { newWidth = width; newHeight = height; } - int scaledWidth = qRound(scale*newWidth); - int scaledHeight = qRound(scale*newHeight); + int scaledWidth = qRound( scale * newWidth ); + int scaledHeight = qRound( scale * newHeight ); - QPixmap result(scaledWidth, scaledHeight); - result.fill(mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent); // if using non-solid pattern, make transparent now and draw brush pattern later + QPixmap result( scaledWidth, scaledHeight ); + result.fill( mBackgroundBrush.style() == Qt::SolidPattern ? mBackgroundBrush.color() : Qt::transparent ); // if using non-solid pattern, make transparent now and draw brush pattern later QCPPainter painter; - painter.begin(&result); - if (painter.isActive()) + painter.begin( &result ); + if( painter.isActive() ) { QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter.setMode(QCPPainter::pmNoCaching); - if (!qFuzzyCompare(scale, 1.0)) + setViewport( QRect( 0, 0, newWidth, newHeight ) ); + painter.setMode( QCPPainter::pmNoCaching ); + if( !qFuzzyCompare( scale, 1.0 ) ) { - if (scale > 1.0) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales - painter.setMode(QCPPainter::pmNonCosmetic); - painter.scale(scale, scale); + if( scale > 1.0 ) // for scale < 1 we always want cosmetic pens where possible, because else lines might disappear for very small scales + painter.setMode( QCPPainter::pmNonCosmetic ); + painter.scale( scale, scale ); } - if (mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush) // solid fills were done a few lines above with QPixmap::fill - painter.fillRect(mViewport, mBackgroundBrush); - draw(&painter); - setViewport(oldViewport); + if( mBackgroundBrush.style() != Qt::SolidPattern && mBackgroundBrush.style() != Qt::NoBrush ) // solid fills were done a few lines above with QPixmap::fill + painter.fillRect( mViewport, mBackgroundBrush ); + draw( &painter ); + setViewport( oldViewport ); painter.end(); - } else // might happen if pixmap has width or height zero + } + else // might happen if pixmap has width or height zero { qDebug() << Q_FUNC_INFO << "Couldn't activate painter on pixmap"; return QPixmap(); @@ -15715,30 +15847,32 @@ QPixmap QCustomPlot::toPixmap(int width, int height, double scale) \see toPixmap */ -void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) +void QCustomPlot::toPainter( QCPPainter* painter, int width, int height ) { // this method is somewhat similar to toPixmap. Change something here, and a change in toPixmap might be necessary, too. int newWidth, newHeight; - if (width == 0 || height == 0) + if( width == 0 || height == 0 ) { newWidth = this->width(); newHeight = this->height(); - } else + } + else { newWidth = width; newHeight = height; } - if (painter->isActive()) + if( painter->isActive() ) { QRect oldViewport = viewport(); - setViewport(QRect(0, 0, newWidth, newHeight)); - painter->setMode(QCPPainter::pmNoCaching); - if (mBackgroundBrush.style() != Qt::NoBrush) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here - painter->fillRect(mViewport, mBackgroundBrush); - draw(painter); - setViewport(oldViewport); - } else + setViewport( QRect( 0, 0, newWidth, newHeight ) ); + painter->setMode( QCPPainter::pmNoCaching ); + if( mBackgroundBrush.style() != Qt::NoBrush ) // unlike in toPixmap, we can't do QPixmap::fill for Qt::SolidPattern brush style, so we also draw solid fills with fillRect here + painter->fillRect( mViewport, mBackgroundBrush ); + draw( painter ); + setViewport( oldViewport ); + } + else qDebug() << Q_FUNC_INFO << "Passed painter is not active"; } /* end of 'src/core.cpp' */ @@ -15748,7 +15882,6 @@ void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) /* including file 'src/colorgradient.cpp', size 25342 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorGradient //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -15787,13 +15920,10 @@ void QCustomPlot::toPainter(QCPPainter *painter, int width, int height) The color level count is initialized to 350. */ -QCPColorGradient::QCPColorGradient() : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) +QCPColorGradient::QCPColorGradient() + : mLevelCount( 350 ), mColorInterpolation( ciRGB ), mPeriodic( false ), mColorBufferInvalidated( true ) { - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); + mColorBuffer.fill( qRgb( 0, 0, 0 ), mLevelCount ); } /*! @@ -15802,23 +15932,20 @@ QCPColorGradient::QCPColorGradient() : The color level count is initialized to 350. */ -QCPColorGradient::QCPColorGradient(GradientPreset preset) : - mLevelCount(350), - mColorInterpolation(ciRGB), - mPeriodic(false), - mColorBufferInvalidated(true) +QCPColorGradient::QCPColorGradient( GradientPreset preset ) + : mLevelCount( 350 ), mColorInterpolation( ciRGB ), mPeriodic( false ), mColorBufferInvalidated( true ) { - mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); - loadPreset(preset); + mColorBuffer.fill( qRgb( 0, 0, 0 ), mLevelCount ); + loadPreset( preset ); } /* undocumented operator */ -bool QCPColorGradient::operator==(const QCPColorGradient &other) const +bool QCPColorGradient::operator==( const QCPColorGradient& other ) const { - return ((other.mLevelCount == this->mLevelCount) && - (other.mColorInterpolation == this->mColorInterpolation) && - (other.mPeriodic == this->mPeriodic) && - (other.mColorStops == this->mColorStops)); + return ( ( other.mLevelCount == this->mLevelCount ) && + ( other.mColorInterpolation == this->mColorInterpolation ) && + ( other.mPeriodic == this->mPeriodic ) && + ( other.mColorStops == this->mColorStops ) ); } /*! @@ -15827,14 +15954,14 @@ bool QCPColorGradient::operator==(const QCPColorGradient &other) const \image html QCPColorGradient-levelcount.png */ -void QCPColorGradient::setLevelCount(int n) +void QCPColorGradient::setLevelCount( int n ) { - if (n < 2) + if( n < 2 ) { qDebug() << Q_FUNC_INFO << "n must be greater or equal 2 but was" << n; n = 2; } - if (n != mLevelCount) + if( n != mLevelCount ) { mLevelCount = n; mColorBufferInvalidated = true; @@ -15852,7 +15979,7 @@ void QCPColorGradient::setLevelCount(int n) \see clearColorStops */ -void QCPColorGradient::setColorStops(const QMap &colorStops) +void QCPColorGradient::setColorStops( const QMap& colorStops ) { mColorStops = colorStops; mColorBufferInvalidated = true; @@ -15864,9 +15991,9 @@ void QCPColorGradient::setColorStops(const QMap &colorStops) \see setColorStops, clearColorStops */ -void QCPColorGradient::setColorStopAt(double position, const QColor &color) +void QCPColorGradient::setColorStopAt( double position, const QColor& color ) { - mColorStops.insert(position, color); + mColorStops.insert( position, color ); mColorBufferInvalidated = true; } @@ -15877,9 +16004,9 @@ void QCPColorGradient::setColorStopAt(double position, const QColor &color) For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, whereas in HSV space the intermediate color is yellow. */ -void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolation interpolation) +void QCPColorGradient::setColorInterpolation( QCPColorGradient::ColorInterpolation interpolation ) { - if (interpolation != mColorInterpolation) + if( interpolation != mColorInterpolation ) { mColorInterpolation = interpolation; mColorBufferInvalidated = true; @@ -15901,7 +16028,7 @@ void QCPColorGradient::setColorInterpolation(QCPColorGradient::ColorInterpolatio dimension, such as an angle or a phase. If this is not the case, the color encoding might become ambiguous, because multiple different data values are shown as the same color. */ -void QCPColorGradient::setPeriodic(bool enabled) +void QCPColorGradient::setPeriodic( bool enabled ) { mPeriodic = enabled; } @@ -15924,67 +16051,70 @@ void QCPColorGradient::setPeriodic(bool enabled) The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied with alpha (see QImage::Format_ARGB32_Premultiplied). */ -void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +void QCPColorGradient::colorize( const double* data, const QCPRange& range, QRgb* scanLine, int n, int dataIndexFactor, bool logarithmic ) { // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) + if( !data ) { qDebug() << Q_FUNC_INFO << "null pointer given as data"; return; } - if (!scanLine) + if( !scanLine ) { qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; return; } - if (mColorBufferInvalidated) + if( mColorBufferInvalidated ) updateColorBuffer(); - - if (!logarithmic) + + if( !logarithmic ) { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) + const double posToIndexFactor = ( mLevelCount - 1 ) / range.size(); + if( mPeriodic ) { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); + scanLine[i] = mColorBuffer.at( index ); } } - } else // logarithmic == true - { - if (mPeriodic) + else { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - scanLine[i] = mColorBuffer.at(index); + else if( index >= mLevelCount ) + index = mLevelCount - 1; + scanLine[i] = mColorBuffer.at( index ); + } + } + } + else // logarithmic == true + { + if( mPeriodic ) + { + for( int i = 0; i < n; ++i ) + { + int index = (int)( qLn( data[dataIndexFactor * i] / range.lower ) / qLn( range.upper / range.lower ) * ( mLevelCount - 1 ) ) % mLevelCount; + if( index < 0 ) + index += mLevelCount; + scanLine[i] = mColorBuffer.at( index ); + } + } + else + { + for( int i = 0; i < n; ++i ) + { + int index = qLn( data[dataIndexFactor * i] / range.lower ) / qLn( range.upper / range.lower ) * ( mLevelCount - 1 ); + if( index < 0 ) + index = 0; + else if( index >= mLevelCount ) + index = mLevelCount - 1; + scanLine[i] = mColorBuffer.at( index ); } } } @@ -15998,103 +16128,110 @@ void QCPColorGradient::colorize(const double *data, const QCPRange &range, QRgb The QRgb values that are placed in \a scanLine have their r, g and b components premultiplied with alpha (see QImage::Format_ARGB32_Premultiplied). */ -void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor, bool logarithmic) +void QCPColorGradient::colorize( const double* data, const unsigned char* alpha, const QCPRange& range, QRgb* scanLine, int n, int dataIndexFactor, bool logarithmic ) { // If you change something here, make sure to also adapt color() and the other colorize() overload - if (!data) + if( !data ) { qDebug() << Q_FUNC_INFO << "null pointer given as data"; return; } - if (!alpha) + if( !alpha ) { qDebug() << Q_FUNC_INFO << "null pointer given as alpha"; return; } - if (!scanLine) + if( !scanLine ) { qDebug() << Q_FUNC_INFO << "null pointer given as scanLine"; return; } - if (mColorBufferInvalidated) + if( mColorBufferInvalidated ) updateColorBuffer(); - - if (!logarithmic) + + if( !logarithmic ) { - const double posToIndexFactor = (mLevelCount-1)/range.size(); - if (mPeriodic) + const double posToIndexFactor = ( mLevelCount - 1 ) / range.size(); + if( mPeriodic ) { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) + else { - scanLine[i] = mColorBuffer.at(index); - } else - { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + const QRgb rgb = mColorBuffer.at( index ); + const float alphaF = alpha[dataIndexFactor * i] / 255.0f; + scanLine[i] = qRgba( qRed( rgb ) * alphaF, qGreen( rgb ) * alphaF, qBlue( rgb ) * alphaF, qAlpha( rgb ) * alphaF ); } } } - } else // logarithmic == true - { - if (mPeriodic) + else { - for (int i=0; i= mLevelCount ) + index = mLevelCount - 1; + if( alpha[dataIndexFactor * i] == 255 ) { - scanLine[i] = mColorBuffer.at(index); - } else + scanLine[i] = mColorBuffer.at( index ); + } + else { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + const QRgb rgb = mColorBuffer.at( index ); + const float alphaF = alpha[dataIndexFactor * i] / 255.0f; + scanLine[i] = qRgba( qRed( rgb ) * alphaF, qGreen( rgb ) * alphaF, qBlue( rgb ) * alphaF, qAlpha( rgb ) * alphaF ); } } - } else + } + } + else // logarithmic == true + { + if( mPeriodic ) { - for (int i=0; i= mLevelCount) - index = mLevelCount-1; - if (alpha[dataIndexFactor*i] == 255) + else if( index >= mLevelCount ) + index = mLevelCount - 1; + if( alpha[dataIndexFactor * i] == 255 ) { - scanLine[i] = mColorBuffer.at(index); - } else + scanLine[i] = mColorBuffer.at( index ); + } + else { - const QRgb rgb = mColorBuffer.at(index); - const float alphaF = alpha[dataIndexFactor*i]/255.0f; - scanLine[i] = qRgba(qRed(rgb)*alphaF, qGreen(rgb)*alphaF, qBlue(rgb)*alphaF, qAlpha(rgb)*alphaF); + const QRgb rgb = mColorBuffer.at( index ); + const float alphaF = alpha[dataIndexFactor * i] / 255.0f; + scanLine[i] = qRgba( qRed( rgb ) * alphaF, qGreen( rgb ) * alphaF, qBlue( rgb ) * alphaF, qAlpha( rgb ) * alphaF ); } } } @@ -16113,29 +16250,30 @@ void QCPColorGradient::colorize(const double *data, const unsigned char *alpha, The returned QRgb has its r, g and b components premultiplied with alpha (see QImage::Format_ARGB32_Premultiplied). */ -QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) +QRgb QCPColorGradient::color( double position, const QCPRange& range, bool logarithmic ) { // If you change something here, make sure to also adapt ::colorize() - if (mColorBufferInvalidated) + if( mColorBufferInvalidated ) updateColorBuffer(); int index = 0; - if (!logarithmic) - index = (position-range.lower)*(mLevelCount-1)/range.size(); + if( !logarithmic ) + index = ( position - range.lower ) * ( mLevelCount - 1 ) / range.size(); else - index = qLn(position/range.lower)/qLn(range.upper/range.lower)*(mLevelCount-1); - if (mPeriodic) + index = qLn( position / range.lower ) / qLn( range.upper / range.lower ) * ( mLevelCount - 1 ); + if( mPeriodic ) { index = index % mLevelCount; - if (index < 0) + if( index < 0 ) index += mLevelCount; - } else - { - if (index < 0) - index = 0; - else if (index >= mLevelCount) - index = mLevelCount-1; } - return mColorBuffer.at(index); + else + { + if( index < 0 ) + index = 0; + else if( index >= mLevelCount ) + index = mLevelCount - 1; + } + return mColorBuffer.at( index ); } /*! @@ -16145,107 +16283,107 @@ QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logari The available presets are: \image html QCPColorGradient.png */ -void QCPColorGradient::loadPreset(GradientPreset preset) +void QCPColorGradient::loadPreset( GradientPreset preset ) { clearColorStops(); - switch (preset) + switch( preset ) { - case gpGrayscale: - setColorInterpolation(ciRGB); - setColorStopAt(0, Qt::black); - setColorStopAt(1, Qt::white); - break; - case gpHot: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 0, 0)); - setColorStopAt(0.2, QColor(180, 10, 0)); - setColorStopAt(0.4, QColor(245, 50, 0)); - setColorStopAt(0.6, QColor(255, 150, 10)); - setColorStopAt(0.8, QColor(255, 255, 50)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpCold: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.2, QColor(0, 10, 180)); - setColorStopAt(0.4, QColor(0, 50, 245)); - setColorStopAt(0.6, QColor(10, 150, 255)); - setColorStopAt(0.8, QColor(50, 255, 255)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpNight: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(10, 20, 30)); - setColorStopAt(1, QColor(250, 255, 250)); - break; - case gpCandy: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(0, 0, 255)); - setColorStopAt(1, QColor(255, 250, 250)); - break; - case gpGeography: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(70, 170, 210)); - setColorStopAt(0.20, QColor(90, 160, 180)); - setColorStopAt(0.25, QColor(45, 130, 175)); - setColorStopAt(0.30, QColor(100, 140, 125)); - setColorStopAt(0.5, QColor(100, 140, 100)); - setColorStopAt(0.6, QColor(130, 145, 120)); - setColorStopAt(0.7, QColor(140, 130, 120)); - setColorStopAt(0.9, QColor(180, 190, 190)); - setColorStopAt(1, QColor(210, 210, 230)); - break; - case gpIon: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 10, 10)); - setColorStopAt(0.45, QColor(0, 0, 255)); - setColorStopAt(0.8, QColor(0, 255, 255)); - setColorStopAt(1, QColor(0, 255, 0)); - break; - case gpThermal: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 50)); - setColorStopAt(0.15, QColor(20, 0, 120)); - setColorStopAt(0.33, QColor(200, 30, 140)); - setColorStopAt(0.6, QColor(255, 100, 0)); - setColorStopAt(0.85, QColor(255, 255, 40)); - setColorStopAt(1, QColor(255, 255, 255)); - break; - case gpPolar: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(50, 255, 255)); - setColorStopAt(0.18, QColor(10, 70, 255)); - setColorStopAt(0.28, QColor(10, 10, 190)); - setColorStopAt(0.5, QColor(0, 0, 0)); - setColorStopAt(0.72, QColor(190, 10, 10)); - setColorStopAt(0.82, QColor(255, 70, 10)); - setColorStopAt(1, QColor(255, 255, 50)); - break; - case gpSpectrum: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(50, 0, 50)); - setColorStopAt(0.15, QColor(0, 0, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.6, QColor(255, 255, 0)); - setColorStopAt(0.75, QColor(255, 30, 0)); - setColorStopAt(1, QColor(50, 0, 0)); - break; - case gpJet: - setColorInterpolation(ciRGB); - setColorStopAt(0, QColor(0, 0, 100)); - setColorStopAt(0.15, QColor(0, 50, 255)); - setColorStopAt(0.35, QColor(0, 255, 255)); - setColorStopAt(0.65, QColor(255, 255, 0)); - setColorStopAt(0.85, QColor(255, 30, 0)); - setColorStopAt(1, QColor(100, 0, 0)); - break; - case gpHues: - setColorInterpolation(ciHSV); - setColorStopAt(0, QColor(255, 0, 0)); - setColorStopAt(1.0/3.0, QColor(0, 0, 255)); - setColorStopAt(2.0/3.0, QColor(0, 255, 0)); - setColorStopAt(1, QColor(255, 0, 0)); - break; + case gpGrayscale: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, Qt::black ); + setColorStopAt( 1, Qt::white ); + break; + case gpHot: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 50, 0, 0 ) ); + setColorStopAt( 0.2, QColor( 180, 10, 0 ) ); + setColorStopAt( 0.4, QColor( 245, 50, 0 ) ); + setColorStopAt( 0.6, QColor( 255, 150, 10 ) ); + setColorStopAt( 0.8, QColor( 255, 255, 50 ) ); + setColorStopAt( 1, QColor( 255, 255, 255 ) ); + break; + case gpCold: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 0, 0, 50 ) ); + setColorStopAt( 0.2, QColor( 0, 10, 180 ) ); + setColorStopAt( 0.4, QColor( 0, 50, 245 ) ); + setColorStopAt( 0.6, QColor( 10, 150, 255 ) ); + setColorStopAt( 0.8, QColor( 50, 255, 255 ) ); + setColorStopAt( 1, QColor( 255, 255, 255 ) ); + break; + case gpNight: + setColorInterpolation( ciHSV ); + setColorStopAt( 0, QColor( 10, 20, 30 ) ); + setColorStopAt( 1, QColor( 250, 255, 250 ) ); + break; + case gpCandy: + setColorInterpolation( ciHSV ); + setColorStopAt( 0, QColor( 0, 0, 255 ) ); + setColorStopAt( 1, QColor( 255, 250, 250 ) ); + break; + case gpGeography: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 70, 170, 210 ) ); + setColorStopAt( 0.20, QColor( 90, 160, 180 ) ); + setColorStopAt( 0.25, QColor( 45, 130, 175 ) ); + setColorStopAt( 0.30, QColor( 100, 140, 125 ) ); + setColorStopAt( 0.5, QColor( 100, 140, 100 ) ); + setColorStopAt( 0.6, QColor( 130, 145, 120 ) ); + setColorStopAt( 0.7, QColor( 140, 130, 120 ) ); + setColorStopAt( 0.9, QColor( 180, 190, 190 ) ); + setColorStopAt( 1, QColor( 210, 210, 230 ) ); + break; + case gpIon: + setColorInterpolation( ciHSV ); + setColorStopAt( 0, QColor( 50, 10, 10 ) ); + setColorStopAt( 0.45, QColor( 0, 0, 255 ) ); + setColorStopAt( 0.8, QColor( 0, 255, 255 ) ); + setColorStopAt( 1, QColor( 0, 255, 0 ) ); + break; + case gpThermal: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 0, 0, 50 ) ); + setColorStopAt( 0.15, QColor( 20, 0, 120 ) ); + setColorStopAt( 0.33, QColor( 200, 30, 140 ) ); + setColorStopAt( 0.6, QColor( 255, 100, 0 ) ); + setColorStopAt( 0.85, QColor( 255, 255, 40 ) ); + setColorStopAt( 1, QColor( 255, 255, 255 ) ); + break; + case gpPolar: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 50, 255, 255 ) ); + setColorStopAt( 0.18, QColor( 10, 70, 255 ) ); + setColorStopAt( 0.28, QColor( 10, 10, 190 ) ); + setColorStopAt( 0.5, QColor( 0, 0, 0 ) ); + setColorStopAt( 0.72, QColor( 190, 10, 10 ) ); + setColorStopAt( 0.82, QColor( 255, 70, 10 ) ); + setColorStopAt( 1, QColor( 255, 255, 50 ) ); + break; + case gpSpectrum: + setColorInterpolation( ciHSV ); + setColorStopAt( 0, QColor( 50, 0, 50 ) ); + setColorStopAt( 0.15, QColor( 0, 0, 255 ) ); + setColorStopAt( 0.35, QColor( 0, 255, 255 ) ); + setColorStopAt( 0.6, QColor( 255, 255, 0 ) ); + setColorStopAt( 0.75, QColor( 255, 30, 0 ) ); + setColorStopAt( 1, QColor( 50, 0, 0 ) ); + break; + case gpJet: + setColorInterpolation( ciRGB ); + setColorStopAt( 0, QColor( 0, 0, 100 ) ); + setColorStopAt( 0.15, QColor( 0, 50, 255 ) ); + setColorStopAt( 0.35, QColor( 0, 255, 255 ) ); + setColorStopAt( 0.65, QColor( 255, 255, 0 ) ); + setColorStopAt( 0.85, QColor( 255, 30, 0 ) ); + setColorStopAt( 1, QColor( 100, 0, 0 ) ); + break; + case gpHues: + setColorInterpolation( ciHSV ); + setColorStopAt( 0, QColor( 255, 0, 0 ) ); + setColorStopAt( 1.0 / 3.0, QColor( 0, 0, 255 ) ); + setColorStopAt( 2.0 / 3.0, QColor( 0, 255, 0 ) ); + setColorStopAt( 1, QColor( 255, 0, 0 ) ); + break; } } @@ -16268,10 +16406,10 @@ void QCPColorGradient::clearColorStops() */ QCPColorGradient QCPColorGradient::inverted() const { - QCPColorGradient result(*this); + QCPColorGradient result( *this ); result.clearColorStops(); - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) - result.setColorStopAt(1.0-it.key(), it.value()); + for( QMap::const_iterator it = mColorStops.constBegin(); it != mColorStops.constEnd(); ++it ) + result.setColorStopAt( 1.0 - it.key(), it.value() ); return result; } @@ -16282,9 +16420,9 @@ QCPColorGradient QCPColorGradient::inverted() const */ bool QCPColorGradient::stopsUseAlpha() const { - for (QMap::const_iterator it=mColorStops.constBegin(); it!=mColorStops.constEnd(); ++it) + for( QMap::const_iterator it = mColorStops.constBegin(); it != mColorStops.constEnd(); ++it ) { - if (it.value().alpha() < 255) + if( it.value().alpha() < 255 ) return true; } return false; @@ -16297,106 +16435,114 @@ bool QCPColorGradient::stopsUseAlpha() const */ void QCPColorGradient::updateColorBuffer() { - if (mColorBuffer.size() != mLevelCount) - mColorBuffer.resize(mLevelCount); - if (mColorStops.size() > 1) + if( mColorBuffer.size() != mLevelCount ) + mColorBuffer.resize( mLevelCount ); + if( mColorStops.size() > 1 ) { - double indexToPosFactor = 1.0/(double)(mLevelCount-1); + double indexToPosFactor = 1.0 / (double)( mLevelCount - 1 ); const bool useAlpha = stopsUseAlpha(); - for (int i=0; i::const_iterator it = mColorStops.lowerBound(position); - if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop + double position = i * indexToPosFactor; + QMap::const_iterator it = mColorStops.lowerBound( position ); + if( it == mColorStops.constEnd() ) // position is on or after last stop, use color of last stop { - if (useAlpha) + if( useAlpha ) { - const QColor col = (it-1).value(); - const float alphaPremultiplier = col.alpha()/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(col.red()*alphaPremultiplier, col.green()*alphaPremultiplier, col.blue()*alphaPremultiplier, col.alpha()); - } else - mColorBuffer[i] = (it-1).value().rgba(); - } else if (it == mColorStops.constBegin()) // position is on or before first stop, use color of first stop + const QColor col = ( it - 1 ).value(); + const float alphaPremultiplier = col.alpha() / 255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba( col.red() * alphaPremultiplier, col.green() * alphaPremultiplier, col.blue() * alphaPremultiplier, col.alpha() ); + } + else + mColorBuffer[i] = ( it - 1 ).value().rgba(); + } + else if( it == mColorStops.constBegin() ) // position is on or before first stop, use color of first stop { - if (useAlpha) + if( useAlpha ) { const QColor col = it.value(); - const float alphaPremultiplier = col.alpha()/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(col.red()*alphaPremultiplier, col.green()*alphaPremultiplier, col.blue()*alphaPremultiplier, col.alpha()); - } else + const float alphaPremultiplier = col.alpha() / 255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba( col.red() * alphaPremultiplier, col.green() * alphaPremultiplier, col.blue() * alphaPremultiplier, col.alpha() ); + } + else mColorBuffer[i] = it.value().rgba(); - } else // position is in between stops (or on an intermediate stop), interpolate color + } + else // position is in between stops (or on an intermediate stop), interpolate color { QMap::const_iterator high = it; - QMap::const_iterator low = it-1; - double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 - switch (mColorInterpolation) + QMap::const_iterator low = it - 1; + double t = ( position - low.key() ) / ( high.key() - low.key() ); // interpolation factor 0..1 + switch( mColorInterpolation ) { - case ciRGB: + case ciRGB: { + if( useAlpha ) { - if (useAlpha) - { - const int alpha = (1-t)*low.value().alpha() + t*high.value().alpha(); - const float alphaPremultiplier = alpha/255.0f; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba(((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier, - ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier, - ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier, - alpha); - } else - { - mColorBuffer[i] = qRgb(((1-t)*low.value().red() + t*high.value().red()), - ((1-t)*low.value().green() + t*high.value().green()), - ((1-t)*low.value().blue() + t*high.value().blue())); - } - break; + const int alpha = ( 1 - t ) * low.value().alpha() + t * high.value().alpha(); + const float alphaPremultiplier = alpha / 255.0f; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba( ( ( 1 - t ) * low.value().red() + t * high.value().red() ) * alphaPremultiplier, + ( ( 1 - t ) * low.value().green() + t * high.value().green() ) * alphaPremultiplier, + ( ( 1 - t ) * low.value().blue() + t * high.value().blue() ) * alphaPremultiplier, + alpha ); } - case ciHSV: + else { - QColor lowHsv = low.value().toHsv(); - QColor highHsv = high.value().toHsv(); - double hue = 0; - double hueDiff = highHsv.hueF()-lowHsv.hueF(); - if (hueDiff > 0.5) - hue = lowHsv.hueF() - t*(1.0-hueDiff); - else if (hueDiff < -0.5) - hue = lowHsv.hueF() + t*(1.0+hueDiff); - else - hue = lowHsv.hueF() + t*hueDiff; - if (hue < 0) hue += 1.0; - else if (hue >= 1.0) hue -= 1.0; - if (useAlpha) - { - const QRgb rgb = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - const float alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); - mColorBuffer[i] = qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha); - } - else - { - mColorBuffer[i] = QColor::fromHsvF(hue, - (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), - (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); - } - break; + mColorBuffer[i] = qRgb( ( ( 1 - t ) * low.value().red() + t * high.value().red() ), + ( ( 1 - t ) * low.value().green() + t * high.value().green() ), + ( ( 1 - t ) * low.value().blue() + t * high.value().blue() ) ); } + break; + } + case ciHSV: { + QColor lowHsv = low.value().toHsv(); + QColor highHsv = high.value().toHsv(); + double hue = 0; + double hueDiff = highHsv.hueF() - lowHsv.hueF(); + if( hueDiff > 0.5 ) + hue = lowHsv.hueF() - t * ( 1.0 - hueDiff ); + else if( hueDiff < -0.5 ) + hue = lowHsv.hueF() + t * ( 1.0 + hueDiff ); + else + hue = lowHsv.hueF() + t * hueDiff; + if( hue < 0 ) + hue += 1.0; + else if( hue >= 1.0 ) + hue -= 1.0; + if( useAlpha ) + { + const QRgb rgb = QColor::fromHsvF( hue, + ( 1 - t ) * lowHsv.saturationF() + t * highHsv.saturationF(), + ( 1 - t ) * lowHsv.valueF() + t * highHsv.valueF() ) + .rgb(); + const float alpha = ( 1 - t ) * lowHsv.alphaF() + t * highHsv.alphaF(); + mColorBuffer[i] = qRgba( qRed( rgb ) * alpha, qGreen( rgb ) * alpha, qBlue( rgb ) * alpha, 255 * alpha ); + } + else + { + mColorBuffer[i] = QColor::fromHsvF( hue, + ( 1 - t ) * lowHsv.saturationF() + t * highHsv.saturationF(), + ( 1 - t ) * lowHsv.valueF() + t * highHsv.valueF() ) + .rgb(); + } + break; + } } } } - } else if (mColorStops.size() == 1) + } + else if( mColorStops.size() == 1 ) { const QRgb rgb = mColorStops.constBegin().value().rgb(); const float alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill(qRgba(qRed(rgb)*alpha, qGreen(rgb)*alpha, qBlue(rgb)*alpha, 255*alpha)); - } else // mColorStops is empty, fill color buffer with black + mColorBuffer.fill( qRgba( qRed( rgb ) * alpha, qGreen( rgb ) * alpha, qBlue( rgb ) * alpha, 255 * alpha ) ); + } + else // mColorStops is empty, fill color buffer with black { - mColorBuffer.fill(qRgb(0, 0, 0)); + mColorBuffer.fill( qRgb( 0, 0, 0 ) ); } mColorBufferInvalidated = false; } /* end of 'src/colorgradient.cpp' */ - /* including file 'src/selectiondecorator-bracket.cpp', size 12313 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -16423,16 +16569,9 @@ void QCPColorGradient::updateColorBuffer() /*! Creates a new QCPSelectionDecoratorBracket instance with default values. */ -QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() : - mBracketPen(QPen(Qt::black)), - mBracketBrush(Qt::NoBrush), - mBracketWidth(5), - mBracketHeight(50), - mBracketStyle(bsSquareBracket), - mTangentToData(false), - mTangentAverage(2) +QCPSelectionDecoratorBracket::QCPSelectionDecoratorBracket() + : mBracketPen( QPen( Qt::black ) ), mBracketBrush( Qt::NoBrush ), mBracketWidth( 5 ), mBracketHeight( 50 ), mBracketStyle( bsSquareBracket ), mTangentToData( false ), mTangentAverage( 2 ) { - } QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() @@ -16443,7 +16582,7 @@ QCPSelectionDecoratorBracket::~QCPSelectionDecoratorBracket() Sets the pen that will be used to draw the brackets at the beginning and end of each selected data segment. */ -void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) +void QCPSelectionDecoratorBracket::setBracketPen( const QPen& pen ) { mBracketPen = pen; } @@ -16452,7 +16591,7 @@ void QCPSelectionDecoratorBracket::setBracketPen(const QPen &pen) Sets the brush that will be used to draw the brackets at the beginning and end of each selected data segment. */ -void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) +void QCPSelectionDecoratorBracket::setBracketBrush( const QBrush& brush ) { mBracketBrush = brush; } @@ -16462,7 +16601,7 @@ void QCPSelectionDecoratorBracket::setBracketBrush(const QBrush &brush) the data, or the tangent direction of the current data slope, if \ref setTangentToData is enabled. */ -void QCPSelectionDecoratorBracket::setBracketWidth(int width) +void QCPSelectionDecoratorBracket::setBracketWidth( int width ) { mBracketWidth = width; } @@ -16472,7 +16611,7 @@ void QCPSelectionDecoratorBracket::setBracketWidth(int width) of the data, or the tangent direction of the current data slope, if \ref setTangentToData is enabled. */ -void QCPSelectionDecoratorBracket::setBracketHeight(int height) +void QCPSelectionDecoratorBracket::setBracketHeight( int height ) { mBracketHeight = height; } @@ -16482,7 +16621,7 @@ void QCPSelectionDecoratorBracket::setBracketHeight(int height) \see setBracketWidth, setBracketHeight */ -void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) +void QCPSelectionDecoratorBracket::setBracketStyle( QCPSelectionDecoratorBracket::BracketStyle style ) { mBracketStyle = style; } @@ -16494,7 +16633,7 @@ void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket: For noisy data, it might be more visually appealing to average the slope over multiple data points. This can be configured via \ref setTangentAverage. */ -void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) +void QCPSelectionDecoratorBracket::setTangentToData( bool enabled ) { mTangentToData = enabled; } @@ -16507,10 +16646,10 @@ void QCPSelectionDecoratorBracket::setTangentToData(bool enabled) taken into account. The smallest value of \a pointCount is 1, which is effectively equivalent to disabling \ref setTangentToData. */ -void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) +void QCPSelectionDecoratorBracket::setTangentAverage( int pointCount ) { mTangentAverage = pointCount; - if (mTangentAverage < 1) + if( mTangentAverage < 1 ) mTangentAverage = 1; } @@ -16527,38 +16666,33 @@ void QCPSelectionDecoratorBracket::setTangentAverage(int pointCount) shapes (see \ref QCPSelectionDecoratorBracket::bsUserStyle), this is the method you should reimplement. */ -void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int direction) const +void QCPSelectionDecoratorBracket::drawBracket( QCPPainter* painter, int direction ) const { - switch (mBracketStyle) + switch( mBracketStyle ) { - case bsSquareBracket: - { - painter->drawLine(QLineF(mBracketWidth*direction, -mBracketHeight*0.5, 0, -mBracketHeight*0.5)); - painter->drawLine(QLineF(mBracketWidth*direction, mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - break; - } - case bsHalfEllipse: - { - painter->drawArc(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight, -90*16, -180*16*direction); - break; - } - case bsEllipse: - { - painter->drawEllipse(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight); - break; - } - case bsPlus: - { - painter->drawLine(QLineF(0, -mBracketHeight*0.5, 0, mBracketHeight*0.5)); - painter->drawLine(QLineF(-mBracketWidth*0.5, 0, mBracketWidth*0.5, 0)); - break; - } - default: - { - qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast(mBracketStyle); - break; - } + case bsSquareBracket: { + painter->drawLine( QLineF( mBracketWidth * direction, -mBracketHeight * 0.5, 0, -mBracketHeight * 0.5 ) ); + painter->drawLine( QLineF( mBracketWidth * direction, mBracketHeight * 0.5, 0, mBracketHeight * 0.5 ) ); + painter->drawLine( QLineF( 0, -mBracketHeight * 0.5, 0, mBracketHeight * 0.5 ) ); + break; + } + case bsHalfEllipse: { + painter->drawArc( -mBracketWidth * 0.5, -mBracketHeight * 0.5, mBracketWidth, mBracketHeight, -90 * 16, -180 * 16 * direction ); + break; + } + case bsEllipse: { + painter->drawEllipse( -mBracketWidth * 0.5, -mBracketHeight * 0.5, mBracketWidth, mBracketHeight ); + break; + } + case bsPlus: { + painter->drawLine( QLineF( 0, -mBracketHeight * 0.5, 0, mBracketHeight * 0.5 ) ); + painter->drawLine( QLineF( -mBracketWidth * 0.5, 0, mBracketWidth * 0.5, 0 ) ); + break; + } + default: { + qDebug() << Q_FUNC_INFO << "unknown/custom bracket style can't be handeld by default implementation:" << static_cast( mBracketStyle ); + break; + } } } @@ -16570,41 +16704,42 @@ void QCPSelectionDecoratorBracket::drawBracket(QCPPainter *painter, int directio \seebaseclassmethod */ -void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSelection selection) +void QCPSelectionDecoratorBracket::drawDecoration( QCPPainter* painter, QCPDataSelection selection ) { - if (!mPlottable || selection.isEmpty()) return; - - if (QCPPlottableInterface1D *interface1d = mPlottable->interface1D()) + if( !mPlottable || selection.isEmpty() ) + return; + + if( QCPPlottableInterface1D* interface1d = mPlottable->interface1D() ) { - foreach (const QCPDataRange &dataRange, selection.dataRanges()) + foreach( const QCPDataRange& dataRange, selection.dataRanges() ) { // determine position and (if tangent mode is enabled) angle of brackets: - int openBracketDir = (mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed()) ? 1 : -1; + int openBracketDir = ( mPlottable->keyAxis() && !mPlottable->keyAxis()->rangeReversed() ) ? 1 : -1; int closeBracketDir = -openBracketDir; - QPointF openBracketPos = getPixelCoordinates(interface1d, dataRange.begin()); - QPointF closeBracketPos = getPixelCoordinates(interface1d, dataRange.end()-1); + QPointF openBracketPos = getPixelCoordinates( interface1d, dataRange.begin() ); + QPointF closeBracketPos = getPixelCoordinates( interface1d, dataRange.end() - 1 ); double openBracketAngle = 0; double closeBracketAngle = 0; - if (mTangentToData) + if( mTangentToData ) { - openBracketAngle = getTangentAngle(interface1d, dataRange.begin(), openBracketDir); - closeBracketAngle = getTangentAngle(interface1d, dataRange.end()-1, closeBracketDir); + openBracketAngle = getTangentAngle( interface1d, dataRange.begin(), openBracketDir ); + closeBracketAngle = getTangentAngle( interface1d, dataRange.end() - 1, closeBracketDir ); } // draw opening bracket: QTransform oldTransform = painter->transform(); - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(openBracketPos); - painter->rotate(openBracketAngle/M_PI*180.0); - drawBracket(painter, openBracketDir); - painter->setTransform(oldTransform); + painter->setPen( mBracketPen ); + painter->setBrush( mBracketBrush ); + painter->translate( openBracketPos ); + painter->rotate( openBracketAngle / M_PI * 180.0 ); + drawBracket( painter, openBracketDir ); + painter->setTransform( oldTransform ); // draw closing bracket: - painter->setPen(mBracketPen); - painter->setBrush(mBracketBrush); - painter->translate(closeBracketPos); - painter->rotate(closeBracketAngle/M_PI*180.0); - drawBracket(painter, closeBracketDir); - painter->setTransform(oldTransform); + painter->setPen( mBracketPen ); + painter->setBrush( mBracketBrush ); + painter->translate( closeBracketPos ); + painter->rotate( closeBracketAngle / M_PI * 180.0 ); + drawBracket( painter, closeBracketDir ); + painter->setTransform( oldTransform ); } } } @@ -16622,45 +16757,46 @@ void QCPSelectionDecoratorBracket::drawDecoration(QCPPainter *painter, QCPDataSe \a interface1d is the interface to the plottable's data which is used to query data coordinates. */ -double QCPSelectionDecoratorBracket::getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const +double QCPSelectionDecoratorBracket::getTangentAngle( const QCPPlottableInterface1D* interface1d, int dataIndex, int direction ) const { - if (!interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount()) + if( !interface1d || dataIndex < 0 || dataIndex >= interface1d->dataCount() ) return 0; - direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 - + direction = direction < 0 ? -1 : 1; // enforce direction is either -1 or 1 + // how many steps we can actually go from index in the given direction without exceeding data bounds: int averageCount; - if (direction < 0) - averageCount = qMin(mTangentAverage, dataIndex); + if( direction < 0 ) + averageCount = qMin( mTangentAverage, dataIndex ); else - averageCount = qMin(mTangentAverage, interface1d->dataCount()-1-dataIndex); + averageCount = qMin( mTangentAverage, interface1d->dataCount() - 1 - dataIndex ); qDebug() << averageCount; // calculate point average of averageCount points: - QVector points(averageCount); + QVector points( averageCount ); QPointF pointsAverage; int currentIndex = dataIndex; - for (int i=0; ikeyAxis(); - QCPAxis *valueAxis = mPlottable->valueAxis(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(0, 0); } - - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))); + QCPAxis* keyAxis = mPlottable->keyAxis(); + QCPAxis* valueAxis = mPlottable->valueAxis(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QPointF( 0, 0 ); + } + + if( keyAxis->orientation() == Qt::Horizontal ) + return QPointF( keyAxis->coordToPixel( interface1d->dataMainKey( dataIndex ) ), valueAxis->coordToPixel( interface1d->dataMainValue( dataIndex ) ) ); else - return QPointF(valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))); + return QPointF( valueAxis->coordToPixel( interface1d->dataMainValue( dataIndex ) ), keyAxis->coordToPixel( interface1d->dataMainKey( dataIndex ) ) ); } /* end of 'src/selectiondecorator-bracket.cpp' */ - /* including file 'src/layoutelements/layoutelement-axisrect.cpp', size 47584 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisRect //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -16816,47 +16954,38 @@ QPointF QCPSelectionDecoratorBracket::getPixelCoordinates(const QCPPlottableInte Creates a QCPAxisRect instance and sets default values. An axis is added for each of the four sides, the top and right axes are set invisible initially. */ -QCPAxisRect::QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes) : - QCPLayoutElement(parentPlot), - mBackgroundBrush(Qt::NoBrush), - mBackgroundScaled(true), - mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), - mInsetLayout(new QCPLayoutInset), - mRangeDrag(Qt::Horizontal|Qt::Vertical), - mRangeZoom(Qt::Horizontal|Qt::Vertical), - mRangeZoomFactorHorz(0.85), - mRangeZoomFactorVert(0.85), - mDragging(false) +QCPAxisRect::QCPAxisRect( QCustomPlot* parentPlot, bool setupDefaultAxes ) + : QCPLayoutElement( parentPlot ), mBackgroundBrush( Qt::NoBrush ), mBackgroundScaled( true ), mBackgroundScaledMode( Qt::KeepAspectRatioByExpanding ), mInsetLayout( new QCPLayoutInset ), mRangeDrag( Qt::Horizontal | Qt::Vertical ), mRangeZoom( Qt::Horizontal | Qt::Vertical ), mRangeZoomFactorHorz( 0.85 ), mRangeZoomFactorVert( 0.85 ), mDragging( false ) { - mInsetLayout->initializeParentPlot(mParentPlot); - mInsetLayout->setParentLayerable(this); - mInsetLayout->setParent(this); - - setMinimumSize(50, 50); - setMinimumMargins(QMargins(15, 15, 15, 15)); - mAxes.insert(QCPAxis::atLeft, QList()); - mAxes.insert(QCPAxis::atRight, QList()); - mAxes.insert(QCPAxis::atTop, QList()); - mAxes.insert(QCPAxis::atBottom, QList()); - - if (setupDefaultAxes) + mInsetLayout->initializeParentPlot( mParentPlot ); + mInsetLayout->setParentLayerable( this ); + mInsetLayout->setParent( this ); + + setMinimumSize( 50, 50 ); + setMinimumMargins( QMargins( 15, 15, 15, 15 ) ); + mAxes.insert( QCPAxis::atLeft, QList() ); + mAxes.insert( QCPAxis::atRight, QList() ); + mAxes.insert( QCPAxis::atTop, QList() ); + mAxes.insert( QCPAxis::atBottom, QList() ); + + if( setupDefaultAxes ) { - QCPAxis *xAxis = addAxis(QCPAxis::atBottom); - QCPAxis *yAxis = addAxis(QCPAxis::atLeft); - QCPAxis *xAxis2 = addAxis(QCPAxis::atTop); - QCPAxis *yAxis2 = addAxis(QCPAxis::atRight); - setRangeDragAxes(xAxis, yAxis); - setRangeZoomAxes(xAxis, yAxis); - xAxis2->setVisible(false); - yAxis2->setVisible(false); - xAxis->grid()->setVisible(true); - yAxis->grid()->setVisible(true); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); - xAxis2->grid()->setZeroLinePen(Qt::NoPen); - yAxis2->grid()->setZeroLinePen(Qt::NoPen); - xAxis2->grid()->setVisible(false); - yAxis2->grid()->setVisible(false); + QCPAxis* xAxis = addAxis( QCPAxis::atBottom ); + QCPAxis* yAxis = addAxis( QCPAxis::atLeft ); + QCPAxis* xAxis2 = addAxis( QCPAxis::atTop ); + QCPAxis* yAxis2 = addAxis( QCPAxis::atRight ); + setRangeDragAxes( xAxis, yAxis ); + setRangeZoomAxes( xAxis, yAxis ); + xAxis2->setVisible( false ); + yAxis2->setVisible( false ); + xAxis->grid()->setVisible( true ); + yAxis->grid()->setVisible( true ); + xAxis2->grid()->setVisible( false ); + yAxis2->grid()->setVisible( false ); + xAxis2->grid()->setZeroLinePen( Qt::NoPen ); + yAxis2->grid()->setZeroLinePen( Qt::NoPen ); + xAxis2->grid()->setVisible( false ); + yAxis2->grid()->setVisible( false ); } } @@ -16864,10 +16993,10 @@ QCPAxisRect::~QCPAxisRect() { delete mInsetLayout; mInsetLayout = 0; - + QList axesList = axes(); - for (int i=0; i ax(mAxes.value(type)); - if (index >= 0 && index < ax.size()) + QList ax( mAxes.value( type ) ); + if( index >= 0 && index < ax.size() ) { - return ax.at(index); - } else + return ax.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; return 0; @@ -16906,17 +17036,17 @@ QCPAxis *QCPAxisRect::axis(QCPAxis::AxisType type, int index) const \see axis */ -QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const +QList QCPAxisRect::axes( QCPAxis::AxisTypes types ) const { QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << mAxes.value(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << mAxes.value(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << mAxes.value(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << mAxes.value(QCPAxis::atBottom); + if( types.testFlag( QCPAxis::atLeft ) ) + result << mAxes.value( QCPAxis::atLeft ); + if( types.testFlag( QCPAxis::atRight ) ) + result << mAxes.value( QCPAxis::atRight ); + if( types.testFlag( QCPAxis::atTop ) ) + result << mAxes.value( QCPAxis::atTop ); + if( types.testFlag( QCPAxis::atBottom ) ) + result << mAxes.value( QCPAxis::atBottom ); return result; } @@ -16927,8 +17057,8 @@ QList QCPAxisRect::axes(QCPAxis::AxisTypes types) const QList QCPAxisRect::axes() const { QList result; - QHashIterator > it(mAxes); - while (it.hasNext()) + QHashIterator > it( mAxes ); + while( it.hasNext() ) { it.next(); result << it.value(); @@ -16956,50 +17086,67 @@ QList QCPAxisRect::axes() const \see addAxes, setupFullAxesBox */ -QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) +QCPAxis* QCPAxisRect::addAxis( QCPAxis::AxisType type, QCPAxis* axis ) { - QCPAxis *newAxis = axis; - if (!newAxis) + QCPAxis* newAxis = axis; + if( !newAxis ) { - newAxis = new QCPAxis(this, type); - } else // user provided existing axis instance, do some sanity checks + newAxis = new QCPAxis( this, type ); + } + else // user provided existing axis instance, do some sanity checks { - if (newAxis->axisType() != type) + if( newAxis->axisType() != type ) { qDebug() << Q_FUNC_INFO << "passed axis has different axis type than specified in type parameter"; return 0; } - if (newAxis->axisRect() != this) + if( newAxis->axisRect() != this ) { qDebug() << Q_FUNC_INFO << "passed axis doesn't have this axis rect as parent axis rect"; return 0; } - if (axes().contains(newAxis)) + if( axes().contains( newAxis ) ) { qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; return 0; } } - if (mAxes[type].size() > 0) // multiple axes on one side, add half-bar axis ending to additional axes with offset + if( mAxes[type].size() > 0 ) // multiple axes on one side, add half-bar axis ending to additional axes with offset { - bool invert = (type == QCPAxis::atRight) || (type == QCPAxis::atBottom); - newAxis->setLowerEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, !invert)); - newAxis->setUpperEnding(QCPLineEnding(QCPLineEnding::esHalfBar, 6, 10, invert)); + bool invert = ( type == QCPAxis::atRight ) || ( type == QCPAxis::atBottom ); + newAxis->setLowerEnding( QCPLineEnding( QCPLineEnding::esHalfBar, 6, 10, !invert ) ); + newAxis->setUpperEnding( QCPLineEnding( QCPLineEnding::esHalfBar, 6, 10, invert ) ); } - mAxes[type].append(newAxis); - + mAxes[type].append( newAxis ); + // reset convenience axis pointers on parent QCustomPlot if they are unset: - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + if( mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect( 0 ) == this ) { - switch (type) + switch( type ) { - case QCPAxis::atBottom: { if (!mParentPlot->xAxis) mParentPlot->xAxis = newAxis; break; } - case QCPAxis::atLeft: { if (!mParentPlot->yAxis) mParentPlot->yAxis = newAxis; break; } - case QCPAxis::atTop: { if (!mParentPlot->xAxis2) mParentPlot->xAxis2 = newAxis; break; } - case QCPAxis::atRight: { if (!mParentPlot->yAxis2) mParentPlot->yAxis2 = newAxis; break; } + case QCPAxis::atBottom: { + if( !mParentPlot->xAxis ) + mParentPlot->xAxis = newAxis; + break; + } + case QCPAxis::atLeft: { + if( !mParentPlot->yAxis ) + mParentPlot->yAxis = newAxis; + break; + } + case QCPAxis::atTop: { + if( !mParentPlot->xAxis2 ) + mParentPlot->xAxis2 = newAxis; + break; + } + case QCPAxis::atRight: { + if( !mParentPlot->yAxis2 ) + mParentPlot->yAxis2 = newAxis; + break; + } } } - + return newAxis; } @@ -17011,17 +17158,17 @@ QCPAxis *QCPAxisRect::addAxis(QCPAxis::AxisType type, QCPAxis *axis) \see addAxis, setupFullAxesBox */ -QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) +QList QCPAxisRect::addAxes( QCPAxis::AxisTypes types ) { QList result; - if (types.testFlag(QCPAxis::atLeft)) - result << addAxis(QCPAxis::atLeft); - if (types.testFlag(QCPAxis::atRight)) - result << addAxis(QCPAxis::atRight); - if (types.testFlag(QCPAxis::atTop)) - result << addAxis(QCPAxis::atTop); - if (types.testFlag(QCPAxis::atBottom)) - result << addAxis(QCPAxis::atBottom); + if( types.testFlag( QCPAxis::atLeft ) ) + result << addAxis( QCPAxis::atLeft ); + if( types.testFlag( QCPAxis::atRight ) ) + result << addAxis( QCPAxis::atRight ); + if( types.testFlag( QCPAxis::atTop ) ) + result << addAxis( QCPAxis::atTop ); + if( types.testFlag( QCPAxis::atBottom ) ) + result << addAxis( QCPAxis::atBottom ); return result; } @@ -17032,25 +17179,25 @@ QList QCPAxisRect::addAxes(QCPAxis::AxisTypes types) \see addAxis */ -bool QCPAxisRect::removeAxis(QCPAxis *axis) +bool QCPAxisRect::removeAxis( QCPAxis* axis ) { // don't access axis->axisType() to provide safety when axis is an invalid pointer, rather go through all axis containers: - QHashIterator > it(mAxes); - while (it.hasNext()) + QHashIterator > it( mAxes ); + while( it.hasNext() ) { it.next(); - if (it.value().contains(axis)) + if( it.value().contains( axis ) ) { - if (it.value().first() == axis && it.value().size() > 1) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) - it.value()[1]->setOffset(axis->offset()); - mAxes[it.key()].removeOne(axis); - if (qobject_cast(parentPlot())) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) - parentPlot()->axisRemoved(axis); + if( it.value().first() == axis && it.value().size() > 1 ) // if removing first axis, transfer axis offset to the new first axis (which at this point is the second axis, if it exists) + it.value()[1]->setOffset( axis->offset() ); + mAxes[it.key()].removeOne( axis ); + if( qobject_cast( parentPlot() ) ) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the axis rect is not in any layout and thus QObject-child of QCustomPlot) + parentPlot()->axisRemoved( axis ); delete axis; return true; } } - qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast(axis); + qDebug() << Q_FUNC_INFO << "Axis isn't in axis rect:" << reinterpret_cast( axis ); return false; } @@ -17062,9 +17209,9 @@ bool QCPAxisRect::removeAxis(QCPAxis *axis) \see QCustomPlot::setSelectionRectMode */ -void QCPAxisRect::zoom(const QRectF &pixelRect) +void QCPAxisRect::zoom( const QRectF& pixelRect ) { - zoom(pixelRect, axes()); + zoom( pixelRect, axes() ); } /*! \overload @@ -17075,21 +17222,21 @@ void QCPAxisRect::zoom(const QRectF &pixelRect) \see QCustomPlot::setSelectionRectMode */ -void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedAxes) +void QCPAxisRect::zoom( const QRectF& pixelRect, const QList& affectedAxes ) { - foreach (QCPAxis *axis, affectedAxes) + foreach( QCPAxis* axis, affectedAxes ) { - if (!axis) + if( !axis ) { qDebug() << Q_FUNC_INFO << "a passed axis was zero"; continue; } QCPRange pixelRange; - if (axis->orientation() == Qt::Horizontal) - pixelRange = QCPRange(pixelRect.left(), pixelRect.right()); + if( axis->orientation() == Qt::Horizontal ) + pixelRange = QCPRange( pixelRect.left(), pixelRect.right() ); else - pixelRange = QCPRange(pixelRect.top(), pixelRect.bottom()); - axis->setRange(axis->pixelToCoord(pixelRange.lower), axis->pixelToCoord(pixelRange.upper)); + pixelRange = QCPRange( pixelRect.top(), pixelRect.bottom() ); + axis->setRange( axis->pixelToCoord( pixelRange.lower ), axis->pixelToCoord( pixelRange.upper ) ); } } @@ -17112,58 +17259,58 @@ void QCPAxisRect::zoom(const QRectF &pixelRect, const QList &affectedA If \a connectRanges is true, the \ref QCPAxis::rangeChanged "rangeChanged" signals of the bottom and left axes are connected to the \ref QCPAxis::setRange slots of the top and right axes. */ -void QCPAxisRect::setupFullAxesBox(bool connectRanges) +void QCPAxisRect::setupFullAxesBox( bool connectRanges ) { QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - if (axisCount(QCPAxis::atBottom) == 0) - xAxis = addAxis(QCPAxis::atBottom); + if( axisCount( QCPAxis::atBottom ) == 0 ) + xAxis = addAxis( QCPAxis::atBottom ); else - xAxis = axis(QCPAxis::atBottom); - - if (axisCount(QCPAxis::atLeft) == 0) - yAxis = addAxis(QCPAxis::atLeft); + xAxis = axis( QCPAxis::atBottom ); + + if( axisCount( QCPAxis::atLeft ) == 0 ) + yAxis = addAxis( QCPAxis::atLeft ); else - yAxis = axis(QCPAxis::atLeft); - - if (axisCount(QCPAxis::atTop) == 0) - xAxis2 = addAxis(QCPAxis::atTop); + yAxis = axis( QCPAxis::atLeft ); + + if( axisCount( QCPAxis::atTop ) == 0 ) + xAxis2 = addAxis( QCPAxis::atTop ); else - xAxis2 = axis(QCPAxis::atTop); - - if (axisCount(QCPAxis::atRight) == 0) - yAxis2 = addAxis(QCPAxis::atRight); + xAxis2 = axis( QCPAxis::atTop ); + + if( axisCount( QCPAxis::atRight ) == 0 ) + yAxis2 = addAxis( QCPAxis::atRight ); else - yAxis2 = axis(QCPAxis::atRight); - - xAxis->setVisible(true); - yAxis->setVisible(true); - xAxis2->setVisible(true); - yAxis2->setVisible(true); - xAxis2->setTickLabels(false); - yAxis2->setTickLabels(false); - - xAxis2->setRange(xAxis->range()); - xAxis2->setRangeReversed(xAxis->rangeReversed()); - xAxis2->setScaleType(xAxis->scaleType()); - xAxis2->setTicks(xAxis->ticks()); - xAxis2->setNumberFormat(xAxis->numberFormat()); - xAxis2->setNumberPrecision(xAxis->numberPrecision()); - xAxis2->ticker()->setTickCount(xAxis->ticker()->tickCount()); - xAxis2->ticker()->setTickOrigin(xAxis->ticker()->tickOrigin()); - - yAxis2->setRange(yAxis->range()); - yAxis2->setRangeReversed(yAxis->rangeReversed()); - yAxis2->setScaleType(yAxis->scaleType()); - yAxis2->setTicks(yAxis->ticks()); - yAxis2->setNumberFormat(yAxis->numberFormat()); - yAxis2->setNumberPrecision(yAxis->numberPrecision()); - yAxis2->ticker()->setTickCount(yAxis->ticker()->tickCount()); - yAxis2->ticker()->setTickOrigin(yAxis->ticker()->tickOrigin()); - - if (connectRanges) + yAxis2 = axis( QCPAxis::atRight ); + + xAxis->setVisible( true ); + yAxis->setVisible( true ); + xAxis2->setVisible( true ); + yAxis2->setVisible( true ); + xAxis2->setTickLabels( false ); + yAxis2->setTickLabels( false ); + + xAxis2->setRange( xAxis->range() ); + xAxis2->setRangeReversed( xAxis->rangeReversed() ); + xAxis2->setScaleType( xAxis->scaleType() ); + xAxis2->setTicks( xAxis->ticks() ); + xAxis2->setNumberFormat( xAxis->numberFormat() ); + xAxis2->setNumberPrecision( xAxis->numberPrecision() ); + xAxis2->ticker()->setTickCount( xAxis->ticker()->tickCount() ); + xAxis2->ticker()->setTickOrigin( xAxis->ticker()->tickOrigin() ); + + yAxis2->setRange( yAxis->range() ); + yAxis2->setRangeReversed( yAxis->rangeReversed() ); + yAxis2->setScaleType( yAxis->scaleType() ); + yAxis2->setTicks( yAxis->ticks() ); + yAxis2->setNumberFormat( yAxis->numberFormat() ); + yAxis2->setNumberPrecision( yAxis->numberPrecision() ); + yAxis2->ticker()->setTickCount( yAxis->ticker()->tickCount() ); + yAxis2->ticker()->setTickOrigin( yAxis->ticker()->tickOrigin() ); + + if( connectRanges ) { - connect(xAxis, SIGNAL(rangeChanged(QCPRange)), xAxis2, SLOT(setRange(QCPRange))); - connect(yAxis, SIGNAL(rangeChanged(QCPRange)), yAxis2, SLOT(setRange(QCPRange))); + connect( xAxis, SIGNAL( rangeChanged( QCPRange ) ), xAxis2, SLOT( setRange( QCPRange ) ) ); + connect( yAxis, SIGNAL( rangeChanged( QCPRange ) ), yAxis2, SLOT( setRange( QCPRange ) ) ); } } @@ -17179,10 +17326,10 @@ QList QCPAxisRect::plottables() const { // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries QList result; - for (int i=0; imPlottables.size(); ++i) + for( int i = 0; i < mParentPlot->mPlottables.size(); ++i ) { - if (mParentPlot->mPlottables.at(i)->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mPlottables.at(i)); + if( mParentPlot->mPlottables.at( i )->keyAxis()->axisRect() == this || mParentPlot->mPlottables.at( i )->valueAxis()->axisRect() == this ) + result.append( mParentPlot->mPlottables.at( i ) ); } return result; } @@ -17199,10 +17346,10 @@ QList QCPAxisRect::graphs() const { // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries QList result; - for (int i=0; imGraphs.size(); ++i) + for( int i = 0; i < mParentPlot->mGraphs.size(); ++i ) { - if (mParentPlot->mGraphs.at(i)->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at(i)->valueAxis()->axisRect() == this) - result.append(mParentPlot->mGraphs.at(i)); + if( mParentPlot->mGraphs.at( i )->keyAxis()->axisRect() == this || mParentPlot->mGraphs.at( i )->valueAxis()->axisRect() == this ) + result.append( mParentPlot->mGraphs.at( i ) ); } return result; } @@ -17217,26 +17364,26 @@ QList QCPAxisRect::graphs() const \see plottables, graphs */ -QList QCPAxisRect::items() const +QList QCPAxisRect::items() const { // Note: don't just append all QCPAxis::items() into a list, because we might get duplicate entries // and miss those items that have this axis rect as clipAxisRect. QList result; - for (int itemId=0; itemIdmItems.size(); ++itemId) + for( int itemId = 0; itemId < mParentPlot->mItems.size(); ++itemId ) { - if (mParentPlot->mItems.at(itemId)->clipAxisRect() == this) + if( mParentPlot->mItems.at( itemId )->clipAxisRect() == this ) { - result.append(mParentPlot->mItems.at(itemId)); + result.append( mParentPlot->mItems.at( itemId ) ); continue; } - QList positions = mParentPlot->mItems.at(itemId)->positions(); - for (int posId=0; posId positions = mParentPlot->mItems.at( itemId )->positions(); + for( int posId = 0; posId < positions.size(); ++posId ) { - if (positions.at(posId)->axisRect() == this || - positions.at(posId)->keyAxis()->axisRect() == this || - positions.at(posId)->valueAxis()->axisRect() == this) + if( positions.at( posId )->axisRect() == this || + positions.at( posId )->keyAxis()->axisRect() == this || + positions.at( posId )->valueAxis()->axisRect() == this ) { - result.append(mParentPlot->mItems.at(itemId)); + result.append( mParentPlot->mItems.at( itemId ) ); break; } } @@ -17254,54 +17401,53 @@ QList QCPAxisRect::items() const \seebaseclassmethod */ -void QCPAxisRect::update(UpdatePhase phase) +void QCPAxisRect::update( UpdatePhase phase ) { - QCPLayoutElement::update(phase); - - switch (phase) + QCPLayoutElement::update( phase ); + + switch( phase ) { - case upPreparation: - { - QList allAxes = axes(); - for (int i=0; isetupTickVectors(); - break; - } - case upLayout: - { - mInsetLayout->setOuterRect(rect()); - break; - } - default: break; + case upPreparation: { + QList allAxes = axes(); + for( int i = 0; i < allAxes.size(); ++i ) + allAxes.at( i )->setupTickVectors(); + break; } - + case upLayout: { + mInsetLayout->setOuterRect( rect() ); + break; + } + default: + break; + } + // pass update call on to inset layout (doesn't happen automatically, because QCPAxisRect doesn't derive from QCPLayout): - mInsetLayout->update(phase); + mInsetLayout->update( phase ); } /* inherits documentation from base class */ -QList QCPAxisRect::elements(bool recursive) const +QList QCPAxisRect::elements( bool recursive ) const { QList result; - if (mInsetLayout) + if( mInsetLayout ) { result << mInsetLayout; - if (recursive) - result << mInsetLayout->elements(recursive); + if( recursive ) + result << mInsetLayout->elements( recursive ); } return result; } /* inherits documentation from base class */ -void QCPAxisRect::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPAxisRect::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - painter->setAntialiasing(false); + painter->setAntialiasing( false ); } /* inherits documentation from base class */ -void QCPAxisRect::draw(QCPPainter *painter) +void QCPAxisRect::draw( QCPPainter* painter ) { - drawBackground(painter); + drawBackground( painter ); } /*! @@ -17319,7 +17465,7 @@ void QCPAxisRect::draw(QCPPainter *painter) \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) */ -void QCPAxisRect::setBackground(const QPixmap &pm) +void QCPAxisRect::setBackground( const QPixmap& pm ) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -17338,7 +17484,7 @@ void QCPAxisRect::setBackground(const QPixmap &pm) \see setBackground(const QPixmap &pm) */ -void QCPAxisRect::setBackground(const QBrush &brush) +void QCPAxisRect::setBackground( const QBrush& brush ) { mBackgroundBrush = brush; } @@ -17350,7 +17496,7 @@ void QCPAxisRect::setBackground(const QBrush &brush) \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode */ -void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) +void QCPAxisRect::setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatioMode mode ) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -17368,7 +17514,7 @@ void QCPAxisRect::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioM \see setBackground, setBackgroundScaledMode */ -void QCPAxisRect::setBackgroundScaled(bool scaled) +void QCPAxisRect::setBackgroundScaled( bool scaled ) { mBackgroundScaled = scaled; } @@ -17378,7 +17524,7 @@ void QCPAxisRect::setBackgroundScaled(bool scaled) define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. \see setBackground, setBackgroundScaled */ -void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) +void QCPAxisRect::setBackgroundScaledMode( Qt::AspectRatioMode mode ) { mBackgroundScaledMode = mode; } @@ -17389,9 +17535,9 @@ void QCPAxisRect::setBackgroundScaledMode(Qt::AspectRatioMode mode) \see setRangeDragAxes */ -QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) +QCPAxis* QCPAxisRect::rangeDragAxis( Qt::Orientation orientation ) { - if (orientation == Qt::Horizontal) + if( orientation == Qt::Horizontal ) return mRangeDragHorzAxis.isEmpty() ? 0 : mRangeDragHorzAxis.first().data(); else return mRangeDragVertAxis.isEmpty() ? 0 : mRangeDragVertAxis.first().data(); @@ -17403,9 +17549,9 @@ QCPAxis *QCPAxisRect::rangeDragAxis(Qt::Orientation orientation) \see setRangeZoomAxes */ -QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) +QCPAxis* QCPAxisRect::rangeZoomAxis( Qt::Orientation orientation ) { - if (orientation == Qt::Horizontal) + if( orientation == Qt::Horizontal ) return mRangeZoomHorzAxis.isEmpty() ? 0 : mRangeZoomHorzAxis.first().data(); else return mRangeZoomVertAxis.isEmpty() ? 0 : mRangeZoomVertAxis.first().data(); @@ -17416,22 +17562,23 @@ QCPAxis *QCPAxisRect::rangeZoomAxis(Qt::Orientation orientation) \see rangeZoomAxis, setRangeZoomAxes */ -QList QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) +QList QCPAxisRect::rangeDragAxes( Qt::Orientation orientation ) { QList result; - if (orientation == Qt::Horizontal) + if( orientation == Qt::Horizontal ) { - for (int i=0; i QCPAxisRect::rangeDragAxes(Qt::Orientation orientation) \see rangeDragAxis, setRangeDragAxes */ -QList QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) +QList QCPAxisRect::rangeZoomAxes( Qt::Orientation orientation ) { QList result; - if (orientation == Qt::Horizontal) + if( orientation == Qt::Horizontal ) { - for (int i=0; i QCPAxisRect::rangeZoomAxes(Qt::Orientation orientation) \see setRangeZoomFactor */ -double QCPAxisRect::rangeZoomFactor(Qt::Orientation orientation) +double QCPAxisRect::rangeZoomFactor( Qt::Orientation orientation ) { - return (orientation == Qt::Horizontal ? mRangeZoomFactorHorz : mRangeZoomFactorVert); + return ( orientation == Qt::Horizontal ? mRangeZoomFactorHorz : mRangeZoomFactorVert ); } /*! @@ -17489,7 +17637,7 @@ double QCPAxisRect::rangeZoomFactor(Qt::Orientation orientation) \see setRangeZoom, setRangeDragAxes, QCustomPlot::setNoAntialiasingOnDrag */ -void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) +void QCPAxisRect::setRangeDrag( Qt::Orientations orientations ) { mRangeDrag = orientations; } @@ -17509,7 +17657,7 @@ void QCPAxisRect::setRangeDrag(Qt::Orientations orientations) \see setRangeZoomFactor, setRangeZoomAxes, setRangeDrag */ -void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) +void QCPAxisRect::setRangeZoom( Qt::Orientations orientations ) { mRangeZoom = orientations; } @@ -17524,14 +17672,14 @@ void QCPAxisRect::setRangeZoom(Qt::Orientations orientations) \see setRangeZoomAxes */ -void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) +void QCPAxisRect::setRangeDragAxes( QCPAxis* horizontal, QCPAxis* vertical ) { QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeDragAxes(horz, vert); + if( horizontal ) + horz.append( horizontal ); + if( vertical ) + vert.append( vertical ); + setRangeDragAxes( horz, vert ); } /*! \overload @@ -17543,17 +17691,17 @@ void QCPAxisRect::setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical) In the unusual case that you wish to e.g. drag a vertically oriented axis with a horizontal drag motion, use the overload taking two separate lists for horizontal and vertical dragging. */ -void QCPAxisRect::setRangeDragAxes(QList axes) +void QCPAxisRect::setRangeDragAxes( QList axes ) { QList horz, vert; - foreach (QCPAxis *ax, axes) + foreach( QCPAxis* ax, axes ) { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); + if( ax->orientation() == Qt::Horizontal ) + horz.append( ax ); else - vert.append(ax); + vert.append( ax ); } - setRangeDragAxes(horz, vert); + setRangeDragAxes( horz, vert ); } /*! \overload @@ -17562,25 +17710,25 @@ void QCPAxisRect::setRangeDragAxes(QList axes) define specifically which axis reacts to which drag orientation (irrespective of the axis orientation). */ -void QCPAxisRect::setRangeDragAxes(QList horizontal, QList vertical) +void QCPAxisRect::setRangeDragAxes( QList horizontal, QList vertical ) { mRangeDragHorzAxis.clear(); - foreach (QCPAxis *ax, horizontal) + foreach( QCPAxis* ax, horizontal ) { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragHorzAxis.append(axPointer); + QPointer axPointer( ax ); + if( !axPointer.isNull() ) + mRangeDragHorzAxis.append( axPointer ); else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast( ax ); } mRangeDragVertAxis.clear(); - foreach (QCPAxis *ax, vertical) + foreach( QCPAxis* ax, vertical ) { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeDragVertAxis.append(axPointer); + QPointer axPointer( ax ); + if( !axPointer.isNull() ) + mRangeDragVertAxis.append( axPointer ); else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast( ax ); } } @@ -17596,14 +17744,14 @@ void QCPAxisRect::setRangeDragAxes(QList horizontal, QList v \see setRangeDragAxes */ -void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) +void QCPAxisRect::setRangeZoomAxes( QCPAxis* horizontal, QCPAxis* vertical ) { QList horz, vert; - if (horizontal) - horz.append(horizontal); - if (vertical) - vert.append(vertical); - setRangeZoomAxes(horz, vert); + if( horizontal ) + horz.append( horizontal ); + if( vertical ) + vert.append( vertical ); + setRangeZoomAxes( horz, vert ); } /*! \overload @@ -17615,17 +17763,17 @@ void QCPAxisRect::setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical) In the unusual case that you wish to e.g. zoom a vertically oriented axis with a horizontal zoom interaction, use the overload taking two separate lists for horizontal and vertical zooming. */ -void QCPAxisRect::setRangeZoomAxes(QList axes) +void QCPAxisRect::setRangeZoomAxes( QList axes ) { QList horz, vert; - foreach (QCPAxis *ax, axes) + foreach( QCPAxis* ax, axes ) { - if (ax->orientation() == Qt::Horizontal) - horz.append(ax); + if( ax->orientation() == Qt::Horizontal ) + horz.append( ax ); else - vert.append(ax); + vert.append( ax ); } - setRangeZoomAxes(horz, vert); + setRangeZoomAxes( horz, vert ); } /*! \overload @@ -17634,25 +17782,25 @@ void QCPAxisRect::setRangeZoomAxes(QList axes) define specifically which axis reacts to which zoom orientation (irrespective of the axis orientation). */ -void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList vertical) +void QCPAxisRect::setRangeZoomAxes( QList horizontal, QList vertical ) { mRangeZoomHorzAxis.clear(); - foreach (QCPAxis *ax, horizontal) + foreach( QCPAxis* ax, horizontal ) { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomHorzAxis.append(axPointer); + QPointer axPointer( ax ); + if( !axPointer.isNull() ) + mRangeZoomHorzAxis.append( axPointer ); else - qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast(ax); + qDebug() << Q_FUNC_INFO << "invalid axis passed in horizontal list:" << reinterpret_cast( ax ); } mRangeZoomVertAxis.clear(); - foreach (QCPAxis *ax, vertical) + foreach( QCPAxis* ax, vertical ) { - QPointer axPointer(ax); - if (!axPointer.isNull()) - mRangeZoomVertAxis.append(axPointer); + QPointer axPointer( ax ); + if( !axPointer.isNull() ) + mRangeZoomVertAxis.append( axPointer ); else - qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast(ax); + qDebug() << Q_FUNC_INFO << "invalid axis passed in vertical list:" << reinterpret_cast( ax ); } } @@ -17666,7 +17814,7 @@ void QCPAxisRect::setRangeZoomAxes(QList horizontal, QList v will zoom in (make the currently visible range smaller). For zoom factors smaller than one, the same scrolling direction will zoom out. */ -void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFactor) +void QCPAxisRect::setRangeZoomFactor( double horizontalFactor, double verticalFactor ) { mRangeZoomFactorHorz = horizontalFactor; mRangeZoomFactorVert = verticalFactor; @@ -17676,7 +17824,7 @@ void QCPAxisRect::setRangeZoomFactor(double horizontalFactor, double verticalFac Sets both the horizontal and vertical zoom \a factor. */ -void QCPAxisRect::setRangeZoomFactor(double factor) +void QCPAxisRect::setRangeZoomFactor( double factor ) { mRangeZoomFactorHorz = factor; mRangeZoomFactorVert = factor; @@ -17700,26 +17848,27 @@ void QCPAxisRect::setRangeZoomFactor(double factor) \see setBackground, setBackgroundScaled, setBackgroundScaledMode */ -void QCPAxisRect::drawBackground(QCPPainter *painter) +void QCPAxisRect::drawBackground( QCPPainter* painter ) { // draw background fill: - if (mBackgroundBrush != Qt::NoBrush) - painter->fillRect(mRect, mBackgroundBrush); - + if( mBackgroundBrush != Qt::NoBrush ) + painter->fillRect( mRect, mBackgroundBrush ); + // draw background pixmap (on top of fill, if brush specified): - if (!mBackgroundPixmap.isNull()) + if( !mBackgroundPixmap.isNull() ) { - if (mBackgroundScaled) + if( mBackgroundScaled ) { // check whether mScaledBackground needs to be updated: - QSize scaledSize(mBackgroundPixmap.size()); - scaledSize.scale(mRect.size(), mBackgroundScaledMode); - if (mScaledBackgroundPixmap.size() != scaledSize) - mScaledBackgroundPixmap = mBackgroundPixmap.scaled(mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation); - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mScaledBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height()) & mScaledBackgroundPixmap.rect()); - } else + QSize scaledSize( mBackgroundPixmap.size() ); + scaledSize.scale( mRect.size(), mBackgroundScaledMode ); + if( mScaledBackgroundPixmap.size() != scaledSize ) + mScaledBackgroundPixmap = mBackgroundPixmap.scaled( mRect.size(), mBackgroundScaledMode, Qt::SmoothTransformation ); + painter->drawPixmap( mRect.topLeft() + QPoint( 0, -1 ), mScaledBackgroundPixmap, QRect( 0, 0, mRect.width(), mRect.height() ) & mScaledBackgroundPixmap.rect() ); + } + else { - painter->drawPixmap(mRect.topLeft()+QPoint(0, -1), mBackgroundPixmap, QRect(0, 0, mRect.width(), mRect.height())); + painter->drawPixmap( mRect.topLeft() + QPoint( 0, -1 ), mBackgroundPixmap, QRect( 0, 0, mRect.width(), mRect.height() ) ); } } } @@ -17734,37 +17883,37 @@ void QCPAxisRect::drawBackground(QCPPainter *painter) This function is called by \ref calculateAutoMargin. */ -void QCPAxisRect::updateAxesOffset(QCPAxis::AxisType type) +void QCPAxisRect::updateAxesOffset( QCPAxis::AxisType type ) { - const QList axesList = mAxes.value(type); - if (axesList.isEmpty()) + const QList axesList = mAxes.value( type ); + if( axesList.isEmpty() ) return; - - bool isFirstVisible = !axesList.first()->visible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false - for (int i=1; ivisible(); // if the first axis is visible, the second axis (which is where the loop starts) isn't the first visible axis, so initialize with false + for( int i = 1; i < axesList.size(); ++i ) { - int offset = axesList.at(i-1)->offset() + axesList.at(i-1)->calculateMargin(); - if (axesList.at(i)->visible()) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) + int offset = axesList.at( i - 1 )->offset() + axesList.at( i - 1 )->calculateMargin(); + if( axesList.at( i )->visible() ) // only add inner tick length to offset if this axis is visible and it's not the first visible one (might happen if true first axis is invisible) { - if (!isFirstVisible) - offset += axesList.at(i)->tickLengthIn(); + if( !isFirstVisible ) + offset += axesList.at( i )->tickLengthIn(); isFirstVisible = false; } - axesList.at(i)->setOffset(offset); + axesList.at( i )->setOffset( offset ); } } /* inherits documentation from base class */ -int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) +int QCPAxisRect::calculateAutoMargin( QCP::MarginSide side ) { - if (!mAutoMargins.testFlag(side)) + if( !mAutoMargins.testFlag( side ) ) qDebug() << Q_FUNC_INFO << "Called with side that isn't specified as auto margin"; - - updateAxesOffset(QCPAxis::marginSideToAxisType(side)); - + + updateAxesOffset( QCPAxis::marginSideToAxisType( side ) ); + // note: only need to look at the last (outer most) axis to determine the total margin, due to updateAxisOffset call - const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); - if (axesList.size() > 0) + const QList axesList = mAxes.value( QCPAxis::marginSideToAxisType( side ) ); + if( axesList.size() > 0 ) return axesList.last()->offset() + axesList.last()->calculateMargin(); else return 0; @@ -17782,16 +17931,16 @@ int QCPAxisRect::calculateAutoMargin(QCP::MarginSide side) */ void QCPAxisRect::layoutChanged() { - if (mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect(0) == this) + if( mParentPlot && mParentPlot->axisRectCount() > 0 && mParentPlot->axisRect( 0 ) == this ) { - if (axisCount(QCPAxis::atBottom) > 0 && !mParentPlot->xAxis) - mParentPlot->xAxis = axis(QCPAxis::atBottom); - if (axisCount(QCPAxis::atLeft) > 0 && !mParentPlot->yAxis) - mParentPlot->yAxis = axis(QCPAxis::atLeft); - if (axisCount(QCPAxis::atTop) > 0 && !mParentPlot->xAxis2) - mParentPlot->xAxis2 = axis(QCPAxis::atTop); - if (axisCount(QCPAxis::atRight) > 0 && !mParentPlot->yAxis2) - mParentPlot->yAxis2 = axis(QCPAxis::atRight); + if( axisCount( QCPAxis::atBottom ) > 0 && !mParentPlot->xAxis ) + mParentPlot->xAxis = axis( QCPAxis::atBottom ); + if( axisCount( QCPAxis::atLeft ) > 0 && !mParentPlot->yAxis ) + mParentPlot->yAxis = axis( QCPAxis::atLeft ); + if( axisCount( QCPAxis::atTop ) > 0 && !mParentPlot->xAxis2 ) + mParentPlot->xAxis2 = axis( QCPAxis::atTop ); + if( axisCount( QCPAxis::atRight ) > 0 && !mParentPlot->yAxis2 ) + mParentPlot->yAxis2 = axis( QCPAxis::atRight ); } } @@ -17806,27 +17955,27 @@ void QCPAxisRect::layoutChanged() \see mouseMoveEvent, mouseReleaseEvent */ -void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) +void QCPAxisRect::mousePressEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) - if (event->buttons() & Qt::LeftButton) + Q_UNUSED( details ) + if( event->buttons() & Qt::LeftButton ) { mDragging = true; // initialize antialiasing backup in case we start dragging: - if (mParentPlot->noAntialiasingOnDrag()) + if( mParentPlot->noAntialiasingOnDrag() ) { mAADragBackup = mParentPlot->antialiasedElements(); mNotAADragBackup = mParentPlot->notAntialiasedElements(); } // Mouse range dragging interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + if( mParentPlot->interactions().testFlag( QCP::iRangeDrag ) ) { mDragStartHorzRange.clear(); - for (int i=0; irange()); + for( int i = 0; i < mRangeDragHorzAxis.size(); ++i ) + mDragStartHorzRange.append( mRangeDragHorzAxis.at( i ).isNull() ? QCPRange() : mRangeDragHorzAxis.at( i )->range() ); mDragStartVertRange.clear(); - for (int i=0; irange()); + for( int i = 0; i < mRangeDragVertAxis.size(); ++i ) + mDragStartVertRange.append( mRangeDragVertAxis.at( i ).isNull() ? QCPRange() : mRangeDragVertAxis.at( i )->range() ); } } } @@ -17838,75 +17987,75 @@ void QCPAxisRect::mousePressEvent(QMouseEvent *event, const QVariant &details) \see mousePressEvent, mouseReleaseEvent */ -void QCPAxisRect::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +void QCPAxisRect::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) { - Q_UNUSED(startPos) + Q_UNUSED( startPos ) // Mouse range dragging interaction: - if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) + if( mDragging && mParentPlot->interactions().testFlag( QCP::iRangeDrag ) ) { - - if (mRangeDrag.testFlag(Qt::Horizontal)) + if( mRangeDrag.testFlag( Qt::Horizontal ) ) { - for (int i=0; i= mDragStartHorzRange.size()) + if( i >= mDragStartHorzRange.size() ) break; - if (ax->mScaleType == QCPAxis::stLinear) + if( ax->mScaleType == QCPAxis::stLinear ) { - double diff = ax->pixelToCoord(startPos.x()) - ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower+diff, mDragStartHorzRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) + double diff = ax->pixelToCoord( startPos.x() ) - ax->pixelToCoord( event->pos().x() ); + ax->setRange( mDragStartHorzRange.at( i ).lower + diff, mDragStartHorzRange.at( i ).upper + diff ); + } + else if( ax->mScaleType == QCPAxis::stLogarithmic ) { - double diff = ax->pixelToCoord(startPos.x()) / ax->pixelToCoord(event->pos().x()); - ax->setRange(mDragStartHorzRange.at(i).lower*diff, mDragStartHorzRange.at(i).upper*diff); + double diff = ax->pixelToCoord( startPos.x() ) / ax->pixelToCoord( event->pos().x() ); + ax->setRange( mDragStartHorzRange.at( i ).lower * diff, mDragStartHorzRange.at( i ).upper * diff ); } } } - - if (mRangeDrag.testFlag(Qt::Vertical)) + + if( mRangeDrag.testFlag( Qt::Vertical ) ) { - for (int i=0; i= mDragStartVertRange.size()) + if( i >= mDragStartVertRange.size() ) break; - if (ax->mScaleType == QCPAxis::stLinear) + if( ax->mScaleType == QCPAxis::stLinear ) { - double diff = ax->pixelToCoord(startPos.y()) - ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower+diff, mDragStartVertRange.at(i).upper+diff); - } else if (ax->mScaleType == QCPAxis::stLogarithmic) + double diff = ax->pixelToCoord( startPos.y() ) - ax->pixelToCoord( event->pos().y() ); + ax->setRange( mDragStartVertRange.at( i ).lower + diff, mDragStartVertRange.at( i ).upper + diff ); + } + else if( ax->mScaleType == QCPAxis::stLogarithmic ) { - double diff = ax->pixelToCoord(startPos.y()) / ax->pixelToCoord(event->pos().y()); - ax->setRange(mDragStartVertRange.at(i).lower*diff, mDragStartVertRange.at(i).upper*diff); + double diff = ax->pixelToCoord( startPos.y() ) / ax->pixelToCoord( event->pos().y() ); + ax->setRange( mDragStartVertRange.at( i ).lower * diff, mDragStartVertRange.at( i ).upper * diff ); } } } - - if (mRangeDrag != 0) // if either vertical or horizontal drag was enabled, do a replot + + if( mRangeDrag != 0 ) // if either vertical or horizontal drag was enabled, do a replot { - if (mParentPlot->noAntialiasingOnDrag()) - mParentPlot->setNotAntialiasedElements(QCP::aeAll); - mParentPlot->replot(QCustomPlot::rpQueuedReplot); + if( mParentPlot->noAntialiasingOnDrag() ) + mParentPlot->setNotAntialiasedElements( QCP::aeAll ); + mParentPlot->replot( QCustomPlot::rpQueuedReplot ); } - } } /* inherits documentation from base class */ -void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +void QCPAxisRect::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) { - Q_UNUSED(event) - Q_UNUSED(startPos) + Q_UNUSED( event ) + Q_UNUSED( startPos ) mDragging = false; - if (mParentPlot->noAntialiasingOnDrag()) + if( mParentPlot->noAntialiasingOnDrag() ) { - mParentPlot->setAntialiasedElements(mAADragBackup); - mParentPlot->setNotAntialiasedElements(mNotAADragBackup); + mParentPlot->setAntialiasedElements( mAADragBackup ); + mParentPlot->setNotAntialiasedElements( mNotAADragBackup ); } } @@ -17924,31 +18073,31 @@ void QCPAxisRect::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) exponent of the range zoom factor. This takes care of the wheel direction automatically, by inverting the factor, when the wheel step is negative (f^-1 = 1/f). */ -void QCPAxisRect::wheelEvent(QWheelEvent *event) +void QCPAxisRect::wheelEvent( QWheelEvent* event ) { // Mouse range zooming interaction: - if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) + if( mParentPlot->interactions().testFlag( QCP::iRangeZoom ) ) { - if (mRangeZoom != 0) + if( mRangeZoom != 0 ) { double factor; - double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually - if (mRangeZoom.testFlag(Qt::Horizontal)) + double wheelSteps = event->delta() / 120.0; // a single step delta is +/-120 usually + if( mRangeZoom.testFlag( Qt::Horizontal ) ) { - factor = qPow(mRangeZoomFactorHorz, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomHorzAxis.at(i)->pixelToCoord(event->pos().x())); + if( !mRangeZoomHorzAxis.at( i ).isNull() ) + mRangeZoomHorzAxis.at( i )->scaleRange( factor, mRangeZoomHorzAxis.at( i )->pixelToCoord( event->pos().x() ) ); } } - if (mRangeZoom.testFlag(Qt::Vertical)) + if( mRangeZoom.testFlag( Qt::Vertical ) ) { - factor = qPow(mRangeZoomFactorVert, wheelSteps); - for (int i=0; iscaleRange(factor, mRangeZoomVertAxis.at(i)->pixelToCoord(event->pos().y())); + if( !mRangeZoomVertAxis.at( i ).isNull() ) + mRangeZoomVertAxis.at( i )->scaleRange( factor, mRangeZoomVertAxis.at( i )->pixelToCoord( event->pos().y() ) ); } } mParentPlot->replot(); @@ -17957,7 +18106,6 @@ void QCPAxisRect::wheelEvent(QWheelEvent *event) } /* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ - /* including file 'src/layoutelements/layoutelement-legend.cpp', size 31153 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -18003,18 +18151,11 @@ void QCPAxisRect::wheelEvent(QWheelEvent *event) Constructs a QCPAbstractLegendItem and associates it with the QCPLegend \a parent. This does not cause the item to be added to \a parent, so \ref QCPLegend::addItem must be called separately. */ -QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : - QCPLayoutElement(parent->parentPlot()), - mParentLegend(parent), - mFont(parent->font()), - mTextColor(parent->textColor()), - mSelectedFont(parent->selectedFont()), - mSelectedTextColor(parent->selectedTextColor()), - mSelectable(true), - mSelected(false) +QCPAbstractLegendItem::QCPAbstractLegendItem( QCPLegend* parent ) + : QCPLayoutElement( parent->parentPlot() ), mParentLegend( parent ), mFont( parent->font() ), mTextColor( parent->textColor() ), mSelectedFont( parent->selectedFont() ), mSelectedTextColor( parent->selectedTextColor() ), mSelectable( true ), mSelected( false ) { - setLayer(QLatin1String("legend")); - setMargins(QMargins(0, 0, 0, 0)); + setLayer( QLatin1String( "legend" ) ); + setMargins( QMargins( 0, 0, 0, 0 ) ); } /*! @@ -18022,7 +18163,7 @@ QCPAbstractLegendItem::QCPAbstractLegendItem(QCPLegend *parent) : \see setTextColor, QCPLegend::setFont */ -void QCPAbstractLegendItem::setFont(const QFont &font) +void QCPAbstractLegendItem::setFont( const QFont& font ) { mFont = font; } @@ -18032,7 +18173,7 @@ void QCPAbstractLegendItem::setFont(const QFont &font) \see setFont, QCPLegend::setTextColor */ -void QCPAbstractLegendItem::setTextColor(const QColor &color) +void QCPAbstractLegendItem::setTextColor( const QColor& color ) { mTextColor = color; } @@ -18043,7 +18184,7 @@ void QCPAbstractLegendItem::setTextColor(const QColor &color) \see setFont, QCPLegend::setSelectedFont */ -void QCPAbstractLegendItem::setSelectedFont(const QFont &font) +void QCPAbstractLegendItem::setSelectedFont( const QFont& font ) { mSelectedFont = font; } @@ -18054,7 +18195,7 @@ void QCPAbstractLegendItem::setSelectedFont(const QFont &font) \see setTextColor, QCPLegend::setSelectedTextColor */ -void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) +void QCPAbstractLegendItem::setSelectedTextColor( const QColor& color ) { mSelectedTextColor = color; } @@ -18064,12 +18205,12 @@ void QCPAbstractLegendItem::setSelectedTextColor(const QColor &color) \see setSelectedParts, QCustomPlot::setInteractions */ -void QCPAbstractLegendItem::setSelectable(bool selectable) +void QCPAbstractLegendItem::setSelectable( bool selectable ) { - if (mSelectable != selectable) + if( mSelectable != selectable ) { mSelectable = selectable; - emit selectableChanged(mSelectable); + emit selectableChanged( mSelectable ); } } @@ -18081,33 +18222,34 @@ void QCPAbstractLegendItem::setSelectable(bool selectable) \see setSelectableParts, QCustomPlot::setInteractions */ -void QCPAbstractLegendItem::setSelected(bool selected) +void QCPAbstractLegendItem::setSelected( bool selected ) { - if (mSelected != selected) + if( mSelected != selected ) { mSelected = selected; - emit selectionChanged(mSelected); + emit selectionChanged( mSelected ); } } /* inherits documentation from base class */ -double QCPAbstractLegendItem::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPAbstractLegendItem::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (!mParentPlot) return -1; - if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) + Q_UNUSED( details ) + if( !mParentPlot ) return -1; - - if (mRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; + if( onlySelectable && ( !mSelectable || !mParentLegend->selectableParts().testFlag( QCPLegend::spItems ) ) ) + return -1; + + if( mRect.contains( pos.toPoint() ) ) + return mParentPlot->selectionTolerance() * 0.99; else return -1; } /* inherits documentation from base class */ -void QCPAbstractLegendItem::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPAbstractLegendItem::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegendItems); + applyAntialiasingHint( painter, mAntialiased, QCP::aeLegendItems ); } /* inherits documentation from base class */ @@ -18117,27 +18259,27 @@ QRect QCPAbstractLegendItem::clipRect() const } /* inherits documentation from base class */ -void QCPAbstractLegendItem::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPAbstractLegendItem::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + Q_UNUSED( event ) + Q_UNUSED( details ) + if( mSelectable && mParentLegend->selectableParts().testFlag( QCPLegend::spItems ) ) { bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) + setSelected( additive ? !mSelected : true ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } /* inherits documentation from base class */ -void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) +void QCPAbstractLegendItem::deselectEvent( bool* selectionStateChanged ) { - if (mSelectable && mParentLegend->selectableParts().testFlag(QCPLegend::spItems)) + if( mSelectable && mParentLegend->selectableParts().testFlag( QCPLegend::spItems ) ) { bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) + setSelected( false ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } @@ -18177,11 +18319,10 @@ void QCPAbstractLegendItem::deselectEvent(bool *selectionStateChanged) A more convenient way of adding/removing a plottable to/from the legend is via the functions \ref QCPAbstractPlottable::addToLegend and \ref QCPAbstractPlottable::removeFromLegend. */ -QCPPlottableLegendItem::QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable) : - QCPAbstractLegendItem(parent), - mPlottable(plottable) +QCPPlottableLegendItem::QCPPlottableLegendItem( QCPLegend* parent, QCPAbstractPlottable* plottable ) + : QCPAbstractLegendItem( parent ), mPlottable( plottable ) { - setAntialiased(false); + setAntialiased( false ); } /*! \internal @@ -18220,29 +18361,30 @@ QFont QCPPlottableLegendItem::getFont() const parent layout (typically a \ref QCPLegend) and the \ref minimumOuterSizeHint and \ref maximumOuterSizeHint of this legend item. */ -void QCPPlottableLegendItem::draw(QCPPainter *painter) +void QCPPlottableLegendItem::draw( QCPPainter* painter ) { - if (!mPlottable) return; - painter->setFont(getFont()); - painter->setPen(QPen(getTextColor())); + if( !mPlottable ) + return; + painter->setFont( getFont() ); + painter->setPen( QPen( getTextColor() ) ); QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - QRectF iconRect(mRect.topLeft(), iconSize); - int textHeight = qMax(textRect.height(), iconSize.height()); // if text has smaller height than icon, center text vertically in icon height, else align tops - painter->drawText(mRect.x()+iconSize.width()+mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name()); + QRectF textRect = painter->fontMetrics().boundingRect( 0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name() ); + QRectF iconRect( mRect.topLeft(), iconSize ); + int textHeight = qMax( textRect.height(), iconSize.height() ); // if text has smaller height than icon, center text vertically in icon height, else align tops + painter->drawText( mRect.x() + iconSize.width() + mParentLegend->iconTextPadding(), mRect.y(), textRect.width(), textHeight, Qt::TextDontClip, mPlottable->name() ); // draw icon: painter->save(); - painter->setClipRect(iconRect, Qt::IntersectClip); - mPlottable->drawLegendIcon(painter, iconRect); + painter->setClipRect( iconRect, Qt::IntersectClip ); + mPlottable->drawLegendIcon( painter, iconRect ); painter->restore(); // draw icon border: - if (getIconBorderPen().style() != Qt::NoPen) + if( getIconBorderPen().style() != Qt::NoPen ) { - painter->setPen(getIconBorderPen()); - painter->setBrush(Qt::NoBrush); - int halfPen = qCeil(painter->pen().widthF()*0.5)+1; - painter->setClipRect(mOuterRect.adjusted(-halfPen, -halfPen, halfPen, halfPen)); // extend default clip rect so thicker pens (especially during selection) are not clipped - painter->drawRect(iconRect); + painter->setPen( getIconBorderPen() ); + painter->setBrush( Qt::NoBrush ); + int halfPen = qCeil( painter->pen().widthF() * 0.5 ) + 1; + painter->setClipRect( mOuterRect.adjusted( -halfPen, -halfPen, halfPen, halfPen ) ); // extend default clip rect so thicker pens (especially during selection) are not clipped + painter->drawRect( iconRect ); } } @@ -18255,20 +18397,20 @@ void QCPPlottableLegendItem::draw(QCPPainter *painter) */ QSize QCPPlottableLegendItem::minimumOuterSizeHint() const { - if (!mPlottable) return QSize(); - QSize result(0, 0); + if( !mPlottable ) + return QSize(); + QSize result( 0, 0 ); QRect textRect; - QFontMetrics fontMetrics(getFont()); + QFontMetrics fontMetrics( getFont() ); QSize iconSize = mParentLegend->iconSize(); - textRect = fontMetrics.boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); - result.setWidth(iconSize.width() + mParentLegend->iconTextPadding() + textRect.width()); - result.setHeight(qMax(textRect.height(), iconSize.height())); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); + textRect = fontMetrics.boundingRect( 0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name() ); + result.setWidth( iconSize.width() + mParentLegend->iconTextPadding() + textRect.width() ); + result.setHeight( qMax( textRect.height(), iconSize.height() ) ); + result.rwidth() += mMargins.left() + mMargins.right(); + result.rheight() += mMargins.top() + mMargins.bottom(); return result; } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLegend //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -18326,35 +18468,35 @@ QSize QCPPlottableLegendItem::minimumOuterSizeHint() const */ QCPLegend::QCPLegend() { - setFillOrder(QCPLayoutGrid::foRowsFirst); - setWrap(0); - - setRowSpacing(3); - setColumnSpacing(8); - setMargins(QMargins(7, 5, 7, 4)); - setAntialiased(false); - setIconSize(32, 18); - - setIconTextPadding(7); - - setSelectableParts(spLegendBox | spItems); - setSelectedParts(spNone); - - setBorderPen(QPen(Qt::black, 0)); - setSelectedBorderPen(QPen(Qt::blue, 2)); - setIconBorderPen(Qt::NoPen); - setSelectedIconBorderPen(QPen(Qt::blue, 2)); - setBrush(Qt::white); - setSelectedBrush(Qt::white); - setTextColor(Qt::black); - setSelectedTextColor(Qt::blue); + setFillOrder( QCPLayoutGrid::foRowsFirst ); + setWrap( 0 ); + + setRowSpacing( 3 ); + setColumnSpacing( 8 ); + setMargins( QMargins( 7, 5, 7, 4 ) ); + setAntialiased( false ); + setIconSize( 32, 18 ); + + setIconTextPadding( 7 ); + + setSelectableParts( spLegendBox | spItems ); + setSelectedParts( spNone ); + + setBorderPen( QPen( Qt::black, 0 ) ); + setSelectedBorderPen( QPen( Qt::blue, 2 ) ); + setIconBorderPen( Qt::NoPen ); + setSelectedIconBorderPen( QPen( Qt::blue, 2 ) ); + setBrush( Qt::white ); + setSelectedBrush( Qt::white ); + setTextColor( Qt::black ); + setSelectedTextColor( Qt::blue ); } QCPLegend::~QCPLegend() { clearItems(); - if (qobject_cast(mParentPlot)) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) - mParentPlot->legendRemoved(this); + if( qobject_cast( mParentPlot ) ) // make sure this isn't called from QObject dtor when QCustomPlot is already destructed (happens when the legend is not in any layout and thus QObject-child of QCustomPlot) + mParentPlot->legendRemoved( this ); } /* no doc for getter, see setSelectedParts */ @@ -18362,15 +18504,15 @@ QCPLegend::SelectableParts QCPLegend::selectedParts() const { // check whether any legend elements selected, if yes, add spItems to return value bool hasSelectedItems = false; - for (int i=0; iselected()) + if( item( i ) && item( i )->selected() ) { hasSelectedItems = true; break; } } - if (hasSelectedItems) + if( hasSelectedItems ) return mSelectedParts | spItems; else return mSelectedParts & ~spItems; @@ -18379,7 +18521,7 @@ QCPLegend::SelectableParts QCPLegend::selectedParts() const /*! Sets the pen, the border of the entire legend is drawn with. */ -void QCPLegend::setBorderPen(const QPen &pen) +void QCPLegend::setBorderPen( const QPen& pen ) { mBorderPen = pen; } @@ -18387,7 +18529,7 @@ void QCPLegend::setBorderPen(const QPen &pen) /*! Sets the brush of the legend background. */ -void QCPLegend::setBrush(const QBrush &brush) +void QCPLegend::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -18401,13 +18543,13 @@ void QCPLegend::setBrush(const QBrush &brush) \see QCPAbstractLegendItem::setFont */ -void QCPLegend::setFont(const QFont &font) +void QCPLegend::setFont( const QFont& font ) { mFont = font; - for (int i=0; isetFont(mFont); + if( item( i ) ) + item( i )->setFont( mFont ); } } @@ -18420,13 +18562,13 @@ void QCPLegend::setFont(const QFont &font) \see QCPAbstractLegendItem::setTextColor */ -void QCPLegend::setTextColor(const QColor &color) +void QCPLegend::setTextColor( const QColor& color ) { mTextColor = color; - for (int i=0; isetTextColor(color); + if( item( i ) ) + item( i )->setTextColor( color ); } } @@ -18434,17 +18576,17 @@ void QCPLegend::setTextColor(const QColor &color) Sets the size of legend icons. Legend items that draw an icon (e.g. a visual representation of the graph) will use this size by default. */ -void QCPLegend::setIconSize(const QSize &size) +void QCPLegend::setIconSize( const QSize& size ) { mIconSize = size; } /*! \overload */ -void QCPLegend::setIconSize(int width, int height) +void QCPLegend::setIconSize( int width, int height ) { - mIconSize.setWidth(width); - mIconSize.setHeight(height); + mIconSize.setWidth( width ); + mIconSize.setHeight( height ); } /*! @@ -18452,7 +18594,7 @@ void QCPLegend::setIconSize(int width, int height) Legend items that draw an icon (e.g. a visual representation of the graph) and text (e.g. the name of the graph) will use this space by default. */ -void QCPLegend::setIconTextPadding(int padding) +void QCPLegend::setIconTextPadding( int padding ) { mIconTextPadding = padding; } @@ -18463,7 +18605,7 @@ void QCPLegend::setIconTextPadding(int padding) If no border is wanted, set this to \a Qt::NoPen. */ -void QCPLegend::setIconBorderPen(const QPen &pen) +void QCPLegend::setIconBorderPen( const QPen& pen ) { mIconBorderPen = pen; } @@ -18478,12 +18620,12 @@ void QCPLegend::setIconBorderPen(const QPen &pen) \see SelectablePart, setSelectedParts */ -void QCPLegend::setSelectableParts(const SelectableParts &selectable) +void QCPLegend::setSelectableParts( const SelectableParts& selectable ) { - if (mSelectableParts != selectable) + if( mSelectableParts != selectable ) { mSelectableParts = selectable; - emit selectableChanged(mSelectableParts); + emit selectableChanged( mSelectableParts ); } } @@ -18508,28 +18650,28 @@ void QCPLegend::setSelectableParts(const SelectableParts &selectable) \see SelectablePart, setSelectableParts, selectTest, setSelectedBorderPen, setSelectedIconBorderPen, setSelectedBrush, setSelectedFont */ -void QCPLegend::setSelectedParts(const SelectableParts &selected) +void QCPLegend::setSelectedParts( const SelectableParts& selected ) { SelectableParts newSelected = selected; - mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed + mSelectedParts = this->selectedParts(); // update mSelectedParts in case item selection changed - if (mSelectedParts != newSelected) + if( mSelectedParts != newSelected ) { - if (!mSelectedParts.testFlag(spItems) && newSelected.testFlag(spItems)) // attempt to set spItems flag (can't do that) + if( !mSelectedParts.testFlag( spItems ) && newSelected.testFlag( spItems ) ) // attempt to set spItems flag (can't do that) { qDebug() << Q_FUNC_INFO << "spItems flag can not be set, it can only be unset with this function"; newSelected &= ~spItems; } - if (mSelectedParts.testFlag(spItems) && !newSelected.testFlag(spItems)) // spItems flag was unset, so clear item selection + if( mSelectedParts.testFlag( spItems ) && !newSelected.testFlag( spItems ) ) // spItems flag was unset, so clear item selection { - for (int i=0; isetSelected(false); + if( item( i ) ) + item( i )->setSelected( false ); } } mSelectedParts = newSelected; - emit selectionChanged(mSelectedParts); + emit selectionChanged( mSelectedParts ); } } @@ -18539,7 +18681,7 @@ void QCPLegend::setSelectedParts(const SelectableParts &selected) \see setSelectedParts, setSelectableParts, setSelectedBrush */ -void QCPLegend::setSelectedBorderPen(const QPen &pen) +void QCPLegend::setSelectedBorderPen( const QPen& pen ) { mSelectedBorderPen = pen; } @@ -18549,7 +18691,7 @@ void QCPLegend::setSelectedBorderPen(const QPen &pen) \see setSelectedParts, setSelectableParts, setSelectedFont */ -void QCPLegend::setSelectedIconBorderPen(const QPen &pen) +void QCPLegend::setSelectedIconBorderPen( const QPen& pen ) { mSelectedIconBorderPen = pen; } @@ -18560,7 +18702,7 @@ void QCPLegend::setSelectedIconBorderPen(const QPen &pen) \see setSelectedParts, setSelectableParts, setSelectedBorderPen */ -void QCPLegend::setSelectedBrush(const QBrush &brush) +void QCPLegend::setSelectedBrush( const QBrush& brush ) { mSelectedBrush = brush; } @@ -18572,13 +18714,13 @@ void QCPLegend::setSelectedBrush(const QBrush &brush) \see setFont, QCPAbstractLegendItem::setSelectedFont */ -void QCPLegend::setSelectedFont(const QFont &font) +void QCPLegend::setSelectedFont( const QFont& font ) { mSelectedFont = font; - for (int i=0; isetSelectedFont(font); + if( item( i ) ) + item( i )->setSelectedFont( font ); } } @@ -18589,13 +18731,13 @@ void QCPLegend::setSelectedFont(const QFont &font) \see setTextColor, QCPAbstractLegendItem::setSelectedTextColor */ -void QCPLegend::setSelectedTextColor(const QColor &color) +void QCPLegend::setSelectedTextColor( const QColor& color ) { mSelectedTextColor = color; - for (int i=0; isetSelectedTextColor(color); + if( item( i ) ) + item( i )->setSelectedTextColor( color ); } } @@ -18606,9 +18748,9 @@ void QCPLegend::setSelectedTextColor(const QColor &color) \see itemCount, addItem, itemWithPlottable */ -QCPAbstractLegendItem *QCPLegend::item(int index) const +QCPAbstractLegendItem* QCPLegend::item( int index ) const { - return qobject_cast(elementAt(index)); + return qobject_cast( elementAt( index ) ); } /*! @@ -18617,13 +18759,13 @@ QCPAbstractLegendItem *QCPLegend::item(int index) const \see hasItemWithPlottable */ -QCPPlottableLegendItem *QCPLegend::itemWithPlottable(const QCPAbstractPlottable *plottable) const +QCPPlottableLegendItem* QCPLegend::itemWithPlottable( const QCPAbstractPlottable* plottable ) const { - for (int i=0; i(item(i))) + if( QCPPlottableLegendItem* pli = qobject_cast( item( i ) ) ) { - if (pli->plottable() == plottable) + if( pli->plottable() == plottable ) return pli; } } @@ -18648,12 +18790,12 @@ int QCPLegend::itemCount() const \see hasItemWithPlottable */ -bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const +bool QCPLegend::hasItem( QCPAbstractLegendItem* item ) const { - for (int i=0; iitem(i)) - return true; + if( item == this->item( i ) ) + return true; } return false; } @@ -18664,9 +18806,9 @@ bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const \see itemWithPlottable */ -bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) const +bool QCPLegend::hasItemWithPlottable( const QCPAbstractPlottable* plottable ) const { - return itemWithPlottable(plottable); + return itemWithPlottable( plottable ); } /*! @@ -18679,9 +18821,9 @@ bool QCPLegend::hasItemWithPlottable(const QCPAbstractPlottable *plottable) cons \see removeItem, item, hasItem */ -bool QCPLegend::addItem(QCPAbstractLegendItem *item) +bool QCPLegend::addItem( QCPAbstractLegendItem* item ) { - return addElement(item); + return addElement( item ); } /*! \overload @@ -18697,15 +18839,16 @@ bool QCPLegend::addItem(QCPAbstractLegendItem *item) \see itemCount, clearItems */ -bool QCPLegend::removeItem(int index) +bool QCPLegend::removeItem( int index ) { - if (QCPAbstractLegendItem *ali = item(index)) + if( QCPAbstractLegendItem* ali = item( index ) ) { - bool success = remove(ali); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + bool success = remove( ali ); + if( success ) + setFillOrder( fillOrder(), true ); // gets rid of empty cell by reordering return success; - } else + } + else return false; } @@ -18721,11 +18864,11 @@ bool QCPLegend::removeItem(int index) \see clearItems */ -bool QCPLegend::removeItem(QCPAbstractLegendItem *item) +bool QCPLegend::removeItem( QCPAbstractLegendItem* item ) { - bool success = remove(item); - if (success) - setFillOrder(fillOrder(), true); // gets rid of empty cell by reordering + bool success = remove( item ); + if( success ) + setFillOrder( fillOrder(), true ); // gets rid of empty cell by reordering return success; } @@ -18734,8 +18877,8 @@ bool QCPLegend::removeItem(QCPAbstractLegendItem *item) */ void QCPLegend::clearItems() { - for (int i=itemCount()-1; i>=0; --i) - removeItem(i); + for( int i = itemCount() - 1; i >= 0; --i ) + removeItem( i ); } /*! @@ -18744,15 +18887,15 @@ void QCPLegend::clearItems() \see QCPAbstractLegendItem::setSelected, setSelectable */ -QList QCPLegend::selectedItems() const +QList QCPLegend::selectedItems() const { QList result; - for (int i=0; iselected()) - result.append(ali); + if( ali->selected() ) + result.append( ali ); } } return result; @@ -18773,9 +18916,9 @@ QList QCPLegend::selectedItems() const \see setAntialiased */ -void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPLegend::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeLegend); + applyAntialiasingHint( painter, mAntialiased, QCP::aeLegend ); } /*! \internal @@ -18785,7 +18928,7 @@ void QCPLegend::applyDefaultAntialiasingHint(QCPPainter *painter) const */ QPen QCPLegend::getBorderPen() const { - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; + return mSelectedParts.testFlag( spLegendBox ) ? mSelectedBorderPen : mBorderPen; } /*! \internal @@ -18795,7 +18938,7 @@ QPen QCPLegend::getBorderPen() const */ QBrush QCPLegend::getBrush() const { - return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; + return mSelectedParts.testFlag( spLegendBox ) ? mSelectedBrush : mBrush; } /*! \internal @@ -18803,52 +18946,54 @@ QBrush QCPLegend::getBrush() const Draws the legend box with the provided \a painter. The individual legend items are layerables themselves, thus are drawn independently. */ -void QCPLegend::draw(QCPPainter *painter) +void QCPLegend::draw( QCPPainter* painter ) { // draw background rect: - painter->setBrush(getBrush()); - painter->setPen(getBorderPen()); - painter->drawRect(mOuterRect); + painter->setBrush( getBrush() ); + painter->setPen( getBorderPen() ); + painter->drawRect( mOuterRect ); } /* inherits documentation from base class */ -double QCPLegend::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPLegend::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if (!mParentPlot) return -1; - if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) + if( !mParentPlot ) return -1; - - if (mOuterRect.contains(pos.toPoint())) + if( onlySelectable && !mSelectableParts.testFlag( spLegendBox ) ) + return -1; + + if( mOuterRect.contains( pos.toPoint() ) ) { - if (details) details->setValue(spLegendBox); - return mParentPlot->selectionTolerance()*0.99; + if( details ) + details->setValue( spLegendBox ); + return mParentPlot->selectionTolerance() * 0.99; } return -1; } /* inherits documentation from base class */ -void QCPLegend::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPLegend::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - mSelectedParts = selectedParts(); // in case item selection has changed - if (details.value() == spLegendBox && mSelectableParts.testFlag(spLegendBox)) + Q_UNUSED( event ) + mSelectedParts = selectedParts(); // in case item selection has changed + if( details.value() == spLegendBox && mSelectableParts.testFlag( spLegendBox ) ) { SelectableParts selBefore = mSelectedParts; - setSelectedParts(additive ? mSelectedParts^spLegendBox : mSelectedParts|spLegendBox); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) - if (selectionStateChanged) + setSelectedParts( additive ? mSelectedParts ^ spLegendBox : mSelectedParts | spLegendBox ); // no need to unset spItems in !additive case, because they will be deselected by QCustomPlot (they're normal QCPLayerables with own deselectEvent) + if( selectionStateChanged ) *selectionStateChanged = mSelectedParts != selBefore; } } /* inherits documentation from base class */ -void QCPLegend::deselectEvent(bool *selectionStateChanged) +void QCPLegend::deselectEvent( bool* selectionStateChanged ) { - mSelectedParts = selectedParts(); // in case item selection has changed - if (mSelectableParts.testFlag(spLegendBox)) + mSelectedParts = selectedParts(); // in case item selection has changed + if( mSelectableParts.testFlag( spLegendBox ) ) { SelectableParts selBefore = mSelectedParts; - setSelectedParts(selectedParts() & ~spLegendBox); - if (selectionStateChanged) + setSelectedParts( selectedParts() & ~spLegendBox ); + if( selectionStateChanged ) *selectionStateChanged = mSelectedParts != selBefore; } } @@ -18866,14 +19011,13 @@ QCP::Interaction QCPAbstractLegendItem::selectionCategory() const } /* inherits documentation from base class */ -void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) +void QCPLegend::parentPlotInitialized( QCustomPlot* parentPlot ) { - if (parentPlot && !parentPlot->legend) + if( parentPlot && !parentPlot->legend ) parentPlot->legend = this; } /* end of 'src/layoutelements/layoutelement-legend.cpp' */ - /* including file 'src/layoutelements/layoutelement-textelement.cpp', size 12761 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -18922,23 +19066,21 @@ void QCPLegend::parentPlotInitialized(QCustomPlot *parentPlot) Creates a new QCPTextElement instance and sets default values. The initial text is empty (\ref setText). */ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mText(), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) +QCPTextElement::QCPTextElement( QCustomPlot* parentPlot ) + : QCPLayoutElement( parentPlot ), mText(), mTextFlags( Qt::AlignCenter | Qt::TextWordWrap ), mFont( QFont( QLatin1String( "sans serif" ), 12 ) ), // will be taken from parentPlot if available, see below + mTextColor( Qt::black ) + , mSelectedFont( QFont( QLatin1String( "sans serif" ), 12 ) ) + , // will be taken from parentPlot if available, see below + mSelectedTextColor( Qt::blue ) + , mSelectable( false ) + , mSelected( false ) { - if (parentPlot) + if( parentPlot ) { mFont = parentPlot->font(); mSelectedFont = parentPlot->font(); } - setMargins(QMargins(2, 2, 2, 2)); + setMargins( QMargins( 2, 2, 2, 2 ) ); } /*! \overload @@ -18947,23 +19089,21 @@ QCPTextElement::QCPTextElement(QCustomPlot *parentPlot) : The initial text is set to \a text. */ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), 12)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) +QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text ) + : QCPLayoutElement( parentPlot ), mText( text ), mTextFlags( Qt::AlignCenter | Qt::TextWordWrap ), mFont( QFont( QLatin1String( "sans serif" ), 12 ) ), // will be taken from parentPlot if available, see below + mTextColor( Qt::black ) + , mSelectedFont( QFont( QLatin1String( "sans serif" ), 12 ) ) + , // will be taken from parentPlot if available, see below + mSelectedTextColor( Qt::blue ) + , mSelectable( false ) + , mSelected( false ) { - if (parentPlot) + if( parentPlot ) { mFont = parentPlot->font(); mSelectedFont = parentPlot->font(); } - setMargins(QMargins(2, 2, 2, 2)); + setMargins( QMargins( 2, 2, 2, 2 ) ); } /*! \overload @@ -18972,25 +19112,23 @@ QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text) : The initial text is set to \a text with \a pointSize. */ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mTextColor(Qt::black), - mSelectedFont(QFont(QLatin1String("sans serif"), pointSize)), // will be taken from parentPlot if available, see below - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) +QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, double pointSize ) + : QCPLayoutElement( parentPlot ), mText( text ), mTextFlags( Qt::AlignCenter | Qt::TextWordWrap ), mFont( QFont( QLatin1String( "sans serif" ), pointSize ) ), // will be taken from parentPlot if available, see below + mTextColor( Qt::black ) + , mSelectedFont( QFont( QLatin1String( "sans serif" ), pointSize ) ) + , // will be taken from parentPlot if available, see below + mSelectedTextColor( Qt::blue ) + , mSelectable( false ) + , mSelected( false ) { - if (parentPlot) + if( parentPlot ) { mFont = parentPlot->font(); - mFont.setPointSizeF(pointSize); + mFont.setPointSizeF( pointSize ); mSelectedFont = parentPlot->font(); - mSelectedFont.setPointSizeF(pointSize); + mSelectedFont.setPointSizeF( pointSize ); } - setMargins(QMargins(2, 2, 2, 2)); + setMargins( QMargins( 2, 2, 2, 2 ) ); } /*! \overload @@ -18999,18 +19137,10 @@ QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, dou The initial text is set to \a text with \a pointSize and the specified \a fontFamily. */ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(QFont(fontFamily, pointSize)), - mTextColor(Qt::black), - mSelectedFont(QFont(fontFamily, pointSize)), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) +QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, const QString& fontFamily, double pointSize ) + : QCPLayoutElement( parentPlot ), mText( text ), mTextFlags( Qt::AlignCenter | Qt::TextWordWrap ), mFont( QFont( fontFamily, pointSize ) ), mTextColor( Qt::black ), mSelectedFont( QFont( fontFamily, pointSize ) ), mSelectedTextColor( Qt::blue ), mSelectable( false ), mSelected( false ) { - setMargins(QMargins(2, 2, 2, 2)); + setMargins( QMargins( 2, 2, 2, 2 ) ); } /*! \overload @@ -19019,18 +19149,10 @@ QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, con The initial text is set to \a text with the specified \a font. */ -QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font) : - QCPLayoutElement(parentPlot), - mText(text), - mTextFlags(Qt::AlignCenter|Qt::TextWordWrap), - mFont(font), - mTextColor(Qt::black), - mSelectedFont(font), - mSelectedTextColor(Qt::blue), - mSelectable(false), - mSelected(false) +QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, const QFont& font ) + : QCPLayoutElement( parentPlot ), mText( text ), mTextFlags( Qt::AlignCenter | Qt::TextWordWrap ), mFont( font ), mTextColor( Qt::black ), mSelectedFont( font ), mSelectedTextColor( Qt::blue ), mSelectable( false ), mSelected( false ) { - setMargins(QMargins(2, 2, 2, 2)); + setMargins( QMargins( 2, 2, 2, 2 ) ); } /*! @@ -19038,7 +19160,7 @@ QCPTextElement::QCPTextElement(QCustomPlot *parentPlot, const QString &text, con \see setFont, setTextColor, setTextFlags */ -void QCPTextElement::setText(const QString &text) +void QCPTextElement::setText( const QString& text ) { mText = text; } @@ -19063,7 +19185,7 @@ void QCPTextElement::setText(const QString &text) - Qt::TextWordWrap - Qt::TextIncludeTrailingSpaces */ -void QCPTextElement::setTextFlags(int flags) +void QCPTextElement::setTextFlags( int flags ) { mTextFlags = flags; } @@ -19073,7 +19195,7 @@ void QCPTextElement::setTextFlags(int flags) \see setTextColor, setSelectedFont */ -void QCPTextElement::setFont(const QFont &font) +void QCPTextElement::setFont( const QFont& font ) { mFont = font; } @@ -19083,7 +19205,7 @@ void QCPTextElement::setFont(const QFont &font) \see setFont, setSelectedTextColor */ -void QCPTextElement::setTextColor(const QColor &color) +void QCPTextElement::setTextColor( const QColor& color ) { mTextColor = color; } @@ -19093,7 +19215,7 @@ void QCPTextElement::setTextColor(const QColor &color) \see setFont */ -void QCPTextElement::setSelectedFont(const QFont &font) +void QCPTextElement::setSelectedFont( const QFont& font ) { mSelectedFont = font; } @@ -19103,7 +19225,7 @@ void QCPTextElement::setSelectedFont(const QFont &font) \see setTextColor */ -void QCPTextElement::setSelectedTextColor(const QColor &color) +void QCPTextElement::setSelectedTextColor( const QColor& color ) { mSelectedTextColor = color; } @@ -19114,12 +19236,12 @@ void QCPTextElement::setSelectedTextColor(const QColor &color) Note that even when \a selectable is set to false, the selection state may be changed programmatically via \ref setSelected. */ -void QCPTextElement::setSelectable(bool selectable) +void QCPTextElement::setSelectable( bool selectable ) { - if (mSelectable != selectable) + if( mSelectable != selectable ) { mSelectable = selectable; - emit selectableChanged(mSelectable); + emit selectableChanged( mSelectable ); } } @@ -19130,71 +19252,71 @@ void QCPTextElement::setSelectable(bool selectable) Note that this function can change the selection state independently of the current \ref setSelectable state. */ -void QCPTextElement::setSelected(bool selected) +void QCPTextElement::setSelected( bool selected ) { - if (mSelected != selected) + if( mSelected != selected ) { mSelected = selected; - emit selectionChanged(mSelected); + emit selectionChanged( mSelected ); } } /* inherits documentation from base class */ -void QCPTextElement::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPTextElement::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - applyAntialiasingHint(painter, mAntialiased, QCP::aeOther); + applyAntialiasingHint( painter, mAntialiased, QCP::aeOther ); } /* inherits documentation from base class */ -void QCPTextElement::draw(QCPPainter *painter) +void QCPTextElement::draw( QCPPainter* painter ) { - painter->setFont(mainFont()); - painter->setPen(QPen(mainTextColor())); - painter->drawText(mRect, Qt::AlignCenter, mText, &mTextBoundingRect); + painter->setFont( mainFont() ); + painter->setPen( QPen( mainTextColor() ) ); + painter->drawText( mRect, Qt::AlignCenter, mText, &mTextBoundingRect ); } /* inherits documentation from base class */ QSize QCPTextElement::minimumOuterSizeHint() const { - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.rwidth() += mMargins.left()+mMargins.right(); - result.rheight() += mMargins.top()+mMargins.bottom(); + QFontMetrics metrics( mFont ); + QSize result( metrics.boundingRect( 0, 0, 0, 0, Qt::AlignCenter, mText ).size() ); + result.rwidth() += mMargins.left() + mMargins.right(); + result.rheight() += mMargins.top() + mMargins.bottom(); return result; } /* inherits documentation from base class */ QSize QCPTextElement::maximumOuterSizeHint() const { - QFontMetrics metrics(mFont); - QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::AlignCenter, mText).size()); - result.setWidth(QWIDGETSIZE_MAX); - result.rheight() += mMargins.top()+mMargins.bottom(); + QFontMetrics metrics( mFont ); + QSize result( metrics.boundingRect( 0, 0, 0, 0, Qt::AlignCenter, mText ).size() ); + result.setWidth( QWIDGETSIZE_MAX ); + result.rheight() += mMargins.top() + mMargins.bottom(); return result; } /* inherits documentation from base class */ -void QCPTextElement::selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) +void QCPTextElement::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) { - Q_UNUSED(event) - Q_UNUSED(details) - if (mSelectable) + Q_UNUSED( event ) + Q_UNUSED( details ) + if( mSelectable ) { bool selBefore = mSelected; - setSelected(additive ? !mSelected : true); - if (selectionStateChanged) + setSelected( additive ? !mSelected : true ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } /* inherits documentation from base class */ -void QCPTextElement::deselectEvent(bool *selectionStateChanged) +void QCPTextElement::deselectEvent( bool* selectionStateChanged ) { - if (mSelectable) + if( mSelectable ) { bool selBefore = mSelected; - setSelected(false); - if (selectionStateChanged) + setSelected( false ); + if( selectionStateChanged ) *selectionStateChanged = mSelected != selBefore; } } @@ -19209,14 +19331,14 @@ void QCPTextElement::deselectEvent(bool *selectionStateChanged) \seebaseclassmethod */ -double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPTextElement::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - if (mTextBoundingRect.contains(pos.toPoint())) - return mParentPlot->selectionTolerance()*0.99; + + if( mTextBoundingRect.contains( pos.toPoint() ) ) + return mParentPlot->selectionTolerance() * 0.99; else return -1; } @@ -19227,9 +19349,9 @@ double QCPTextElement::selectTest(const QPointF &pos, bool onlySelectable, QVari \seebaseclassmethod */ -void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details) +void QCPTextElement::mousePressEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) + Q_UNUSED( details ) event->accept(); } @@ -19239,10 +19361,10 @@ void QCPTextElement::mousePressEvent(QMouseEvent *event, const QVariant &details \seebaseclassmethod */ -void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +void QCPTextElement::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) { - if ((QPointF(event->pos())-startPos).manhattanLength() <= 3) - emit clicked(event); + if( ( QPointF( event->pos() ) - startPos ).manhattanLength() <= 3 ) + emit clicked( event ); } /*! @@ -19250,10 +19372,10 @@ void QCPTextElement::mouseReleaseEvent(QMouseEvent *event, const QPointF &startP \seebaseclassmethod */ -void QCPTextElement::mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) +void QCPTextElement::mouseDoubleClickEvent( QMouseEvent* event, const QVariant& details ) { - Q_UNUSED(details) - emit doubleClicked(event); + Q_UNUSED( details ) + emit doubleClicked( event ); } /*! \internal @@ -19277,11 +19399,9 @@ QColor QCPTextElement::mainTextColor() const } /* end of 'src/layoutelements/layoutelement-textelement.cpp' */ - /* including file 'src/layoutelements/layoutelement-colorscale.cpp', size 26246 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorScale //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -19368,16 +19488,15 @@ QColor QCPTextElement::mainTextColor() const /*! Constructs a new QCPColorScale. */ -QCPColorScale::QCPColorScale(QCustomPlot *parentPlot) : - QCPLayoutElement(parentPlot), - mType(QCPAxis::atTop), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight - mDataScaleType(QCPAxis::stLinear), - mBarWidth(20), - mAxisRect(new QCPColorScaleAxisRectPrivate(this)) +QCPColorScale::QCPColorScale( QCustomPlot* parentPlot ) + : QCPLayoutElement( parentPlot ), mType( QCPAxis::atTop ), // set to atTop such that setType(QCPAxis::atRight) below doesn't skip work because it thinks it's already atRight + mDataScaleType( QCPAxis::stLinear ) + , mBarWidth( 20 ) + , mAxisRect( new QCPColorScaleAxisRectPrivate( this ) ) { - setMinimumMargins(QMargins(0, 6, 0, 6)); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) - setType(QCPAxis::atRight); - setDataRange(QCPRange(0, 6)); + setMinimumMargins( QMargins( 0, 6, 0, 6 ) ); // for default right color scale types, keep some room at bottom and top (important if no margin group is used) + setType( QCPAxis::atRight ); + setDataRange( QCPRange( 0, 6 ) ); } QCPColorScale::~QCPColorScale() @@ -19388,41 +19507,41 @@ QCPColorScale::~QCPColorScale() /* undocumented getter */ QString QCPColorScale::label() const { - if (!mColorAxis) + if( !mColorAxis ) { qDebug() << Q_FUNC_INFO << "internal color axis undefined"; return QString(); } - + return mColorAxis.data()->label(); } /* undocumented getter */ bool QCPColorScale::rangeDrag() const { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return false; } - - return mAxisRect.data()->rangeDrag().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeDragAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); + + return mAxisRect.data()->rangeDrag().testFlag( QCPAxis::orientation( mType ) ) && + mAxisRect.data()->rangeDragAxis( QCPAxis::orientation( mType ) ) && + mAxisRect.data()->rangeDragAxis( QCPAxis::orientation( mType ) )->orientation() == QCPAxis::orientation( mType ); } /* undocumented getter */ bool QCPColorScale::rangeZoom() const { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return false; } - - return mAxisRect.data()->rangeZoom().testFlag(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType)) && - mAxisRect.data()->rangeZoomAxis(QCPAxis::orientation(mType))->orientation() == QCPAxis::orientation(mType); + + return mAxisRect.data()->rangeZoom().testFlag( QCPAxis::orientation( mType ) ) && + mAxisRect.data()->rangeZoomAxis( QCPAxis::orientation( mType ) ) && + mAxisRect.data()->rangeZoomAxis( QCPAxis::orientation( mType ) )->orientation() == QCPAxis::orientation( mType ); } /*! @@ -19432,48 +19551,48 @@ bool QCPColorScale::rangeZoom() const be a different one. The new axis will adopt the following properties from the previous axis: The range, scale type, label and ticker (the latter will be shared and not copied). */ -void QCPColorScale::setType(QCPAxis::AxisType type) +void QCPColorScale::setType( QCPAxis::AxisType type ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - if (mType != type) + if( mType != type ) { mType = type; - QCPRange rangeTransfer(0, 6); + QCPRange rangeTransfer( 0, 6 ); QString labelTransfer; QSharedPointer tickerTransfer; // transfer/revert some settings on old axis if it exists: bool doTransfer = (bool)mColorAxis; - if (doTransfer) + if( doTransfer ) { rangeTransfer = mColorAxis.data()->range(); labelTransfer = mColorAxis.data()->label(); tickerTransfer = mColorAxis.data()->ticker(); - mColorAxis.data()->setLabel(QString()); - disconnect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + mColorAxis.data()->setLabel( QString() ); + disconnect( mColorAxis.data(), SIGNAL( rangeChanged( QCPRange ) ), this, SLOT( setDataRange( QCPRange ) ) ); + disconnect( mColorAxis.data(), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), this, SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); } QList allAxisTypes = QList() << QCPAxis::atLeft << QCPAxis::atRight << QCPAxis::atBottom << QCPAxis::atTop; - foreach (QCPAxis::AxisType atype, allAxisTypes) + foreach( QCPAxis::AxisType atype, allAxisTypes ) { - mAxisRect.data()->axis(atype)->setTicks(atype == mType); - mAxisRect.data()->axis(atype)->setTickLabels(atype== mType); + mAxisRect.data()->axis( atype )->setTicks( atype == mType ); + mAxisRect.data()->axis( atype )->setTickLabels( atype == mType ); } // set new mColorAxis pointer: - mColorAxis = mAxisRect.data()->axis(mType); + mColorAxis = mAxisRect.data()->axis( mType ); // transfer settings to new axis: - if (doTransfer) + if( doTransfer ) { - mColorAxis.data()->setRange(rangeTransfer); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) - mColorAxis.data()->setLabel(labelTransfer); - mColorAxis.data()->setTicker(tickerTransfer); + mColorAxis.data()->setRange( rangeTransfer ); // range transfer necessary if axis changes from vertical to horizontal or vice versa (axes with same orientation are synchronized via signals) + mColorAxis.data()->setLabel( labelTransfer ); + mColorAxis.data()->setTicker( tickerTransfer ); } - connect(mColorAxis.data(), SIGNAL(rangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorAxis.data(), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); - mAxisRect.data()->setRangeDragAxes(QList() << mColorAxis.data()); + connect( mColorAxis.data(), SIGNAL( rangeChanged( QCPRange ) ), this, SLOT( setDataRange( QCPRange ) ) ); + connect( mColorAxis.data(), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), this, SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); + mAxisRect.data()->setRangeDragAxes( QList() << mColorAxis.data() ); } } @@ -19486,14 +19605,14 @@ void QCPColorScale::setType(QCPAxis::AxisType type) \see setDataScaleType, setGradient, rescaleDataRange */ -void QCPColorScale::setDataRange(const QCPRange &dataRange) +void QCPColorScale::setDataRange( const QCPRange& dataRange ) { - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + if( mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper ) { mDataRange = dataRange; - if (mColorAxis) - mColorAxis.data()->setRange(mDataRange); - emit dataRangeChanged(mDataRange); + if( mColorAxis ) + mColorAxis.data()->setRange( mDataRange ); + emit dataRangeChanged( mDataRange ); } } @@ -19516,16 +19635,16 @@ void QCPColorScale::setDataRange(const QCPRange &dataRange) \see setDataRange, setGradient */ -void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) +void QCPColorScale::setDataScaleType( QCPAxis::ScaleType scaleType ) { - if (mDataScaleType != scaleType) + if( mDataScaleType != scaleType ) { mDataScaleType = scaleType; - if (mColorAxis) - mColorAxis.data()->setScaleType(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); - emit dataScaleTypeChanged(mDataScaleType); + if( mColorAxis ) + mColorAxis.data()->setScaleType( mDataScaleType ); + if( mDataScaleType == QCPAxis::stLogarithmic ) + setDataRange( mDataRange.sanitizedForLogScale() ); + emit dataScaleTypeChanged( mDataScaleType ); } } @@ -19536,14 +19655,14 @@ void QCPColorScale::setDataScaleType(QCPAxis::ScaleType scaleType) \see setDataRange, setDataScaleType */ -void QCPColorScale::setGradient(const QCPColorGradient &gradient) +void QCPColorScale::setGradient( const QCPColorGradient& gradient ) { - if (mGradient != gradient) + if( mGradient != gradient ) { mGradient = gradient; - if (mAxisRect) + if( mAxisRect ) mAxisRect.data()->mGradientImageInvalidated = true; - emit gradientChanged(mGradient); + emit gradientChanged( mGradient ); } } @@ -19551,22 +19670,22 @@ void QCPColorScale::setGradient(const QCPColorGradient &gradient) Sets the axis label of the color scale. This is equivalent to calling \ref QCPAxis::setLabel on the internal \ref axis. */ -void QCPColorScale::setLabel(const QString &str) +void QCPColorScale::setLabel( const QString& str ) { - if (!mColorAxis) + if( !mColorAxis ) { qDebug() << Q_FUNC_INFO << "internal color axis undefined"; return; } - - mColorAxis.data()->setLabel(str); + + mColorAxis.data()->setLabel( str ); } /*! Sets the width (or height, for horizontal color scales) the bar where the gradient is displayed will have. */ -void QCPColorScale::setBarWidth(int width) +void QCPColorScale::setBarWidth( int width ) { mBarWidth = width; } @@ -19577,18 +19696,18 @@ void QCPColorScale::setBarWidth(int width) Note that \ref QCP::iRangeDrag must be in the QCustomPlot's interactions (\ref QCustomPlot::setInteractions) to allow range dragging. */ -void QCPColorScale::setRangeDrag(bool enabled) +void QCPColorScale::setRangeDrag( bool enabled ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - - if (enabled) - mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + + if( enabled ) + mAxisRect.data()->setRangeDrag( QCPAxis::orientation( mType ) ); else - mAxisRect.data()->setRangeDrag(0); + mAxisRect.data()->setRangeDrag( 0 ); } /*! @@ -19597,18 +19716,18 @@ void QCPColorScale::setRangeDrag(bool enabled) Note that \ref QCP::iRangeZoom must be in the QCustomPlot's interactions (\ref QCustomPlot::setInteractions) to allow range dragging. */ -void QCPColorScale::setRangeZoom(bool enabled) +void QCPColorScale::setRangeZoom( bool enabled ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - - if (enabled) - mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + + if( enabled ) + mAxisRect.data()->setRangeZoom( QCPAxis::orientation( mType ) ); else - mAxisRect.data()->setRangeZoom(0); + mAxisRect.data()->setRangeZoom( 0 ); } /*! @@ -19617,11 +19736,11 @@ void QCPColorScale::setRangeZoom(bool enabled) QList QCPColorScale::colorMaps() const { QList result; - for (int i=0; iplottableCount(); ++i) + for( int i = 0; i < mParentPlot->plottableCount(); ++i ) { - if (QCPColorMap *cm = qobject_cast(mParentPlot->plottable(i))) - if (cm->colorScale() == this) - result.append(cm); + if( QCPColorMap* cm = qobject_cast( mParentPlot->plottable( i ) ) ) + if( cm->colorScale() == this ) + result.append( cm ); } return result; } @@ -19632,149 +19751,151 @@ QList QCPColorScale::colorMaps() const \see setDataRange */ -void QCPColorScale::rescaleDataRange(bool onlyVisibleMaps) +void QCPColorScale::rescaleDataRange( bool onlyVisibleMaps ) { QList maps = colorMaps(); QCPRange newRange; bool haveRange = false; QCP::SignDomain sign = QCP::sdBoth; - if (mDataScaleType == QCPAxis::stLogarithmic) - sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); - for (int i=0; irealVisibility() && onlyVisibleMaps) + if( !maps.at( i )->realVisibility() && onlyVisibleMaps ) continue; QCPRange mapRange; - if (maps.at(i)->colorScale() == this) + if( maps.at( i )->colorScale() == this ) { bool currentFoundRange = true; - mapRange = maps.at(i)->data()->dataBounds(); - if (sign == QCP::sdPositive) + mapRange = maps.at( i )->data()->dataBounds(); + if( sign == QCP::sdPositive ) { - if (mapRange.lower <= 0 && mapRange.upper > 0) - mapRange.lower = mapRange.upper*1e-3; - else if (mapRange.lower <= 0 && mapRange.upper <= 0) - currentFoundRange = false; - } else if (sign == QCP::sdNegative) - { - if (mapRange.upper >= 0 && mapRange.lower < 0) - mapRange.upper = mapRange.lower*1e-3; - else if (mapRange.upper >= 0 && mapRange.lower >= 0) + if( mapRange.lower <= 0 && mapRange.upper > 0 ) + mapRange.lower = mapRange.upper * 1e-3; + else if( mapRange.lower <= 0 && mapRange.upper <= 0 ) currentFoundRange = false; } - if (currentFoundRange) + else if( sign == QCP::sdNegative ) { - if (!haveRange) + if( mapRange.upper >= 0 && mapRange.lower < 0 ) + mapRange.upper = mapRange.lower * 1e-3; + else if( mapRange.upper >= 0 && mapRange.lower >= 0 ) + currentFoundRange = false; + } + if( currentFoundRange ) + { + if( !haveRange ) newRange = mapRange; else - newRange.expand(mapRange); + newRange.expand( mapRange ); haveRange = true; } } } - if (haveRange) + if( haveRange ) { - if (!QCPRange::validRange(newRange)) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data + if( !QCPRange::validRange( newRange ) ) // likely due to range being zero (plottable has only constant data in this dimension), shift current range to at least center the data { - double center = (newRange.lower+newRange.upper)*0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason - if (mDataScaleType == QCPAxis::stLinear) + double center = ( newRange.lower + newRange.upper ) * 0.5; // upper and lower should be equal anyway, but just to make sure, incase validRange returned false for other reason + if( mDataScaleType == QCPAxis::stLinear ) { - newRange.lower = center-mDataRange.size()/2.0; - newRange.upper = center+mDataRange.size()/2.0; - } else // mScaleType == stLogarithmic + newRange.lower = center - mDataRange.size() / 2.0; + newRange.upper = center + mDataRange.size() / 2.0; + } + else // mScaleType == stLogarithmic { - newRange.lower = center/qSqrt(mDataRange.upper/mDataRange.lower); - newRange.upper = center*qSqrt(mDataRange.upper/mDataRange.lower); + newRange.lower = center / qSqrt( mDataRange.upper / mDataRange.lower ); + newRange.upper = center * qSqrt( mDataRange.upper / mDataRange.lower ); } } - setDataRange(newRange); + setDataRange( newRange ); } } /* inherits documentation from base class */ -void QCPColorScale::update(UpdatePhase phase) +void QCPColorScale::update( UpdatePhase phase ) { - QCPLayoutElement::update(phase); - if (!mAxisRect) + QCPLayoutElement::update( phase ); + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - - mAxisRect.data()->update(phase); - - switch (phase) + + mAxisRect.data()->update( phase ); + + switch( phase ) { - case upMargins: + case upMargins: { + if( mType == QCPAxis::atBottom || mType == QCPAxis::atTop ) { - if (mType == QCPAxis::atBottom || mType == QCPAxis::atTop) - { - setMaximumSize(QWIDGETSIZE_MAX, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - setMinimumSize(0, mBarWidth+mAxisRect.data()->margins().top()+mAxisRect.data()->margins().bottom()); - } else - { - setMaximumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX); - setMinimumSize(mBarWidth+mAxisRect.data()->margins().left()+mAxisRect.data()->margins().right(), 0); - } - break; + setMaximumSize( QWIDGETSIZE_MAX, mBarWidth + mAxisRect.data()->margins().top() + mAxisRect.data()->margins().bottom() ); + setMinimumSize( 0, mBarWidth + mAxisRect.data()->margins().top() + mAxisRect.data()->margins().bottom() ); } - case upLayout: + else { - mAxisRect.data()->setOuterRect(rect()); - break; + setMaximumSize( mBarWidth + mAxisRect.data()->margins().left() + mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX ); + setMinimumSize( mBarWidth + mAxisRect.data()->margins().left() + mAxisRect.data()->margins().right(), 0 ); } - default: break; + break; + } + case upLayout: { + mAxisRect.data()->setOuterRect( rect() ); + break; + } + default: + break; } } /* inherits documentation from base class */ -void QCPColorScale::applyDefaultAntialiasingHint(QCPPainter *painter) const +void QCPColorScale::applyDefaultAntialiasingHint( QCPPainter* painter ) const { - painter->setAntialiasing(false); + painter->setAntialiasing( false ); } /* inherits documentation from base class */ -void QCPColorScale::mousePressEvent(QMouseEvent *event, const QVariant &details) +void QCPColorScale::mousePressEvent( QMouseEvent* event, const QVariant& details ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - mAxisRect.data()->mousePressEvent(event, details); + mAxisRect.data()->mousePressEvent( event, details ); } /* inherits documentation from base class */ -void QCPColorScale::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) +void QCPColorScale::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - mAxisRect.data()->mouseMoveEvent(event, startPos); + mAxisRect.data()->mouseMoveEvent( event, startPos ); } /* inherits documentation from base class */ -void QCPColorScale::mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) +void QCPColorScale::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - mAxisRect.data()->mouseReleaseEvent(event, startPos); + mAxisRect.data()->mouseReleaseEvent( event, startPos ); } /* inherits documentation from base class */ -void QCPColorScale::wheelEvent(QWheelEvent *event) +void QCPColorScale::wheelEvent( QWheelEvent* event ) { - if (!mAxisRect) + if( !mAxisRect ) { qDebug() << Q_FUNC_INFO << "internal axis rect was deleted"; return; } - mAxisRect.data()->wheelEvent(event); + mAxisRect.data()->wheelEvent( event ); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -19791,41 +19912,38 @@ void QCPColorScale::wheelEvent(QWheelEvent *event) It provides the axis rect functionality for the QCPColorScale class. */ - /*! Creates a new instance, as a child of \a parentColorScale. */ -QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale) : - QCPAxisRect(parentColorScale->parentPlot(), true), - mParentColorScale(parentColorScale), - mGradientImageInvalidated(true) +QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate( QCPColorScale* parentColorScale ) + : QCPAxisRect( parentColorScale->parentPlot(), true ), mParentColorScale( parentColorScale ), mGradientImageInvalidated( true ) { - setParentLayerable(parentColorScale); - setMinimumMargins(QMargins(0, 0, 0, 0)); + setParentLayerable( parentColorScale ); + setMinimumMargins( QMargins( 0, 0, 0, 0 ) ); QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) + foreach( QCPAxis::AxisType type, allAxisTypes ) { - axis(type)->setVisible(true); - axis(type)->grid()->setVisible(false); - axis(type)->setPadding(0); - connect(axis(type), SIGNAL(selectionChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectionChanged(QCPAxis::SelectableParts))); - connect(axis(type), SIGNAL(selectableChanged(QCPAxis::SelectableParts)), this, SLOT(axisSelectableChanged(QCPAxis::SelectableParts))); + axis( type )->setVisible( true ); + axis( type )->grid()->setVisible( false ); + axis( type )->setPadding( 0 ); + connect( axis( type ), SIGNAL( selectionChanged( QCPAxis::SelectableParts ) ), this, SLOT( axisSelectionChanged( QCPAxis::SelectableParts ) ) ); + connect( axis( type ), SIGNAL( selectableChanged( QCPAxis::SelectableParts ) ), this, SLOT( axisSelectableChanged( QCPAxis::SelectableParts ) ) ); } - connect(axis(QCPAxis::atLeft), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atRight), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atRight), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atLeft), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atTop), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atTop), SIGNAL(rangeChanged(QCPRange)), axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); - connect(axis(QCPAxis::atLeft), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atRight), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atRight), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atLeft), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atBottom), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atTop), SLOT(setScaleType(QCPAxis::ScaleType))); - connect(axis(QCPAxis::atTop), SIGNAL(scaleTypeChanged(QCPAxis::ScaleType)), axis(QCPAxis::atBottom), SLOT(setScaleType(QCPAxis::ScaleType))); - + connect( axis( QCPAxis::atLeft ), SIGNAL( rangeChanged( QCPRange ) ), axis( QCPAxis::atRight ), SLOT( setRange( QCPRange ) ) ); + connect( axis( QCPAxis::atRight ), SIGNAL( rangeChanged( QCPRange ) ), axis( QCPAxis::atLeft ), SLOT( setRange( QCPRange ) ) ); + connect( axis( QCPAxis::atBottom ), SIGNAL( rangeChanged( QCPRange ) ), axis( QCPAxis::atTop ), SLOT( setRange( QCPRange ) ) ); + connect( axis( QCPAxis::atTop ), SIGNAL( rangeChanged( QCPRange ) ), axis( QCPAxis::atBottom ), SLOT( setRange( QCPRange ) ) ); + connect( axis( QCPAxis::atLeft ), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), axis( QCPAxis::atRight ), SLOT( setScaleType( QCPAxis::ScaleType ) ) ); + connect( axis( QCPAxis::atRight ), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), axis( QCPAxis::atLeft ), SLOT( setScaleType( QCPAxis::ScaleType ) ) ); + connect( axis( QCPAxis::atBottom ), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), axis( QCPAxis::atTop ), SLOT( setScaleType( QCPAxis::ScaleType ) ) ); + connect( axis( QCPAxis::atTop ), SIGNAL( scaleTypeChanged( QCPAxis::ScaleType ) ), axis( QCPAxis::atBottom ), SLOT( setScaleType( QCPAxis::ScaleType ) ) ); + // make layer transfers of color scale transfer to axis rect and axes // the axes must be set after axis rect, such that they appear above color gradient drawn by axis rect: - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), this, SLOT(setLayer(QCPLayer*))); - foreach (QCPAxis::AxisType type, allAxisTypes) - connect(parentColorScale, SIGNAL(layerChanged(QCPLayer*)), axis(type), SLOT(setLayer(QCPLayer*))); + connect( parentColorScale, SIGNAL( layerChanged( QCPLayer* ) ), this, SLOT( setLayer( QCPLayer* ) ) ); + foreach( QCPAxis::AxisType type, allAxisTypes ) + connect( parentColorScale, SIGNAL( layerChanged( QCPLayer* ) ), axis( type ), SLOT( setLayer( QCPLayer* ) ) ); } /*! \internal @@ -19835,21 +19953,21 @@ QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate(QCPColorScale *parent \seebaseclassmethod */ -void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) +void QCPColorScaleAxisRectPrivate::draw( QCPPainter* painter ) { - if (mGradientImageInvalidated) + if( mGradientImageInvalidated ) updateGradientImage(); - + bool mirrorHorz = false; bool mirrorVert = false; - if (mParentColorScale->mColorAxis) + if( mParentColorScale->mColorAxis ) { - mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop); - mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && (mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight); + mirrorHorz = mParentColorScale->mColorAxis.data()->rangeReversed() && ( mParentColorScale->type() == QCPAxis::atBottom || mParentColorScale->type() == QCPAxis::atTop ); + mirrorVert = mParentColorScale->mColorAxis.data()->rangeReversed() && ( mParentColorScale->type() == QCPAxis::atLeft || mParentColorScale->type() == QCPAxis::atRight ); } - - painter->drawImage(rect().adjusted(0, -1, 0, -1), mGradientImage.mirrored(mirrorHorz, mirrorVert)); - QCPAxisRect::draw(painter); + + painter->drawImage( rect().adjusted( 0, -1, 0, -1 ), mGradientImage.mirrored( mirrorHorz, mirrorVert ) ); + QCPAxisRect::draw( painter ); } /*! \internal @@ -19859,36 +19977,37 @@ void QCPColorScaleAxisRectPrivate::draw(QCPPainter *painter) */ void QCPColorScaleAxisRectPrivate::updateGradientImage() { - if (rect().isEmpty()) + if( rect().isEmpty() ) return; - + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; int n = mParentColorScale->mGradient.levelCount(); int w, h; - QVector data(n); - for (int i=0; i data( n ); + for( int i = 0; i < n; ++i ) data[i] = i; - if (mParentColorScale->mType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop) + if( mParentColorScale->mType == QCPAxis::atBottom || mParentColorScale->mType == QCPAxis::atTop ) { w = n; h = rect().height(); - mGradientImage = QImage(w, h, format); + mGradientImage = QImage( w, h, format ); QVector pixels; - for (int y=0; y(mGradientImage.scanLine(y))); - mParentColorScale->mGradient.colorize(data.constData(), QCPRange(0, n-1), pixels.first(), n); - for (int y=1; y( mGradientImage.scanLine( y ) ) ); + mParentColorScale->mGradient.colorize( data.constData(), QCPRange( 0, n - 1 ), pixels.first(), n ); + for( int y = 1; y < h; ++y ) + memcpy( pixels.at( y ), pixels.first(), n * sizeof( QRgb ) ); + } + else { w = rect().width(); h = n; - mGradientImage = QImage(w, h, format); - for (int y=0; y(mGradientImage.scanLine(y)); - const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); - for (int x=0; x( mGradientImage.scanLine( y ) ); + const QRgb lineColor = mParentColorScale->mGradient.color( data[h - 1 - y], QCPRange( 0, n - 1 ) ); + for( int x = 0; x < w; ++x ) pixels[x] = lineColor; } } @@ -19900,22 +20019,22 @@ void QCPColorScaleAxisRectPrivate::updateGradientImage() This slot is connected to the selectionChanged signals of the four axes in the constructor. It synchronizes the selection state of the axes. */ -void QCPColorScaleAxisRectPrivate::axisSelectionChanged(QCPAxis::SelectableParts selectedParts) +void QCPColorScaleAxisRectPrivate::axisSelectionChanged( QCPAxis::SelectableParts selectedParts ) { // axis bases of four axes shall always (de-)selected synchronously: QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) + foreach( QCPAxis::AxisType type, allAxisTypes ) { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) + if( QCPAxis* senderAxis = qobject_cast( sender() ) ) + if( senderAxis->axisType() == type ) continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + + if( axis( type )->selectableParts().testFlag( QCPAxis::spAxis ) ) { - if (selectedParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectedParts(axis(type)->selectedParts() | QCPAxis::spAxis); + if( selectedParts.testFlag( QCPAxis::spAxis ) ) + axis( type )->setSelectedParts( axis( type )->selectedParts() | QCPAxis::spAxis ); else - axis(type)->setSelectedParts(axis(type)->selectedParts() & ~QCPAxis::spAxis); + axis( type )->setSelectedParts( axis( type )->selectedParts() & ~QCPAxis::spAxis ); } } } @@ -19925,28 +20044,27 @@ void QCPColorScaleAxisRectPrivate::axisSelectionChanged(QCPAxis::SelectableParts This slot is connected to the selectableChanged signals of the four axes in the constructor. It synchronizes the selectability of the axes. */ -void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectableParts selectableParts) +void QCPColorScaleAxisRectPrivate::axisSelectableChanged( QCPAxis::SelectableParts selectableParts ) { // synchronize axis base selectability: QList allAxisTypes = QList() << QCPAxis::atBottom << QCPAxis::atTop << QCPAxis::atLeft << QCPAxis::atRight; - foreach (QCPAxis::AxisType type, allAxisTypes) + foreach( QCPAxis::AxisType type, allAxisTypes ) { - if (QCPAxis *senderAxis = qobject_cast(sender())) - if (senderAxis->axisType() == type) + if( QCPAxis* senderAxis = qobject_cast( sender() ) ) + if( senderAxis->axisType() == type ) continue; - - if (axis(type)->selectableParts().testFlag(QCPAxis::spAxis)) + + if( axis( type )->selectableParts().testFlag( QCPAxis::spAxis ) ) { - if (selectableParts.testFlag(QCPAxis::spAxis)) - axis(type)->setSelectableParts(axis(type)->selectableParts() | QCPAxis::spAxis); + if( selectableParts.testFlag( QCPAxis::spAxis ) ) + axis( type )->setSelectableParts( axis( type )->selectableParts() | QCPAxis::spAxis ); else - axis(type)->setSelectableParts(axis(type)->selectableParts() & ~QCPAxis::spAxis); + axis( type )->setSelectableParts( axis( type )->selectableParts() & ~QCPAxis::spAxis ); } } } /* end of 'src/layoutelements/layoutelement-colorscale.cpp' */ - /* including file 'src/plottables/plottable-graph.cpp', size 74194 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -20024,22 +20142,19 @@ void QCPColorScaleAxisRectPrivate::axisSelectableChanged(QCPAxis::SelectablePart /*! Constructs a data point with key and value set to zero. */ -QCPGraphData::QCPGraphData() : - key(0), - value(0) +QCPGraphData::QCPGraphData() + : key( 0 ), value( 0 ) { } /*! Constructs a data point with the specified \a key and \a value. */ -QCPGraphData::QCPGraphData(double key, double value) : - key(key), - value(value) +QCPGraphData::QCPGraphData( double key, double value ) + : key( key ), value( value ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPGraph //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -20105,19 +20220,19 @@ QCPGraphData::QCPGraphData(double key, double value) : To directly create a graph inside a plot, you can also use the simpler QCustomPlot::addGraph function. */ -QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) +QCPGraph::QCPGraph( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable1D( keyAxis, valueAxis ) { // special handling for QCPGraphs to maintain the simple graph interface: - mParentPlot->registerGraph(this); + mParentPlot->registerGraph( this ); - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setLineStyle(lsLine); - setScatterSkip(0); - setChannelFillGraph(0); - setAdaptiveSampling(true); + setPen( QPen( Qt::blue, 0 ) ); + setBrush( Qt::NoBrush ); + + setLineStyle( lsLine ); + setScatterSkip( 0 ); + setChannelFillGraph( 0 ); + setAdaptiveSampling( true ); } QCPGraph::~QCPGraph() @@ -20139,7 +20254,7 @@ QCPGraph::~QCPGraph() \see addData */ -void QCPGraph::setData(QSharedPointer data) +void QCPGraph::setData( QSharedPointer data ) { mDataContainer = data; } @@ -20155,10 +20270,10 @@ void QCPGraph::setData(QSharedPointer data) \see addData */ -void QCPGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) +void QCPGraph::setData( const QVector& keys, const QVector& values, bool alreadySorted ) { mDataContainer->clear(); - addData(keys, values, alreadySorted); + addData( keys, values, alreadySorted ); } /*! @@ -20167,7 +20282,7 @@ void QCPGraph::setData(const QVector &keys, const QVector &value \see setScatterStyle */ -void QCPGraph::setLineStyle(LineStyle ls) +void QCPGraph::setLineStyle( LineStyle ls ) { mLineStyle = ls; } @@ -20178,7 +20293,7 @@ void QCPGraph::setLineStyle(LineStyle ls) \see QCPScatterStyle, setLineStyle */ -void QCPGraph::setScatterStyle(const QCPScatterStyle &style) +void QCPGraph::setScatterStyle( const QCPScatterStyle& style ) { mScatterStyle = style; } @@ -20194,9 +20309,9 @@ void QCPGraph::setScatterStyle(const QCPScatterStyle &style) \see setScatterStyle */ -void QCPGraph::setScatterSkip(int skip) +void QCPGraph::setScatterSkip( int skip ) { - mScatterSkip = qMax(0, skip); + mScatterSkip = qMax( 0, skip ); } /*! @@ -20208,23 +20323,23 @@ void QCPGraph::setScatterSkip(int skip) \see setBrush */ -void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) +void QCPGraph::setChannelFillGraph( QCPGraph* targetGraph ) { // prevent setting channel target to this graph itself: - if (targetGraph == this) + if( targetGraph == this ) { qDebug() << Q_FUNC_INFO << "targetGraph is this graph itself"; mChannelFillGraph = 0; return; } // prevent setting channel target to a graph not in the plot: - if (targetGraph && targetGraph->mParentPlot != mParentPlot) + if( targetGraph && targetGraph->mParentPlot != mParentPlot ) { qDebug() << Q_FUNC_INFO << "targetGraph not in same plot"; mChannelFillGraph = 0; return; } - + mChannelFillGraph = targetGraph; } @@ -20259,7 +20374,7 @@ void QCPGraph::setChannelFillGraph(QCPGraph *targetGraph) enabled to false before issuing a command like \ref QCustomPlot::savePng, and setting \a enabled back to true afterwards. */ -void QCPGraph::setAdaptiveSampling(bool enabled) +void QCPGraph::setAdaptiveSampling( bool enabled ) { mAdaptiveSampling = enabled; } @@ -20276,23 +20391,23 @@ void QCPGraph::setAdaptiveSampling(bool enabled) Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPGraph::addData(const QVector &keys, const QVector &values, bool alreadySorted) +void QCPGraph::addData( const QVector& keys, const QVector& values, bool alreadySorted ) { - if (keys.size() != values.size()) + if( keys.size() != values.size() ) qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); + const int n = qMin( keys.size(), values.size() ); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->key = keys[i]; it->value = values[i]; ++it; ++i; } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, alreadySorted ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -20302,9 +20417,9 @@ void QCPGraph::addData(const QVector &keys, const QVector &value Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPGraph::addData(double key, double value) +void QCPGraph::addData( double key, double value ) { - mDataContainer->add(QCPGraphData(key, value)); + mDataContainer->add( QCPGraphData( key, value ) ); } /*! @@ -20315,138 +20430,147 @@ void QCPGraph::addData(double key, double value) \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPGraph::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) + double result = pointDistance( pos, closestDataPoint ); + if( details ) { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = closestDataPoint - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } return result; - } else + } + else return -1; } /* inherits documentation from base class */ -QCPRange QCPGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPGraph::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { - return mDataContainer->keyRange(foundRange, inSignDomain); + return mDataContainer->keyRange( foundRange, inSignDomain ); } /* inherits documentation from base class */ -QCPRange QCPGraph::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPGraph::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); + return mDataContainer->valueRange( foundRange, inSignDomain, inKeyRange ); } /* inherits documentation from base class */ -void QCPGraph::draw(QCPPainter *painter) +void QCPGraph::draw( QCPPainter* painter ) { - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - if (mLineStyle == lsNone && mScatterStyle.isNone()) return; - - QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments - + if( !mKeyAxis || !mValueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + if( mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty() ) + return; + if( mLineStyle == lsNone && mScatterStyle.isNone() ) + return; + + QVector lines, scatters; // line and (if necessary) scatter pixel coordinates will be stored here while iterating over segments + // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); // get line pixel points appropriate to line style: - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) - getLines(&lines, lineDataRange); - + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at( i ) : allSegments.at( i ).adjusted( -1, 1 ); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getLines takes care) + getLines( &lines, lineDataRange ); + // check data validity if flag set: #ifdef QCUSTOMPLOT_CHECK_DATA QCPGraphDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + for( it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it ) { - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + if( QCP::isInvalidData( it->key, it->value ) ) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." + << "Plottable name:" << name(); } #endif - + // draw fill of graph: - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); + if( isSelectedSegment && mSelectionDecorator ) + mSelectionDecorator->applyBrush( painter ); else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - drawFill(painter, &lines); - + painter->setBrush( mBrush ); + painter->setPen( Qt::NoPen ); + drawFill( painter, &lines ); + // draw line: - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); + if( isSelectedSegment && mSelectionDecorator ) + mSelectionDecorator->applyPen( painter ); else - painter->setPen(mPen); - painter->setBrush(Qt::NoBrush); - if (mLineStyle == lsImpulse) - drawImpulsePlot(painter, lines); + painter->setPen( mPen ); + painter->setBrush( Qt::NoBrush ); + if( mLineStyle == lsImpulse ) + drawImpulsePlot( painter, lines ); else - drawLinePlot(painter, lines); // also step plots can be drawn as a line plot + drawLinePlot( painter, lines ); // also step plots can be drawn as a line plot } - + // draw scatters: QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) + if( isSelectedSegment && mSelectionDecorator ) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle( mScatterStyle ); + if( !finalScatterStyle.isNone() ) { - getScatters(&scatters, allSegments.at(i)); - drawScatterPlot(painter, scatters, finalScatterStyle); + getScatters( &scatters, allSegments.at( i ) ); + drawScatterPlot( painter, scatters, finalScatterStyle ); } } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPGraph::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { // draw fill: - if (mBrush.style() != Qt::NoBrush) + if( mBrush.style() != Qt::NoBrush ) { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + applyFillAntialiasingHint( painter ); + painter->fillRect( QRectF( rect.left(), rect.top() + rect.height() / 2.0, rect.width(), rect.height() / 3.0 ), mBrush ); } // draw line vertically centered: - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + applyDefaultAntialiasingHint( painter ); + painter->setPen( mPen ); + painter->drawLine( QLineF( rect.left(), rect.top() + rect.height() / 2.0, rect.right() + 5, rect.top() + rect.height() / 2.0 ) ); // +5 on x2 else last segment is missing from dashed/dotted pens } // draw scatter symbol: - if (!mScatterStyle.isNone()) + if( !mScatterStyle.isNone() ) { - applyScattersAntialiasingHint(painter); + applyScattersAntialiasingHint( painter ); // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + if( mScatterStyle.shape() == QCPScatterStyle::ssPixmap && ( mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height() ) ) { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else + QCPScatterStyle scaledStyle( mScatterStyle ); + scaledStyle.setPixmap( scaledStyle.pixmap().scaled( rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); + scaledStyle.applyTo( painter, mPen ); + scaledStyle.drawShape( painter, QRectF( rect ).center() ); + } + else { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); + mScatterStyle.applyTo( painter, mPen ); + mScatterStyle.drawShape( painter, QRectF( rect ).center() ); } } } @@ -20471,32 +20595,45 @@ void QCPGraph::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const \see getScatters */ -void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) const +void QCPGraph::getLines( QVector* lines, const QCPDataRange& dataRange ) const { - if (!lines) return; + if( !lines ) + return; QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) + getVisibleDataBounds( begin, end, dataRange ); + if( begin == end ) { lines->clear(); return; } - - QVector lineData; - if (mLineStyle != lsNone) - getOptimizedLineData(&lineData, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) - std::reverse(lineData.begin(), lineData.end()); - switch (mLineStyle) + QVector lineData; + if( mLineStyle != lsNone ) + getOptimizedLineData( &lineData, begin, end ); + + if( mKeyAxis->rangeReversed() != ( mKeyAxis->orientation() == Qt::Vertical ) ) // make sure key pixels are sorted ascending in lineData (significantly simplifies following processing) + std::reverse( lineData.begin(), lineData.end() ); + + switch( mLineStyle ) { - case lsNone: lines->clear(); break; - case lsLine: *lines = dataToLines(lineData); break; - case lsStepLeft: *lines = dataToStepLeftLines(lineData); break; - case lsStepRight: *lines = dataToStepRightLines(lineData); break; - case lsStepCenter: *lines = dataToStepCenterLines(lineData); break; - case lsImpulse: *lines = dataToImpulseLines(lineData); break; + case lsNone: + lines->clear(); + break; + case lsLine: + *lines = dataToLines( lineData ); + break; + case lsStepLeft: + *lines = dataToStepLeftLines( lineData ); + break; + case lsStepRight: + *lines = dataToStepRightLines( lineData ); + break; + case lsStepCenter: + *lines = dataToStepCenterLines( lineData ); + break; + case lsImpulse: + *lines = dataToImpulseLines( lineData ); + break; } } @@ -20512,46 +20649,53 @@ void QCPGraph::getLines(QVector *lines, const QCPDataRange &dataRange) function to check for valid indices in \a dataRange, e.g. when extending ranges coming from \ref getDataSegments. */ -void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const +void QCPGraph::getScatters( QVector* scatters, const QCPDataRange& dataRange ) const { - if (!scatters) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; scatters->clear(); return; } - + if( !scatters ) + return; + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + scatters->clear(); + return; + } + QCPGraphDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, dataRange); - if (begin == end) + getVisibleDataBounds( begin, end, dataRange ); + if( begin == end ) { scatters->clear(); return; } - + QVector data; - getOptimizedScatterData(&data, begin, end); - - if (mKeyAxis->rangeReversed() != (mKeyAxis->orientation() == Qt::Vertical)) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) - std::reverse(data.begin(), data.end()); - - scatters->resize(data.size()); - if (keyAxis->orientation() == Qt::Vertical) + getOptimizedScatterData( &data, begin, end ); + + if( mKeyAxis->rangeReversed() != ( mKeyAxis->orientation() == Qt::Vertical ) ) // make sure key pixels are sorted ascending in data (significantly simplifies following processing) + std::reverse( data.begin(), data.end() ); + + scatters->resize( data.size() ); + if( keyAxis->orientation() == Qt::Vertical ) { - for (int i=0; icoordToPixel(data.at(i).value)); - (*scatters)[i].setY(keyAxis->coordToPixel(data.at(i).key)); + ( *scatters )[i].setX( valueAxis->coordToPixel( data.at( i ).value ) ); + ( *scatters )[i].setY( keyAxis->coordToPixel( data.at( i ).key ) ); } } - } else + } + else { - for (int i=0; icoordToPixel(data.at(i).key)); - (*scatters)[i].setY(valueAxis->coordToPixel(data.at(i).value)); + ( *scatters )[i].setX( keyAxis->coordToPixel( data.at( i ).key ) ); + ( *scatters )[i].setY( valueAxis->coordToPixel( data.at( i ).value ) ); } } } @@ -20567,29 +20711,34 @@ void QCPGraph::getScatters(QVector *scatters, const QCPDataRange &dataR \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot */ -QVector QCPGraph::dataToLines(const QVector &data) const +QVector QCPGraph::dataToLines( const QVector& data ) const { QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return result; + } + + result.resize( data.size() ); - result.resize(data.size()); - // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - for (int i=0; icoordToPixel(data.at(i).value)); - result[i].setY(keyAxis->coordToPixel(data.at(i).key)); + result[i].setX( valueAxis->coordToPixel( data.at( i ).value ) ); + result[i].setY( keyAxis->coordToPixel( data.at( i ).key ) ); } - } else // key axis is horizontal + } + else // key axis is horizontal { - for (int i=0; icoordToPixel(data.at(i).key)); - result[i].setY(valueAxis->coordToPixel(data.at(i).value)); + result[i].setX( keyAxis->coordToPixel( data.at( i ).key ) ); + result[i].setY( valueAxis->coordToPixel( data.at( i ).value ) ); } } return result; @@ -20605,39 +20754,44 @@ QVector QCPGraph::dataToLines(const QVector &data) const \see dataToLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot */ -QVector QCPGraph::dataToStepLeftLines(const QVector &data) const +QVector QCPGraph::dataToStepLeftLines( const QVector& data ) const { QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return result; + } + + result.resize( data.size() * 2 ); + // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel( data.first().value ); + for( int i = 0; i < data.size(); ++i ) { - const double key = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(lastValue); - result[i*2+1].setY(key); + const double key = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( lastValue ); + result[i * 2 + 0].setY( key ); + lastValue = valueAxis->coordToPixel( data.at( i ).value ); + result[i * 2 + 1].setX( lastValue ); + result[i * 2 + 1].setY( key ); } - } else // key axis is horizontal + } + else // key axis is horizontal { - double lastValue = valueAxis->coordToPixel(data.first().value); - for (int i=0; icoordToPixel( data.first().value ); + for( int i = 0; i < data.size(); ++i ) { - const double key = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - result[i*2+1].setX(key); - result[i*2+1].setY(lastValue); + const double key = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( key ); + result[i * 2 + 0].setY( lastValue ); + lastValue = valueAxis->coordToPixel( data.at( i ).value ); + result[i * 2 + 1].setX( key ); + result[i * 2 + 1].setY( lastValue ); } } return result; @@ -20653,39 +20807,44 @@ QVector QCPGraph::dataToStepLeftLines(const QVector &data \see dataToLines, dataToStepLeftLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot */ -QVector QCPGraph::dataToStepRightLines(const QVector &data) const +QVector QCPGraph::dataToStepRightLines( const QVector& data ) const { QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return result; + } + + result.resize( data.size() * 2 ); + // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel( data.first().key ); + for( int i = 0; i < data.size(); ++i ) { - const double value = valueAxis->coordToPixel(data.at(i).value); - result[i*2+0].setX(value); - result[i*2+0].setY(lastKey); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(value); - result[i*2+1].setY(lastKey); + const double value = valueAxis->coordToPixel( data.at( i ).value ); + result[i * 2 + 0].setX( value ); + result[i * 2 + 0].setY( lastKey ); + lastKey = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 1].setX( value ); + result[i * 2 + 1].setY( lastKey ); } - } else // key axis is horizontal + } + else // key axis is horizontal { - double lastKey = keyAxis->coordToPixel(data.first().key); - for (int i=0; icoordToPixel( data.first().key ); + for( int i = 0; i < data.size(); ++i ) { - const double value = valueAxis->coordToPixel(data.at(i).value); - result[i*2+0].setX(lastKey); - result[i*2+0].setY(value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+1].setX(lastKey); - result[i*2+1].setY(value); + const double value = valueAxis->coordToPixel( data.at( i ).value ); + result[i * 2 + 0].setX( lastKey ); + result[i * 2 + 0].setY( value ); + lastKey = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 1].setX( lastKey ); + result[i * 2 + 1].setY( value ); } } return result; @@ -20701,52 +20860,57 @@ QVector QCPGraph::dataToStepRightLines(const QVector &dat \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToImpulseLines, getLines, drawLinePlot */ -QVector QCPGraph::dataToStepCenterLines(const QVector &data) const +QVector QCPGraph::dataToStepCenterLines( const QVector& data ) const { QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return result; + } + + result.resize( data.size() * 2 ); + // calculate steps from data and transform to pixel coordinates: - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastValue); - result[0].setY(lastKey); - for (int i=1; icoordToPixel( data.first().key ); + double lastValue = valueAxis->coordToPixel( data.first().value ); + result[0].setX( lastValue ); + result[0].setY( lastKey ); + for( int i = 1; i < data.size(); ++i ) { - const double key = (keyAxis->coordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(lastValue); - result[i*2-1].setY(key); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(lastValue); - result[i*2+0].setY(key); + const double key = ( keyAxis->coordToPixel( data.at( i ).key ) + lastKey ) * 0.5; + result[i * 2 - 1].setX( lastValue ); + result[i * 2 - 1].setY( key ); + lastValue = valueAxis->coordToPixel( data.at( i ).value ); + lastKey = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( lastValue ); + result[i * 2 + 0].setY( key ); } - result[data.size()*2-1].setX(lastValue); - result[data.size()*2-1].setY(lastKey); - } else // key axis is horizontal + result[data.size() * 2 - 1].setX( lastValue ); + result[data.size() * 2 - 1].setY( lastKey ); + } + else // key axis is horizontal { - double lastKey = keyAxis->coordToPixel(data.first().key); - double lastValue = valueAxis->coordToPixel(data.first().value); - result[0].setX(lastKey); - result[0].setY(lastValue); - for (int i=1; icoordToPixel( data.first().key ); + double lastValue = valueAxis->coordToPixel( data.first().value ); + result[0].setX( lastKey ); + result[0].setY( lastValue ); + for( int i = 1; i < data.size(); ++i ) { - const double key = (keyAxis->coordToPixel(data.at(i).key)+lastKey)*0.5; - result[i*2-1].setX(key); - result[i*2-1].setY(lastValue); - lastValue = valueAxis->coordToPixel(data.at(i).value); - lastKey = keyAxis->coordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(lastValue); + const double key = ( keyAxis->coordToPixel( data.at( i ).key ) + lastKey ) * 0.5; + result[i * 2 - 1].setX( key ); + result[i * 2 - 1].setY( lastValue ); + lastValue = valueAxis->coordToPixel( data.at( i ).value ); + lastKey = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( key ); + result[i * 2 + 0].setY( lastValue ); } - result[data.size()*2-1].setX(lastKey); - result[data.size()*2-1].setY(lastValue); + result[data.size() * 2 - 1].setX( lastKey ); + result[data.size() * 2 - 1].setY( lastValue ); } return result; } @@ -20761,35 +20925,40 @@ QVector QCPGraph::dataToStepCenterLines(const QVector &da \see dataToLines, dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, getLines, drawImpulsePlot */ -QVector QCPGraph::dataToImpulseLines(const QVector &data) const +QVector QCPGraph::dataToImpulseLines( const QVector& data ) const { QVector result; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } - - result.resize(data.size()*2); - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return result; + } + + result.resize( data.size() * 2 ); + // transform data points to pixels: - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(valueAxis->coordToPixel(0)); - result[i*2+0].setY(key); - result[i*2+1].setX(valueAxis->coordToPixel(data.at(i).value)); - result[i*2+1].setY(key); + const double key = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( valueAxis->coordToPixel( 0 ) ); + result[i * 2 + 0].setY( key ); + result[i * 2 + 1].setX( valueAxis->coordToPixel( data.at( i ).value ) ); + result[i * 2 + 1].setY( key ); } - } else // key axis is horizontal + } + else // key axis is horizontal { - for (int i=0; icoordToPixel(data.at(i).key); - result[i*2+0].setX(key); - result[i*2+0].setY(valueAxis->coordToPixel(0)); - result[i*2+1].setX(key); - result[i*2+1].setY(valueAxis->coordToPixel(data.at(i).value)); + const double key = keyAxis->coordToPixel( data.at( i ).key ); + result[i * 2 + 0].setX( key ); + result[i * 2 + 0].setY( valueAxis->coordToPixel( 0 ) ); + result[i * 2 + 1].setX( key ); + result[i * 2 + 1].setY( valueAxis->coordToPixel( data.at( i ).value ) ); } } return result; @@ -20812,29 +20981,32 @@ QVector QCPGraph::dataToImpulseLines(const QVector &data) \see drawLinePlot, drawImpulsePlot, drawScatterPlot */ -void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const +void QCPGraph::drawFill( QCPPainter* painter, QVector* lines ) const { - if (mLineStyle == lsImpulse) return; // fill doesn't make sense for impulse plot - if (painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0) return; - - applyFillAntialiasingHint(painter); - QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); - if (!mChannelFillGraph) + if( mLineStyle == lsImpulse ) + return; // fill doesn't make sense for impulse plot + if( painter->brush().style() == Qt::NoBrush || painter->brush().color().alpha() == 0 ) + return; + + applyFillAntialiasingHint( painter ); + QVector segments = getNonNanSegments( lines, keyAxis()->orientation() ); + if( !mChannelFillGraph ) { // draw base fill under graph, fill goes all the way to the zero-value-line: - for (int i=0; idrawPolygon(getFillPolygon(lines, segments.at(i))); - } else + for( int i = 0; i < segments.size(); ++i ) + painter->drawPolygon( getFillPolygon( lines, segments.at( i ) ) ); + } + else { // draw fill between this graph and mChannelFillGraph: QVector otherLines; - mChannelFillGraph->getLines(&otherLines, QCPDataRange(0, mChannelFillGraph->dataCount())); - if (!otherLines.isEmpty()) + mChannelFillGraph->getLines( &otherLines, QCPDataRange( 0, mChannelFillGraph->dataCount() ) ); + if( !otherLines.isEmpty() ) { - QVector otherSegments = getNonNanSegments(&otherLines, mChannelFillGraph->keyAxis()->orientation()); - QVector > segmentPairs = getOverlappingSegments(segments, lines, otherSegments, &otherLines); - for (int i=0; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); + QVector otherSegments = getNonNanSegments( &otherLines, mChannelFillGraph->keyAxis()->orientation() ); + QVector > segmentPairs = getOverlappingSegments( segments, lines, otherSegments, &otherLines ); + for( int i = 0; i < segmentPairs.size(); ++i ) + painter->drawPolygon( getChannelFillPolygon( lines, segmentPairs.at( i ).first, &otherLines, segmentPairs.at( i ).second ) ); } } } @@ -20846,12 +21018,12 @@ void QCPGraph::drawFill(QCPPainter *painter, QVector *lines) const \see drawLinePlot, drawImpulsePlot */ -void QCPGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const +void QCPGraph::drawScatterPlot( QCPPainter* painter, const QVector& scatters, const QCPScatterStyle& style ) const { - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &scat \see drawScatterPlot, drawImpulsePlot, QCPAbstractPlottable1D::drawPolyline */ -void QCPGraph::drawLinePlot(QCPPainter *painter, const QVector &lines) const +void QCPGraph::drawLinePlot( QCPPainter* painter, const QVector& lines ) const { - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + if( painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0 ) { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); + applyDefaultAntialiasingHint( painter ); + drawPolyline( painter, lines ); } } @@ -20877,17 +21049,17 @@ void QCPGraph::drawLinePlot(QCPPainter *painter, const QVector &lines) \see drawLinePlot, drawScatterPlot */ -void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &lines) const +void QCPGraph::drawImpulsePlot( QCPPainter* painter, const QVector& lines ) const { - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + if( painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0 ) { - applyDefaultAntialiasingHint(painter); + applyDefaultAntialiasingHint( painter ); QPen oldPen = painter->pen(); QPen newPen = painter->pen(); - newPen.setCapStyle(Qt::FlatCap); // so impulse line doesn't reach beyond zero-line - painter->setPen(newPen); - painter->drawLines(lines); - painter->setPen(oldPen); + newPen.setCapStyle( Qt::FlatCap ); // so impulse line doesn't reach beyond zero-line + painter->setPen( newPen ); + painter->drawLines( lines ); + painter->setPen( oldPen ); } } @@ -20903,83 +21075,92 @@ void QCPGraph::drawImpulsePlot(QCPPainter *painter, const QVector &line \see getOptimizedScatterData */ -void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const +void QCPGraph::getOptimizedLineData( QVector* lineData, const QCPGraphDataContainer::const_iterator& begin, const QCPGraphDataContainer::const_iterator& end ) const { - if (!lineData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (begin == end) return; - - int dataCount = end-begin; - int maxCount = (std::numeric_limits::max)(); - if (mAdaptiveSampling) + if( !lineData ) + return; + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - if (2*keyPixelSpan+2 < static_cast((std::numeric_limits::max)())) - maxCount = 2*keyPixelSpan+2; + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + if( begin == end ) + return; + + int dataCount = end - begin; + int maxCount = ( std::numeric_limits::max )(); + if( mAdaptiveSampling ) + { + double keyPixelSpan = qAbs( keyAxis->coordToPixel( begin->key ) - keyAxis->coordToPixel( ( end - 1 )->key ) ); + if( 2 * keyPixelSpan + 2 < static_cast( ( std::numeric_limits::max )() ) ) + maxCount = 2 * keyPixelSpan + 2; + } + + if( mAdaptiveSampling && dataCount >= maxCount ) // use adaptive sampling only if there are at least two points per pixel on average { QCPGraphDataContainer::const_iterator it = begin; double minValue = it->value; double maxValue = it->value; QCPGraphDataContainer::const_iterator currentIntervalFirstPoint = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor == -1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord( (int)( keyAxis->coordToPixel( begin->key ) + reversedRound ) ); double lastIntervalEndKey = currentIntervalStartKey; - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + double keyEpsilon = qAbs( currentIntervalStartKey - keyAxis->pixelToCoord( keyAxis->coordToPixel( currentIntervalStartKey ) + 1.0 * reversedFactor ) ); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) int intervalDataCount = 1; - ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect - while (it != end) + ++it; // advance iterator to second data point because adaptive sampling works in 1 point retrospect + while( it != end ) { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary + if( it->key < currentIntervalStartKey + keyEpsilon ) // data point is still within same pixel, so skip it and expand value span of this cluster if necessary { - if (it->value < minValue) + if( it->value < minValue ) minValue = it->value; - else if (it->value > maxValue) + else if( it->value > maxValue ) maxValue = it->value; ++intervalDataCount; - } else // new pixel interval started + } + else // new pixel interval started { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + if( intervalDataCount >= 2 ) // last pixel had multiple data points, consolidate them to a cluster { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point is further away, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - if (it->key > currentIntervalStartKey+keyEpsilon*2) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.8, (it-1)->value)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - lastIntervalEndKey = (it-1)->key; + if( lastIntervalEndKey < currentIntervalStartKey - keyEpsilon ) // last point is further away, so first point of this cluster must be at a real data point + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.2, currentIntervalFirstPoint->value ) ); + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.25, minValue ) ); + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.75, maxValue ) ); + if( it->key > currentIntervalStartKey + keyEpsilon * 2 ) // new pixel started further away from previous cluster, so make sure the last point of the cluster is at a real data point + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.8, ( it - 1 )->value ) ); + } + else + lineData->append( QCPGraphData( currentIntervalFirstPoint->key, currentIntervalFirstPoint->value ) ); + lastIntervalEndKey = ( it - 1 )->key; minValue = it->value; maxValue = it->value; currentIntervalFirstPoint = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + currentIntervalStartKey = keyAxis->pixelToCoord( (int)( keyAxis->coordToPixel( it->key ) + reversedRound ) ); + if( keyEpsilonVariable ) + keyEpsilon = qAbs( currentIntervalStartKey - keyAxis->pixelToCoord( keyAxis->coordToPixel( currentIntervalStartKey ) + 1.0 * reversedFactor ) ); intervalDataCount = 1; } ++it; } // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them to a cluster + if( intervalDataCount >= 2 ) // last pixel had multiple data points, consolidate them to a cluster { - if (lastIntervalEndKey < currentIntervalStartKey-keyEpsilon) // last point wasn't a cluster, so first point of this cluster must be at a real data point - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.2, currentIntervalFirstPoint->value)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.25, minValue)); - lineData->append(QCPGraphData(currentIntervalStartKey+keyEpsilon*0.75, maxValue)); - } else - lineData->append(QCPGraphData(currentIntervalFirstPoint->key, currentIntervalFirstPoint->value)); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + if( lastIntervalEndKey < currentIntervalStartKey - keyEpsilon ) // last point wasn't a cluster, so first point of this cluster must be at a real data point + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.2, currentIntervalFirstPoint->value ) ); + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.25, minValue ) ); + lineData->append( QCPGraphData( currentIntervalStartKey + keyEpsilon * 0.75, maxValue ) ); + } + else + lineData->append( QCPGraphData( currentIntervalFirstPoint->key, currentIntervalFirstPoint->value ) ); + } + else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output { - lineData->resize(dataCount); - std::copy(begin, end, lineData->begin()); + lineData->resize( dataCount ); + std::copy( begin, end, lineData->begin() ); } } @@ -20995,32 +21176,38 @@ void QCPGraph::getOptimizedLineData(QVector *lineData, const QCPGr \see getOptimizedLineData */ -void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const +void QCPGraph::getOptimizedScatterData( QVector* scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end ) const { - if (!scatterData) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - const int scatterModulo = mScatterSkip+1; + if( !scatterData ) + return; + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + const int scatterModulo = mScatterSkip + 1; const bool doScatterSkip = mScatterSkip > 0; - int beginIndex = begin-mDataContainer->constBegin(); - int endIndex = end-mDataContainer->constBegin(); - while (doScatterSkip && begin != end && beginIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + int beginIndex = begin - mDataContainer->constBegin(); + int endIndex = end - mDataContainer->constBegin(); + while( doScatterSkip && begin != end && beginIndex % scatterModulo != 0 ) // advance begin iterator to first non-skipped scatter { ++beginIndex; ++begin; } - if (begin == end) return; - int dataCount = end-begin; - int maxCount = (std::numeric_limits::max)(); - if (mAdaptiveSampling) + if( begin == end ) + return; + int dataCount = end - begin; + int maxCount = ( std::numeric_limits::max )(); + if( mAdaptiveSampling ) { - int keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); - maxCount = 2*keyPixelSpan+2; + int keyPixelSpan = qAbs( keyAxis->coordToPixel( begin->key ) - keyAxis->coordToPixel( ( end - 1 )->key ) ); + maxCount = 2 * keyPixelSpan + 2; } - - if (mAdaptiveSampling && dataCount >= maxCount) // use adaptive sampling only if there are at least two points per pixel on average + + if( mAdaptiveSampling && dataCount >= maxCount ) // use adaptive sampling only if there are at least two points per pixel on average { double valueMaxRange = valueAxis->range().upper; double valueMinRange = valueAxis->range().lower; @@ -21031,19 +21218,19 @@ void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGr QCPGraphDataContainer::const_iterator minValueIt = it; QCPGraphDataContainer::const_iterator maxValueIt = it; QCPGraphDataContainer::const_iterator currentIntervalStart = it; - int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction - int reversedRound = reversedFactor==-1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey - double currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(begin->key)+reversedRound)); - double keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); // interval of one pixel on screen when mapped to plot key coordinates - bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) + int reversedFactor = keyAxis->pixelOrientation(); // is used to calculate keyEpsilon pixel into the correct direction + int reversedRound = reversedFactor == -1 ? 1 : 0; // is used to switch between floor (normal) and ceil (reversed) rounding of currentIntervalStartKey + double currentIntervalStartKey = keyAxis->pixelToCoord( (int)( keyAxis->coordToPixel( begin->key ) + reversedRound ) ); + double keyEpsilon = qAbs( currentIntervalStartKey - keyAxis->pixelToCoord( keyAxis->coordToPixel( currentIntervalStartKey ) + 1.0 * reversedFactor ) ); // interval of one pixel on screen when mapped to plot key coordinates + bool keyEpsilonVariable = keyAxis->scaleType() == QCPAxis::stLogarithmic; // indicates whether keyEpsilon needs to be updated after every interval (for log axes) int intervalDataCount = 1; // advance iterator to second (non-skipped) data point because adaptive sampling works in 1 point retrospect: - if (!doScatterSkip) + if( !doScatterSkip ) ++it; else { itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end + if( itIndex < endIndex ) // make sure we didn't jump over end it += scatterModulo; else { @@ -21052,56 +21239,59 @@ void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGr } } // main loop over data points: - while (it != end) + while( it != end ) { - if (it->key < currentIntervalStartKey+keyEpsilon) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary + if( it->key < currentIntervalStartKey + keyEpsilon ) // data point is still within same pixel, so skip it and expand value span of this pixel if necessary { - if (it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange) + if( it->value < minValue && it->value > valueMinRange && it->value < valueMaxRange ) { minValue = it->value; minValueIt = it; - } else if (it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange) + } + else if( it->value > maxValue && it->value > valueMinRange && it->value < valueMaxRange ) { maxValue = it->value; maxValueIt = it; } ++intervalDataCount; - } else // new pixel started + } + else // new pixel started { - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + if( intervalDataCount >= 2 ) // last pixel had multiple data points, consolidate them { // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + double valuePixelSpan = qAbs( valueAxis->coordToPixel( minValue ) - valueAxis->coordToPixel( maxValue ) ); + int dataModulo = qMax( 1, qRound( intervalDataCount / ( valuePixelSpan / 4.0 ) ) ); // approximately every 4 value pixels one data point on average QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; int c = 0; - while (intervalIt != it) + while( intervalIt != it ) { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); + if( ( c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt ) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange ) + scatterData->append( *intervalIt ); ++c; - if (!doScatterSkip) + if( !doScatterSkip ) ++intervalIt; else - intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here + intervalIt += scatterModulo; // since we know indices of "currentIntervalStart", "intervalIt" and "it" are multiples of scatterModulo, we can't accidentally jump over "it" here } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); + } + else if( currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange ) + scatterData->append( *currentIntervalStart ); minValue = it->value; maxValue = it->value; currentIntervalStart = it; - currentIntervalStartKey = keyAxis->pixelToCoord((int)(keyAxis->coordToPixel(it->key)+reversedRound)); - if (keyEpsilonVariable) - keyEpsilon = qAbs(currentIntervalStartKey-keyAxis->pixelToCoord(keyAxis->coordToPixel(currentIntervalStartKey)+1.0*reversedFactor)); + currentIntervalStartKey = keyAxis->pixelToCoord( (int)( keyAxis->coordToPixel( it->key ) + reversedRound ) ); + if( keyEpsilonVariable ) + keyEpsilon = qAbs( currentIntervalStartKey - keyAxis->pixelToCoord( keyAxis->coordToPixel( currentIntervalStartKey ) + 1.0 * reversedFactor ) ); intervalDataCount = 1; } // advance to next data point: - if (!doScatterSkip) + if( !doScatterSkip ) ++it; else { itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end + if( itIndex < endIndex ) // make sure we didn't jump over end it += scatterModulo; else { @@ -21111,25 +21301,25 @@ void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGr } } // handle last interval: - if (intervalDataCount >= 2) // last pixel had multiple data points, consolidate them + if( intervalDataCount >= 2 ) // last pixel had multiple data points, consolidate them { // determine value pixel span and add as many points in interval to maintain certain vertical data density (this is specific to scatter plot): - double valuePixelSpan = qAbs(valueAxis->coordToPixel(minValue)-valueAxis->coordToPixel(maxValue)); - int dataModulo = qMax(1, qRound(intervalDataCount/(valuePixelSpan/4.0))); // approximately every 4 value pixels one data point on average + double valuePixelSpan = qAbs( valueAxis->coordToPixel( minValue ) - valueAxis->coordToPixel( maxValue ) ); + int dataModulo = qMax( 1, qRound( intervalDataCount / ( valuePixelSpan / 4.0 ) ) ); // approximately every 4 value pixels one data point on average QCPGraphDataContainer::const_iterator intervalIt = currentIntervalStart; - int intervalItIndex = intervalIt-mDataContainer->constBegin(); + int intervalItIndex = intervalIt - mDataContainer->constBegin(); int c = 0; - while (intervalIt != it) + while( intervalIt != it ) { - if ((c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange) - scatterData->append(*intervalIt); + if( ( c % dataModulo == 0 || intervalIt == minValueIt || intervalIt == maxValueIt ) && intervalIt->value > valueMinRange && intervalIt->value < valueMaxRange ) + scatterData->append( *intervalIt ); ++c; - if (!doScatterSkip) + if( !doScatterSkip ) ++intervalIt; - else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: + else // here we can't guarantee that adding scatterModulo doesn't exceed "it" (because "it" is equal to "end" here, and "end" isn't scatterModulo-aligned), so check via index comparison: { intervalItIndex += scatterModulo; - if (intervalItIndex < itIndex) + if( intervalItIndex < itIndex ) intervalIt += scatterModulo; else { @@ -21138,24 +21328,25 @@ void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGr } } } - } else if (currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange) - scatterData->append(*currentIntervalStart); - - } else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output + } + else if( currentIntervalStart->value > valueMinRange && currentIntervalStart->value < valueMaxRange ) + scatterData->append( *currentIntervalStart ); + } + else // don't use adaptive sampling algorithm, transfer points one-to-one from the data container into the output { QCPGraphDataContainer::const_iterator it = begin; int itIndex = beginIndex; - scatterData->reserve(dataCount); - while (it != end) + scatterData->reserve( dataCount ); + while( it != end ) { - scatterData->append(*it); + scatterData->append( *it ); // advance to next data point: - if (!doScatterSkip) + if( !doScatterSkip ) ++it; else { itIndex += scatterModulo; - if (itIndex < endIndex) + if( itIndex < endIndex ) it += scatterModulo; else { @@ -21176,22 +21367,27 @@ void QCPGraph::getOptimizedScatterData(QVector *scatterData, QCPGr indicate a range that contains one additional data point to the left and right of the visible axis range. */ -void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +void QCPGraph::getVisibleDataBounds( QCPGraphDataContainer::const_iterator& begin, QCPGraphDataContainer::const_iterator& end, const QCPDataRange& rangeRestriction ) const { - if (rangeRestriction.isEmpty()) + if( rangeRestriction.isEmpty() ) { end = mDataContainer->constEnd(); begin = end; - } else + } + else { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } // get visible data range: - begin = mDataContainer->findBegin(keyAxis->range().lower); - end = mDataContainer->findEnd(keyAxis->range().upper); + begin = mDataContainer->findBegin( keyAxis->range().lower ); + end = mDataContainer->findEnd( keyAxis->range().upper ); // limit lower/upperEnd to rangeRestriction: - mDataContainer->limitIteratorsToDataRange(begin, end, rangeRestriction); // this also ensures rangeRestriction outside data bounds doesn't break anything + mDataContainer->limitIteratorsToDataRange( begin, end, rangeRestriction ); // this also ensures rangeRestriction outside data bounds doesn't break anything } } @@ -21206,41 +21402,42 @@ void QCPGraph::getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin \see getOverlappingSegments, drawFill */ -QVector QCPGraph::getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const +QVector QCPGraph::getNonNanSegments( const QVector* lineData, Qt::Orientation keyOrientation ) const { QVector result; const int n = lineData->size(); - - QCPDataRange currentSegment(-1, -1); + + QCPDataRange currentSegment( -1, -1 ); int i = 0; - - if (keyOrientation == Qt::Horizontal) + + if( keyOrientation == Qt::Horizontal ) { - while (i < n) + while( i < n ) { - while (i < n && qIsNaN(lineData->at(i).y())) // seek next non-NaN data point + while( i < n && qIsNaN( lineData->at( i ).y() ) ) // seek next non-NaN data point ++i; - if (i == n) + if( i == n ) break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).y())) // seek next NaN data point or end of data + currentSegment.setBegin( i++ ); + while( i < n && !qIsNaN( lineData->at( i ).y() ) ) // seek next NaN data point or end of data ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); + currentSegment.setEnd( i++ ); + result.append( currentSegment ); } - } else // keyOrientation == Qt::Vertical + } + else // keyOrientation == Qt::Vertical { - while (i < n) + while( i < n ) { - while (i < n && qIsNaN(lineData->at(i).x())) // seek next non-NaN data point + while( i < n && qIsNaN( lineData->at( i ).x() ) ) // seek next non-NaN data point ++i; - if (i == n) + if( i == n ) break; - currentSegment.setBegin(i++); - while (i < n && !qIsNaN(lineData->at(i).x())) // seek next NaN data point or end of data + currentSegment.setBegin( i++ ); + while( i < n && !qIsNaN( lineData->at( i ).x() ) ) // seek next NaN data point or end of data ++i; - currentSegment.setEnd(i++); - result.append(currentSegment); + currentSegment.setEnd( i++ ); + result.append( currentSegment ); } } return result; @@ -21264,52 +21461,53 @@ QVector QCPGraph::getNonNanSegments(const QVector *lineDa \see getNonNanSegments, segmentsIntersect, drawFill, getChannelFillPolygon */ -QVector > QCPGraph::getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const +QVector > QCPGraph::getOverlappingSegments( QVector thisSegments, const QVector* thisData, QVector otherSegments, const QVector* otherData ) const { QVector > result; - if (thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty()) + if( thisData->isEmpty() || otherData->isEmpty() || thisSegments.isEmpty() || otherSegments.isEmpty() ) return result; - + int thisIndex = 0; int otherIndex = 0; const bool verticalKey = mKeyAxis->orientation() == Qt::Vertical; - while (thisIndex < thisSegments.size() && otherIndex < otherSegments.size()) + while( thisIndex < thisSegments.size() && otherIndex < otherSegments.size() ) { - if (thisSegments.at(thisIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + if( thisSegments.at( thisIndex ).size() < 2 ) // segments with fewer than two points won't have a fill anyhow { ++thisIndex; continue; } - if (otherSegments.at(otherIndex).size() < 2) // segments with fewer than two points won't have a fill anyhow + if( otherSegments.at( otherIndex ).size() < 2 ) // segments with fewer than two points won't have a fill anyhow { ++otherIndex; continue; } double thisLower, thisUpper, otherLower, otherUpper; - if (!verticalKey) + if( !verticalKey ) { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).x(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).x(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).x(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).x(); - } else - { - thisLower = thisData->at(thisSegments.at(thisIndex).begin()).y(); - thisUpper = thisData->at(thisSegments.at(thisIndex).end()-1).y(); - otherLower = otherData->at(otherSegments.at(otherIndex).begin()).y(); - otherUpper = otherData->at(otherSegments.at(otherIndex).end()-1).y(); + thisLower = thisData->at( thisSegments.at( thisIndex ).begin() ).x(); + thisUpper = thisData->at( thisSegments.at( thisIndex ).end() - 1 ).x(); + otherLower = otherData->at( otherSegments.at( otherIndex ).begin() ).x(); + otherUpper = otherData->at( otherSegments.at( otherIndex ).end() - 1 ).x(); } - + else + { + thisLower = thisData->at( thisSegments.at( thisIndex ).begin() ).y(); + thisUpper = thisData->at( thisSegments.at( thisIndex ).end() - 1 ).y(); + otherLower = otherData->at( otherSegments.at( otherIndex ).begin() ).y(); + otherUpper = otherData->at( otherSegments.at( otherIndex ).end() - 1 ).y(); + } + int bPrecedence; - if (segmentsIntersect(thisLower, thisUpper, otherLower, otherUpper, bPrecedence)) - result.append(QPair(thisSegments.at(thisIndex), otherSegments.at(otherIndex))); - - if (bPrecedence <= 0) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment + if( segmentsIntersect( thisLower, thisUpper, otherLower, otherUpper, bPrecedence ) ) + result.append( QPair( thisSegments.at( thisIndex ), otherSegments.at( otherIndex ) ) ); + + if( bPrecedence <= 0 ) // otherSegment doesn't reach as far as thisSegment, so continue with next otherSegment, keeping current thisSegment ++otherIndex; - else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment + else // otherSegment reaches further than thisSegment, so continue with next thisSegment, keeping current otherSegment ++thisIndex; } - + return result; } @@ -21327,24 +21525,26 @@ QVector > QCPGraph::getOverlappingSegments(QVe \see getOverlappingSegments */ -bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const +bool QCPGraph::segmentsIntersect( double aLower, double aUpper, double bLower, double bUpper, int& bPrecedence ) const { bPrecedence = 0; - if (aLower > bUpper) + if( aLower > bUpper ) { bPrecedence = -1; return false; - } else if (bLower > aUpper) + } + else if( bLower > aUpper ) { bPrecedence = 1; return false; - } else + } + else { - if (aUpper > bUpper) + if( aUpper > bUpper ) bPrecedence = -1; - else if (aUpper < bUpper) + else if( aUpper < bUpper ) bPrecedence = 1; - + return true; } } @@ -21360,44 +21560,51 @@ bool QCPGraph::segmentsIntersect(double aLower, double aUpper, double bLower, do the key axis of this graph is horizontal or vertical, \a matchingDataPoint will provide the x or y value of the returned point, respectively. */ -QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const +QPointF QCPGraph::getFillBasePoint( QPointF matchingDataPoint ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - QPointF result; - if (valueAxis->scaleType() == QCPAxis::stLinear) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - if (keyAxis->orientation() == Qt::Horizontal) + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QPointF(); + } + + QPointF result; + if( valueAxis->scaleType() == QCPAxis::stLinear ) + { + if( keyAxis->orientation() == Qt::Horizontal ) { - result.setX(matchingDataPoint.x()); - result.setY(valueAxis->coordToPixel(0)); - } else // keyAxis->orientation() == Qt::Vertical - { - result.setX(valueAxis->coordToPixel(0)); - result.setY(matchingDataPoint.y()); + result.setX( matchingDataPoint.x() ); + result.setY( valueAxis->coordToPixel( 0 ) ); } - } else // valueAxis->mScaleType == QCPAxis::stLogarithmic + else // keyAxis->orientation() == Qt::Vertical + { + result.setX( valueAxis->coordToPixel( 0 ) ); + result.setY( matchingDataPoint.y() ); + } + } + else // valueAxis->mScaleType == QCPAxis::stLogarithmic { // In logarithmic scaling we can't just draw to value 0 so we just fill all the way // to the axis which is in the direction towards 0 - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setX(keyAxis->axisRect()->right()); + if( ( valueAxis->range().upper < 0 && !valueAxis->rangeReversed() ) || + ( valueAxis->range().upper > 0 && valueAxis->rangeReversed() ) ) // if range is negative, zero is on opposite side of key axis + result.setX( keyAxis->axisRect()->right() ); else - result.setX(keyAxis->axisRect()->left()); - result.setY(matchingDataPoint.y()); - } else if (keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom) + result.setX( keyAxis->axisRect()->left() ); + result.setY( matchingDataPoint.y() ); + } + else if( keyAxis->axisType() == QCPAxis::atTop || keyAxis->axisType() == QCPAxis::atBottom ) { - result.setX(matchingDataPoint.x()); - if ((valueAxis->range().upper < 0 && !valueAxis->rangeReversed()) || - (valueAxis->range().upper > 0 && valueAxis->rangeReversed())) // if range is negative, zero is on opposite side of key axis - result.setY(keyAxis->axisRect()->top()); + result.setX( matchingDataPoint.x() ); + if( ( valueAxis->range().upper < 0 && !valueAxis->rangeReversed() ) || + ( valueAxis->range().upper > 0 && valueAxis->rangeReversed() ) ) // if range is negative, zero is on opposite side of key axis + result.setY( keyAxis->axisRect()->top() ); else - result.setY(keyAxis->axisRect()->bottom()); + result.setY( keyAxis->axisRect()->bottom() ); } } return result; @@ -21419,16 +21626,16 @@ QPointF QCPGraph::getFillBasePoint(QPointF matchingDataPoint) const \see drawFill, getNonNanSegments */ -const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDataRange segment) const +const QPolygonF QCPGraph::getFillPolygon( const QVector* lineData, QCPDataRange segment ) const { - if (segment.size() < 2) + if( segment.size() < 2 ) return QPolygonF(); - QPolygonF result(segment.size()+2); - - result[0] = getFillBasePoint(lineData->at(segment.begin())); - std::copy(lineData->constBegin()+segment.begin(), lineData->constBegin()+segment.end(), result.begin()+1); - result[result.size()-1] = getFillBasePoint(lineData->at(segment.end()-1)); - + QPolygonF result( segment.size() + 2 ); + + result[0] = getFillBasePoint( lineData->at( segment.begin() ) ); + std::copy( lineData->constBegin() + segment.begin(), lineData->constBegin() + segment.end(), result.begin() + 1 ); + result[result.size() - 1] = getFillBasePoint( lineData->at( segment.end() - 1 ) ); + return result; } @@ -21450,103 +21657,121 @@ const QPolygonF QCPGraph::getFillPolygon(const QVector *lineData, QCPDa \see drawFill, getOverlappingSegments, getNonNanSegments */ -const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const +const QPolygonF QCPGraph::getChannelFillPolygon( const QVector* thisData, QCPDataRange thisSegment, const QVector* otherData, QCPDataRange otherSegment ) const { - if (!mChannelFillGraph) + if( !mChannelFillGraph ) return QPolygonF(); - - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPolygonF(); } - if (!mChannelFillGraph.data()->mKeyAxis) { qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; return QPolygonF(); } - - if (mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation()) - return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) - - if (thisData->isEmpty()) return QPolygonF(); - QVector thisSegmentData(thisSegment.size()); - QVector otherSegmentData(otherSegment.size()); - std::copy(thisData->constBegin()+thisSegment.begin(), thisData->constBegin()+thisSegment.end(), thisSegmentData.begin()); - std::copy(otherData->constBegin()+otherSegment.begin(), otherData->constBegin()+otherSegment.end(), otherSegmentData.begin()); + + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QPolygonF(); + } + if( !mChannelFillGraph.data()->mKeyAxis ) + { + qDebug() << Q_FUNC_INFO << "channel fill target key axis invalid"; + return QPolygonF(); + } + + if( mChannelFillGraph.data()->mKeyAxis.data()->orientation() != keyAxis->orientation() ) + return QPolygonF(); // don't have same axis orientation, can't fill that (Note: if keyAxis fits, valueAxis will fit too, because it's always orthogonal to keyAxis) + + if( thisData->isEmpty() ) + return QPolygonF(); + QVector thisSegmentData( thisSegment.size() ); + QVector otherSegmentData( otherSegment.size() ); + std::copy( thisData->constBegin() + thisSegment.begin(), thisData->constBegin() + thisSegment.end(), thisSegmentData.begin() ); + std::copy( otherData->constBegin() + otherSegment.begin(), otherData->constBegin() + otherSegment.end(), otherSegmentData.begin() ); // pointers to be able to swap them, depending which data range needs cropping: - QVector *staticData = &thisSegmentData; - QVector *croppedData = &otherSegmentData; - + QVector* staticData = &thisSegmentData; + QVector* croppedData = &otherSegmentData; + // crop both vectors to ranges in which the keys overlap (which coord is key, depends on axisType): - if (keyAxis->orientation() == Qt::Horizontal) + if( keyAxis->orientation() == Qt::Horizontal ) { // x is key // crop lower bound: - if (staticData->first().x() < croppedData->first().x()) // other one must be cropped - qSwap(staticData, croppedData); - const int lowBound = findIndexBelowX(croppedData, staticData->first().x()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); + if( staticData->first().x() < croppedData->first().x() ) // other one must be cropped + qSwap( staticData, croppedData ); + const int lowBound = findIndexBelowX( croppedData, staticData->first().x() ); + if( lowBound == -1 ) + return QPolygonF(); // key ranges have no overlap + croppedData->remove( 0, lowBound ); // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + if( croppedData->size() < 2 ) + return QPolygonF(); // need at least two points for interpolation double slope; - if (!qFuzzyCompare(croppedData->at(1).x(), croppedData->at(0).x())) - slope = (croppedData->at(1).y()-croppedData->at(0).y())/(croppedData->at(1).x()-croppedData->at(0).x()); + if( !qFuzzyCompare( croppedData->at( 1 ).x(), croppedData->at( 0 ).x() ) ) + slope = ( croppedData->at( 1 ).y() - croppedData->at( 0 ).y() ) / ( croppedData->at( 1 ).x() - croppedData->at( 0 ).x() ); else slope = 0; - (*croppedData)[0].setY(croppedData->at(0).y()+slope*(staticData->first().x()-croppedData->at(0).x())); - (*croppedData)[0].setX(staticData->first().x()); - + ( *croppedData )[0].setY( croppedData->at( 0 ).y() + slope * ( staticData->first().x() - croppedData->at( 0 ).x() ) ); + ( *croppedData )[0].setX( staticData->first().x() ); + // crop upper bound: - if (staticData->last().x() > croppedData->last().x()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveX(croppedData, staticData->last().x()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + if( staticData->last().x() > croppedData->last().x() ) // other one must be cropped + qSwap( staticData, croppedData ); + int highBound = findIndexAboveX( croppedData, staticData->last().x() ); + if( highBound == -1 ) + return QPolygonF(); // key ranges have no overlap + croppedData->remove( highBound + 1, croppedData->size() - ( highBound + 1 ) ); // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - const int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).x(), croppedData->at(li-1).x())) - slope = (croppedData->at(li).y()-croppedData->at(li-1).y())/(croppedData->at(li).x()-croppedData->at(li-1).x()); + if( croppedData->size() < 2 ) + return QPolygonF(); // need at least two points for interpolation + const int li = croppedData->size() - 1; // last index + if( !qFuzzyCompare( croppedData->at( li ).x(), croppedData->at( li - 1 ).x() ) ) + slope = ( croppedData->at( li ).y() - croppedData->at( li - 1 ).y() ) / ( croppedData->at( li ).x() - croppedData->at( li - 1 ).x() ); else slope = 0; - (*croppedData)[li].setY(croppedData->at(li-1).y()+slope*(staticData->last().x()-croppedData->at(li-1).x())); - (*croppedData)[li].setX(staticData->last().x()); - } else // mKeyAxis->orientation() == Qt::Vertical + ( *croppedData )[li].setY( croppedData->at( li - 1 ).y() + slope * ( staticData->last().x() - croppedData->at( li - 1 ).x() ) ); + ( *croppedData )[li].setX( staticData->last().x() ); + } + else // mKeyAxis->orientation() == Qt::Vertical { // y is key // crop lower bound: - if (staticData->first().y() < croppedData->first().y()) // other one must be cropped - qSwap(staticData, croppedData); - int lowBound = findIndexBelowY(croppedData, staticData->first().y()); - if (lowBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(0, lowBound); + if( staticData->first().y() < croppedData->first().y() ) // other one must be cropped + qSwap( staticData, croppedData ); + int lowBound = findIndexBelowY( croppedData, staticData->first().y() ); + if( lowBound == -1 ) + return QPolygonF(); // key ranges have no overlap + croppedData->remove( 0, lowBound ); // set lowest point of cropped data to fit exactly key position of first static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation + if( croppedData->size() < 2 ) + return QPolygonF(); // need at least two points for interpolation double slope; - if (!qFuzzyCompare(croppedData->at(1).y(), croppedData->at(0).y())) // avoid division by zero in step plots - slope = (croppedData->at(1).x()-croppedData->at(0).x())/(croppedData->at(1).y()-croppedData->at(0).y()); + if( !qFuzzyCompare( croppedData->at( 1 ).y(), croppedData->at( 0 ).y() ) ) // avoid division by zero in step plots + slope = ( croppedData->at( 1 ).x() - croppedData->at( 0 ).x() ) / ( croppedData->at( 1 ).y() - croppedData->at( 0 ).y() ); else slope = 0; - (*croppedData)[0].setX(croppedData->at(0).x()+slope*(staticData->first().y()-croppedData->at(0).y())); - (*croppedData)[0].setY(staticData->first().y()); - + ( *croppedData )[0].setX( croppedData->at( 0 ).x() + slope * ( staticData->first().y() - croppedData->at( 0 ).y() ) ); + ( *croppedData )[0].setY( staticData->first().y() ); + // crop upper bound: - if (staticData->last().y() > croppedData->last().y()) // other one must be cropped - qSwap(staticData, croppedData); - int highBound = findIndexAboveY(croppedData, staticData->last().y()); - if (highBound == -1) return QPolygonF(); // key ranges have no overlap - croppedData->remove(highBound+1, croppedData->size()-(highBound+1)); + if( staticData->last().y() > croppedData->last().y() ) // other one must be cropped + qSwap( staticData, croppedData ); + int highBound = findIndexAboveY( croppedData, staticData->last().y() ); + if( highBound == -1 ) + return QPolygonF(); // key ranges have no overlap + croppedData->remove( highBound + 1, croppedData->size() - ( highBound + 1 ) ); // set highest point of cropped data to fit exactly key position of last static data point via linear interpolation: - if (croppedData->size() < 2) return QPolygonF(); // need at least two points for interpolation - int li = croppedData->size()-1; // last index - if (!qFuzzyCompare(croppedData->at(li).y(), croppedData->at(li-1).y())) // avoid division by zero in step plots - slope = (croppedData->at(li).x()-croppedData->at(li-1).x())/(croppedData->at(li).y()-croppedData->at(li-1).y()); + if( croppedData->size() < 2 ) + return QPolygonF(); // need at least two points for interpolation + int li = croppedData->size() - 1; // last index + if( !qFuzzyCompare( croppedData->at( li ).y(), croppedData->at( li - 1 ).y() ) ) // avoid division by zero in step plots + slope = ( croppedData->at( li ).x() - croppedData->at( li - 1 ).x() ) / ( croppedData->at( li ).y() - croppedData->at( li - 1 ).y() ); else slope = 0; - (*croppedData)[li].setX(croppedData->at(li-1).x()+slope*(staticData->last().y()-croppedData->at(li-1).y())); - (*croppedData)[li].setY(staticData->last().y()); + ( *croppedData )[li].setX( croppedData->at( li - 1 ).x() + slope * ( staticData->last().y() - croppedData->at( li - 1 ).y() ) ); + ( *croppedData )[li].setY( staticData->last().y() ); } - + // return joined: - for (int i=otherSegmentData.size()-1; i>=0; --i) // insert reversed, otherwise the polygon will be twisted - thisSegmentData << otherSegmentData.at(i); - return QPolygonF(thisSegmentData); + for( int i = otherSegmentData.size() - 1; i >= 0; --i ) // insert reversed, otherwise the polygon will be twisted + thisSegmentData << otherSegmentData.at( i ); + return QPolygonF( thisSegmentData ); } /*! \internal @@ -21557,16 +21782,16 @@ const QPolygonF QCPGraph::getChannelFillPolygon(const QVector *thisData Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. */ -int QCPGraph::findIndexAboveX(const QVector *data, double x) const +int QCPGraph::findIndexAboveX( const QVector* data, double x ) const { - for (int i=data->size()-1; i>=0; --i) + for( int i = data->size() - 1; i >= 0; --i ) { - if (data->at(i).x() < x) + if( data->at( i ).x() < x ) { - if (isize()-1) - return i+1; + if( i < data->size() - 1 ) + return i + 1; else - return data->size()-1; + return data->size() - 1; } } return -1; @@ -21580,14 +21805,14 @@ int QCPGraph::findIndexAboveX(const QVector *data, double x) const Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. */ -int QCPGraph::findIndexBelowX(const QVector *data, double x) const +int QCPGraph::findIndexBelowX( const QVector* data, double x ) const { - for (int i=0; isize(); ++i) + for( int i = 0; i < data->size(); ++i ) { - if (data->at(i).x() > x) + if( data->at( i ).x() > x ) { - if (i>0) - return i-1; + if( i > 0 ) + return i - 1; else return 0; } @@ -21603,16 +21828,16 @@ int QCPGraph::findIndexBelowX(const QVector *data, double x) const Used to calculate the channel fill polygon, see \ref getChannelFillPolygon. */ -int QCPGraph::findIndexAboveY(const QVector *data, double y) const +int QCPGraph::findIndexAboveY( const QVector* data, double y ) const { - for (int i=data->size()-1; i>=0; --i) + for( int i = data->size() - 1; i >= 0; --i ) { - if (data->at(i).y() < y) + if( data->at( i ).y() < y ) { - if (isize()-1) - return i+1; + if( i < data->size() - 1 ) + return i + 1; else - return data->size()-1; + return data->size() - 1; } } return -1; @@ -21629,52 +21854,52 @@ int QCPGraph::findIndexAboveY(const QVector *data, double y) const If either the graph has no data or if the line style is \ref lsNone and the scatter style's shape is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the graph), returns -1.0. */ -double QCPGraph::pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const +double QCPGraph::pointDistance( const QPointF& pixelPoint, QCPGraphDataContainer::const_iterator& closestData ) const { closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) + if( mDataContainer->isEmpty() ) return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) + if( mLineStyle == lsNone && mScatterStyle.isNone() ) return -1.0; - + // calculate minimum distances to graph data points and find closestData iterator: - double minDistSqr = (std::numeric_limits::max)(); + double minDistSqr = ( std::numeric_limits::max )(); // determine which key range comes into question, taking selection tolerance around pos into account: double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pixelPoint-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pixelPoint+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); + pixelsToCoords( pixelPoint - QPointF( mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance() ), posKeyMin, dummy ); + pixelsToCoords( pixelPoint + QPointF( mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance() ), posKeyMax, dummy ); + if( posKeyMin > posKeyMax ) + qSwap( posKeyMin, posKeyMax ); // iterate over found data points and then choose the one with the shortest distance to pos: - QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); - QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); - for (QCPGraphDataContainer::const_iterator it=begin; it!=end; ++it) + QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin( posKeyMin, true ); + QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd( posKeyMax, true ); + for( QCPGraphDataContainer::const_iterator it = begin; it != end; ++it ) { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) + const double currentDistSqr = QCPVector2D( coordsToPixels( it->key, it->value ) - pixelPoint ).lengthSquared(); + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestData = it; } } - + // calculate distance to graph line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { // line displayed, calculate distance to line segments: QVector lineData; - getLines(&lineData, QCPDataRange(0, dataCount())); - QCPVector2D p(pixelPoint); - const int step = mLineStyle==lsImpulse ? 2 : 1; // impulse plot differs from other line styles in that the lineData points are only pairwise connected - for (int i=0; i *data, double y) const +int QCPGraph::findIndexBelowY( const QVector* data, double y ) const { - for (int i=0; isize(); ++i) + for( int i = 0; i < data->size(); ++i ) { - if (data->at(i).y() > y) + if( data->at( i ).y() > y ) { - if (i>0) - return i-1; + if( i > 0 ) + return i - 1; else return 0; } @@ -21701,7 +21926,6 @@ int QCPGraph::findIndexBelowY(const QVector *data, double y) const } /* end of 'src/plottables/plottable-graph.cpp' */ - /* including file 'src/plottables/plottable-curve.cpp', size 63742 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -21781,24 +22005,19 @@ int QCPGraph::findIndexBelowY(const QVector *data, double y) const /*! Constructs a curve data point with t, key and value set to zero. */ -QCPCurveData::QCPCurveData() : - t(0), - key(0), - value(0) +QCPCurveData::QCPCurveData() + : t( 0 ), key( 0 ), value( 0 ) { } /*! Constructs a curve data point with the specified \a t, \a key and \a value. */ -QCPCurveData::QCPCurveData(double t, double key, double value) : - t(t), - key(key), - value(value) +QCPCurveData::QCPCurveData( double t, double key, double value ) + : t( t ), key( key ), value( value ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPCurve //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -21860,16 +22079,16 @@ QCPCurveData::QCPCurveData(double t, double key, double value) : keyAxis. This QCustomPlot instance takes ownership of the QCPCurve, so do not delete it manually but use QCustomPlot::removePlottable() instead. */ -QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis) +QCPCurve::QCPCurve( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable1D( keyAxis, valueAxis ) { // modify inherited properties from abstract plottable: - setPen(QPen(Qt::blue, 0)); - setBrush(Qt::NoBrush); - - setScatterStyle(QCPScatterStyle()); - setLineStyle(lsLine); - setScatterSkip(0); + setPen( QPen( Qt::blue, 0 ) ); + setBrush( Qt::NoBrush ); + + setScatterStyle( QCPScatterStyle() ); + setLineStyle( lsLine ); + setScatterSkip( 0 ); } QCPCurve::~QCPCurve() @@ -21891,7 +22110,7 @@ QCPCurve::~QCPCurve() \see addData */ -void QCPCurve::setData(QSharedPointer data) +void QCPCurve::setData( QSharedPointer data ) { mDataContainer = data; } @@ -21907,13 +22126,12 @@ void QCPCurve::setData(QSharedPointer data) \see addData */ -void QCPCurve::setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +void QCPCurve::setData( const QVector& t, const QVector& keys, const QVector& values, bool alreadySorted ) { mDataContainer->clear(); - addData(t, keys, values, alreadySorted); + addData( t, keys, values, alreadySorted ); } - /*! \overload Replaces the current data with the provided points in \a keys and \a values. The provided vectors @@ -21925,10 +22143,10 @@ void QCPCurve::setData(const QVector &t, const QVector &keys, co \see addData */ -void QCPCurve::setData(const QVector &keys, const QVector &values) +void QCPCurve::setData( const QVector& keys, const QVector& values ) { mDataContainer->clear(); - addData(keys, values); + addData( keys, values ); } /*! @@ -21938,7 +22156,7 @@ void QCPCurve::setData(const QVector &keys, const QVector &value \see QCPScatterStyle, setLineStyle */ -void QCPCurve::setScatterStyle(const QCPScatterStyle &style) +void QCPCurve::setScatterStyle( const QCPScatterStyle& style ) { mScatterStyle = style; } @@ -21954,9 +22172,9 @@ void QCPCurve::setScatterStyle(const QCPScatterStyle &style) \see setScatterStyle */ -void QCPCurve::setScatterSkip(int skip) +void QCPCurve::setScatterSkip( int skip ) { - mScatterSkip = qMax(0, skip); + mScatterSkip = qMax( 0, skip ); } /*! @@ -21966,7 +22184,7 @@ void QCPCurve::setScatterSkip(int skip) \see setScatterStyle */ -void QCPCurve::setLineStyle(QCPCurve::LineStyle style) +void QCPCurve::setLineStyle( QCPCurve::LineStyle style ) { mLineStyle = style; } @@ -21983,16 +22201,16 @@ void QCPCurve::setLineStyle(QCPCurve::LineStyle style) Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPCurve::addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted) +void QCPCurve::addData( const QVector& t, const QVector& keys, const QVector& values, bool alreadySorted ) { - if (t.size() != keys.size() || t.size() != values.size()) + if( t.size() != keys.size() || t.size() != values.size() ) qDebug() << Q_FUNC_INFO << "ts, keys and values have different sizes:" << t.size() << keys.size() << values.size(); - const int n = qMin(qMin(t.size(), keys.size()), values.size()); - QVector tempData(n); + const int n = qMin( qMin( t.size(), keys.size() ), values.size() ); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->t = t[i]; it->key = keys[i]; @@ -22000,7 +22218,7 @@ void QCPCurve::addData(const QVector &t, const QVector &keys, co ++it; ++i; } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, alreadySorted ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -22015,21 +22233,21 @@ void QCPCurve::addData(const QVector &t, const QVector &keys, co Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPCurve::addData(const QVector &keys, const QVector &values) +void QCPCurve::addData( const QVector& keys, const QVector& values ) { - if (keys.size() != values.size()) + if( keys.size() != values.size() ) qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); + const int n = qMin( keys.size(), values.size() ); double tStart; - if (!mDataContainer->isEmpty()) - tStart = (mDataContainer->constEnd()-1)->t + 1.0; + if( !mDataContainer->isEmpty() ) + tStart = ( mDataContainer->constEnd() - 1 )->t + 1.0; else tStart = 0; - QVector tempData(n); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->t = tStart + i; it->key = keys[i]; @@ -22037,7 +22255,7 @@ void QCPCurve::addData(const QVector &keys, const QVector &value ++it; ++i; } - mDataContainer->add(tempData, true); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, true ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -22046,9 +22264,9 @@ void QCPCurve::addData(const QVector &keys, const QVector &value Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPCurve::addData(double t, double key, double value) +void QCPCurve::addData( double t, double key, double value ) { - mDataContainer->add(QCPCurveData(t, key, value)); + mDataContainer->add( QCPCurveData( t, key, value ) ); } /*! \overload @@ -22061,12 +22279,12 @@ void QCPCurve::addData(double t, double key, double value) Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPCurve::addData(double key, double value) +void QCPCurve::addData( double key, double value ) { - if (!mDataContainer->isEmpty()) - mDataContainer->add(QCPCurveData((mDataContainer->constEnd()-1)->t + 1.0, key, value)); + if( !mDataContainer->isEmpty() ) + mDataContainer->add( QCPCurveData( ( mDataContainer->constEnd() - 1 )->t + 1.0, key, value ) ); else - mDataContainer->add(QCPCurveData(0.0, key, value)); + mDataContainer->add( QCPCurveData( 0.0, key, value ) ); } /*! @@ -22077,138 +22295,142 @@ void QCPCurve::addData(double key, double value) \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPCurve::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) + double result = pointDistance( pos, closestDataPoint ); + if( details ) { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = closestDataPoint - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } return result; - } else + } + else return -1; } /* inherits documentation from base class */ -QCPRange QCPCurve::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPCurve::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { - return mDataContainer->keyRange(foundRange, inSignDomain); + return mDataContainer->keyRange( foundRange, inSignDomain ); } /* inherits documentation from base class */ -QCPRange QCPCurve::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPCurve::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); + return mDataContainer->valueRange( foundRange, inSignDomain, inKeyRange ); } /* inherits documentation from base class */ -void QCPCurve::draw(QCPPainter *painter) +void QCPCurve::draw( QCPPainter* painter ) { - if (mDataContainer->isEmpty()) return; - + if( mDataContainer->isEmpty() ) + return; + // allocate line vector: QVector lines, scatters; - + // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); - + // fill with curve data: - QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width - if (isSelectedSegment && mSelectionDecorator) + QPen finalCurvePen = mPen; // determine the final pen already here, because the line optimization depends on its stroke width + if( isSelectedSegment && mSelectionDecorator ) finalCurvePen = mSelectionDecorator->pen(); - - QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at(i) : allSegments.at(i).adjusted(-1, 1); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) - getCurveLines(&lines, lineDataRange, finalCurvePen.widthF()); - + + QCPDataRange lineDataRange = isSelectedSegment ? allSegments.at( i ) : allSegments.at( i ).adjusted( -1, 1 ); // unselected segments extend lines to bordering selected data point (safe to exceed total data bounds in first/last segment, getCurveLines takes care) + getCurveLines( &lines, lineDataRange, finalCurvePen.widthF() ); + // check data validity if flag set: - #ifdef QCUSTOMPLOT_CHECK_DATA - for (QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) +#ifdef QCUSTOMPLOT_CHECK_DATA + for( QCPCurveDataContainer::const_iterator it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it ) { - if (QCP::isInvalidData(it->t) || - QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." << "Plottable name:" << name(); + if( QCP::isInvalidData( it->t ) || + QCP::isInvalidData( it->key, it->value ) ) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "invalid." + << "Plottable name:" << name(); } - #endif - +#endif + // draw curve fill: - applyFillAntialiasingHint(painter); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyBrush(painter); + applyFillAntialiasingHint( painter ); + if( isSelectedSegment && mSelectionDecorator ) + mSelectionDecorator->applyBrush( painter ); else - painter->setBrush(mBrush); - painter->setPen(Qt::NoPen); - if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) - painter->drawPolygon(QPolygonF(lines)); - + painter->setBrush( mBrush ); + painter->setPen( Qt::NoPen ); + if( painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0 ) + painter->drawPolygon( QPolygonF( lines ) ); + // draw curve line: - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { - painter->setPen(finalCurvePen); - painter->setBrush(Qt::NoBrush); - drawCurveLine(painter, lines); + painter->setPen( finalCurvePen ); + painter->setBrush( Qt::NoBrush ); + drawCurveLine( painter, lines ); } - + // draw scatters: QCPScatterStyle finalScatterStyle = mScatterStyle; - if (isSelectedSegment && mSelectionDecorator) - finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if (!finalScatterStyle.isNone()) + if( isSelectedSegment && mSelectionDecorator ) + finalScatterStyle = mSelectionDecorator->getFinalScatterStyle( mScatterStyle ); + if( !finalScatterStyle.isNone() ) { - getScatters(&scatters, allSegments.at(i), finalScatterStyle.size()); - drawScatterPlot(painter, scatters, finalScatterStyle); + getScatters( &scatters, allSegments.at( i ), finalScatterStyle.size() ); + drawScatterPlot( painter, scatters, finalScatterStyle ); } } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPCurve::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { // draw fill: - if (mBrush.style() != Qt::NoBrush) + if( mBrush.style() != Qt::NoBrush ) { - applyFillAntialiasingHint(painter); - painter->fillRect(QRectF(rect.left(), rect.top()+rect.height()/2.0, rect.width(), rect.height()/3.0), mBrush); + applyFillAntialiasingHint( painter ); + painter->fillRect( QRectF( rect.left(), rect.top() + rect.height() / 2.0, rect.width(), rect.height() / 3.0 ), mBrush ); } // draw line vertically centered: - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->drawLine(QLineF(rect.left(), rect.top()+rect.height()/2.0, rect.right()+5, rect.top()+rect.height()/2.0)); // +5 on x2 else last segment is missing from dashed/dotted pens + applyDefaultAntialiasingHint( painter ); + painter->setPen( mPen ); + painter->drawLine( QLineF( rect.left(), rect.top() + rect.height() / 2.0, rect.right() + 5, rect.top() + rect.height() / 2.0 ) ); // +5 on x2 else last segment is missing from dashed/dotted pens } // draw scatter symbol: - if (!mScatterStyle.isNone()) + if( !mScatterStyle.isNone() ) { - applyScattersAntialiasingHint(painter); + applyScattersAntialiasingHint( painter ); // scale scatter pixmap if it's too large to fit in legend icon rect: - if (mScatterStyle.shape() == QCPScatterStyle::ssPixmap && (mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height())) + if( mScatterStyle.shape() == QCPScatterStyle::ssPixmap && ( mScatterStyle.pixmap().size().width() > rect.width() || mScatterStyle.pixmap().size().height() > rect.height() ) ) { - QCPScatterStyle scaledStyle(mScatterStyle); - scaledStyle.setPixmap(scaledStyle.pixmap().scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - scaledStyle.applyTo(painter, mPen); - scaledStyle.drawShape(painter, QRectF(rect).center()); - } else + QCPScatterStyle scaledStyle( mScatterStyle ); + scaledStyle.setPixmap( scaledStyle.pixmap().scaled( rect.size().toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); + scaledStyle.applyTo( painter, mPen ); + scaledStyle.drawShape( painter, QRectF( rect ).center() ); + } + else { - mScatterStyle.applyTo(painter, mPen); - mScatterStyle.drawShape(painter, QRectF(rect).center()); + mScatterStyle.applyTo( painter, mPen ); + mScatterStyle.drawShape( painter, QRectF( rect ).center() ); } } } @@ -22219,12 +22441,12 @@ void QCPCurve::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const \see drawScatterPlot, getCurveLines */ -void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) const +void QCPCurve::drawCurveLine( QCPPainter* painter, const QVector& lines ) const { - if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0) + if( painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0 ) { - applyDefaultAntialiasingHint(painter); - drawPolyline(painter, lines); + applyDefaultAntialiasingHint( painter ); + drawPolyline( painter, lines ); } } @@ -22235,14 +22457,14 @@ void QCPCurve::drawCurveLine(QCPPainter *painter, const QVector &lines) \see drawCurveLine, getCurveLines */ -void QCPCurve::drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const +void QCPCurve::drawScatterPlot( QCPPainter* painter, const QVector& points, const QCPScatterStyle& style ) const { // draw scatter point symbols: - applyScattersAntialiasingHint(painter); - style.applyTo(painter, mPen); - for (int i=0; i &poin \see drawCurveLine, drawScatterPlot */ -void QCPCurve::getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const +void QCPCurve::getCurveLines( QVector* lines, const QCPDataRange& dataRange, double penWidth ) const { - if (!lines) return; + if( !lines ) + return; lines->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + // add margins to rect to compensate for stroke width - const double strokeMargin = qMax(qreal(1.0), qreal(penWidth*0.75)); // stroke radius + 50% safety - const double keyMin = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().lower)-strokeMargin*keyAxis->pixelOrientation()); - const double keyMax = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyAxis->range().upper)+strokeMargin*keyAxis->pixelOrientation()); - const double valueMin = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().lower)-strokeMargin*valueAxis->pixelOrientation()); - const double valueMax = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueAxis->range().upper)+strokeMargin*valueAxis->pixelOrientation()); + const double strokeMargin = qMax( qreal( 1.0 ), qreal( penWidth * 0.75 ) ); // stroke radius + 50% safety + const double keyMin = keyAxis->pixelToCoord( keyAxis->coordToPixel( keyAxis->range().lower ) - strokeMargin * keyAxis->pixelOrientation() ); + const double keyMax = keyAxis->pixelToCoord( keyAxis->coordToPixel( keyAxis->range().upper ) + strokeMargin * keyAxis->pixelOrientation() ); + const double valueMin = valueAxis->pixelToCoord( valueAxis->coordToPixel( valueAxis->range().lower ) - strokeMargin * valueAxis->pixelOrientation() ); + const double valueMax = valueAxis->pixelToCoord( valueAxis->coordToPixel( valueAxis->range().upper ) + strokeMargin * valueAxis->pixelOrientation() ); QCPCurveDataContainer::const_iterator itBegin = mDataContainer->constBegin(); QCPCurveDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(itBegin, itEnd, dataRange); - if (itBegin == itEnd) + mDataContainer->limitIteratorsToDataRange( itBegin, itEnd, dataRange ); + if( itBegin == itEnd ) return; QCPCurveDataContainer::const_iterator it = itBegin; - QCPCurveDataContainer::const_iterator prevIt = itEnd-1; - int prevRegion = getRegion(prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin); - QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) - while (it != itEnd) + QCPCurveDataContainer::const_iterator prevIt = itEnd - 1; + int prevRegion = getRegion( prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin ); + QVector trailingPoints; // points that must be applied after all other points (are generated only when handling first point to get virtual segment between last and first point right) + while( it != itEnd ) { - const int currentRegion = getRegion(it->key, it->value, keyMin, valueMax, keyMax, valueMin); - if (currentRegion != prevRegion) // changed region, possibly need to add some optimized edge points or original points if entering R + const int currentRegion = getRegion( it->key, it->value, keyMin, valueMax, keyMax, valueMin ); + if( currentRegion != prevRegion ) // changed region, possibly need to add some optimized edge points or original points if entering R { - if (currentRegion != 5) // segment doesn't end in R, so it's a candidate for removal + if( currentRegion != 5 ) // segment doesn't end in R, so it's a candidate for removal { QPointF crossA, crossB; - if (prevRegion == 5) // we're coming from R, so add this point optimized + if( prevRegion == 5 ) // we're coming from R, so add this point optimized { - lines->append(getOptimizedPoint(currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin)); + lines->append( getOptimizedPoint( currentRegion, it->key, it->value, prevIt->key, prevIt->value, keyMin, valueMax, keyMax, valueMin ) ); // in the situations 5->1/7/9/3 the segment may leave R and directly cross through two outer regions. In these cases we need to add an additional corner point - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - } else if (mayTraverse(prevRegion, currentRegion) && - getTraverse(prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB)) + *lines << getOptimizedCornerPoints( prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin ); + } + else if( mayTraverse( prevRegion, currentRegion ) && + getTraverse( prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin, crossA, crossB ) ) { // add the two cross points optimized if segment crosses R and if segment isn't virtual zeroth segment between last and first curve point: QVector beforeTraverseCornerPoints, afterTraverseCornerPoints; - getTraverseCornerPoints(prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints); - if (it != itBegin) + getTraverseCornerPoints( prevRegion, currentRegion, keyMin, valueMax, keyMax, valueMin, beforeTraverseCornerPoints, afterTraverseCornerPoints ); + if( it != itBegin ) { *lines << beforeTraverseCornerPoints; - lines->append(crossA); - lines->append(crossB); + lines->append( crossA ); + lines->append( crossB ); *lines << afterTraverseCornerPoints; - } else - { - lines->append(crossB); - *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA ; } - } else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) - { - *lines << getOptimizedCornerPoints(prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); + else + { + lines->append( crossB ); + *lines << afterTraverseCornerPoints; + trailingPoints << beforeTraverseCornerPoints << crossA; + } + } + else // doesn't cross R, line is just moving around in outside regions, so only need to add optimized point(s) at the boundary corner(s) + { + *lines << getOptimizedCornerPoints( prevRegion, currentRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin ); } - } else // segment does end in R, so we add previous point optimized and this point at original position - { - if (it == itBegin) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end - trailingPoints << getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin); - else - lines->append(getOptimizedPoint(prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin)); - lines->append(coordsToPixels(it->key, it->value)); } - } else // region didn't change - { - if (currentRegion == 5) // still in R, keep adding original points + else // segment does end in R, so we add previous point optimized and this point at original position { - lines->append(coordsToPixels(it->key, it->value)); - } else // still outside R, no need to add anything + if( it == itBegin ) // it is first point in curve and prevIt is last one. So save optimized point for adding it to the lineData in the end + trailingPoints << getOptimizedPoint( prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin ); + else + lines->append( getOptimizedPoint( prevRegion, prevIt->key, prevIt->value, it->key, it->value, keyMin, valueMax, keyMax, valueMin ) ); + lines->append( coordsToPixels( it->key, it->value ) ); + } + } + else // region didn't change + { + if( currentRegion == 5 ) // still in R, keep adding original points + { + lines->append( coordsToPixels( it->key, it->value ) ); + } + else // still outside R, no need to add anything { // see how this is not doing anything? That's the main optimization... } @@ -22376,52 +22609,57 @@ void QCPCurve::getCurveLines(QVector *lines, const QCPDataRange &dataRa \see draw, drawScatterPlot */ -void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const +void QCPCurve::getScatters( QVector* scatters, const QCPDataRange& dataRange, double scatterWidth ) const { - if (!scatters) return; + if( !scatters ) + return; scatters->clear(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - mDataContainer->limitIteratorsToDataRange(begin, end, dataRange); - if (begin == end) + mDataContainer->limitIteratorsToDataRange( begin, end, dataRange ); + if( begin == end ) return; - const int scatterModulo = mScatterSkip+1; + const int scatterModulo = mScatterSkip + 1; const bool doScatterSkip = mScatterSkip > 0; - int endIndex = end-mDataContainer->constBegin(); - + int endIndex = end - mDataContainer->constBegin(); + QCPRange keyRange = keyAxis->range(); QCPRange valueRange = valueAxis->range(); // extend range to include width of scatter symbols: - keyRange.lower = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.lower)-scatterWidth*keyAxis->pixelOrientation()); - keyRange.upper = keyAxis->pixelToCoord(keyAxis->coordToPixel(keyRange.upper)+scatterWidth*keyAxis->pixelOrientation()); - valueRange.lower = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.lower)-scatterWidth*valueAxis->pixelOrientation()); - valueRange.upper = valueAxis->pixelToCoord(valueAxis->coordToPixel(valueRange.upper)+scatterWidth*valueAxis->pixelOrientation()); - + keyRange.lower = keyAxis->pixelToCoord( keyAxis->coordToPixel( keyRange.lower ) - scatterWidth * keyAxis->pixelOrientation() ); + keyRange.upper = keyAxis->pixelToCoord( keyAxis->coordToPixel( keyRange.upper ) + scatterWidth * keyAxis->pixelOrientation() ); + valueRange.lower = valueAxis->pixelToCoord( valueAxis->coordToPixel( valueRange.lower ) - scatterWidth * valueAxis->pixelOrientation() ); + valueRange.upper = valueAxis->pixelToCoord( valueAxis->coordToPixel( valueRange.upper ) + scatterWidth * valueAxis->pixelOrientation() ); + QCPCurveDataContainer::const_iterator it = begin; - int itIndex = begin-mDataContainer->constBegin(); - while (doScatterSkip && it != end && itIndex % scatterModulo != 0) // advance begin iterator to first non-skipped scatter + int itIndex = begin - mDataContainer->constBegin(); + while( doScatterSkip && it != end && itIndex % scatterModulo != 0 ) // advance begin iterator to first non-skipped scatter { ++itIndex; ++it; } - if (keyAxis->orientation() == Qt::Vertical) + if( keyAxis->orientation() == Qt::Vertical ) { - while (it != end) + while( it != end ) { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(valueAxis->coordToPixel(it->value), keyAxis->coordToPixel(it->key))); - + if( !qIsNaN( it->value ) && keyRange.contains( it->key ) && valueRange.contains( it->value ) ) + scatters->append( QPointF( valueAxis->coordToPixel( it->value ), keyAxis->coordToPixel( it->key ) ) ); + // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) + if( !doScatterSkip ) ++it; else { itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end + if( itIndex < endIndex ) // make sure we didn't jump over end it += scatterModulo; else { @@ -22430,20 +22668,21 @@ void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataR } } } - } else + } + else { - while (it != end) + while( it != end ) { - if (!qIsNaN(it->value) && keyRange.contains(it->key) && valueRange.contains(it->value)) - scatters->append(QPointF(keyAxis->coordToPixel(it->key), valueAxis->coordToPixel(it->value))); - + if( !qIsNaN( it->value ) && keyRange.contains( it->key ) && valueRange.contains( it->value ) ) + scatters->append( QPointF( keyAxis->coordToPixel( it->key ), valueAxis->coordToPixel( it->value ) ) ); + // advance iterator to next (non-skipped) data point: - if (!doScatterSkip) + if( !doScatterSkip ) ++it; else { itIndex += scatterModulo; - if (itIndex < endIndex) // make sure we didn't jump over end + if( itIndex < endIndex ) // make sure we didn't jump over end it += scatterModulo; else { @@ -22474,29 +22713,31 @@ void QCPCurve::getScatters(QVector *scatters, const QCPDataRange &dataR With the rectangle being region 5, and the outer regions extending infinitely outwards. In the curve optimization algorithm, region 5 is considered to be the visible portion of the plot. */ -int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +int QCPCurve::getRegion( double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const { - if (key < keyMin) // region 123 + if( key < keyMin ) // region 123 { - if (value > valueMax) + if( value > valueMax ) return 1; - else if (value < valueMin) + else if( value < valueMin ) return 3; else return 2; - } else if (key > keyMax) // region 789 + } + else if( key > keyMax ) // region 789 { - if (value > valueMax) + if( value > valueMax ) return 7; - else if (value < valueMin) + else if( value < valueMin ) return 9; else return 8; - } else // region 456 + } + else // region 456 { - if (value > valueMax) + if( value > valueMax ) return 4; - else if (value < valueMin) + else if( value < valueMin ) return 6; else return 5; @@ -22518,102 +22759,101 @@ int QCPCurve::getRegion(double key, double value, double keyMin, double valueMax leaving it. It is important though that \a otherRegion correctly identifies the other region not equal to 5. */ -QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +QPointF QCPCurve::getOptimizedPoint( int otherRegion, double otherKey, double otherValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const { // The intersection point interpolation here is done in pixel coordinates, so we don't need to // differentiate between different axis scale types. Note that the nomenclature // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be // different in pixel coordinates (horz/vert key axes, reversed ranges) - - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double otherValuePx = mValueAxis->coordToPixel(otherValue); - const double valuePx = mValueAxis->coordToPixel(value); - const double otherKeyPx = mKeyAxis->coordToPixel(otherKey); - const double keyPx = mKeyAxis->coordToPixel(key); - double intersectKeyPx = keyMinPx; // initial key just a fail-safe - double intersectValuePx = valueMinPx; // initial value just a fail-safe - switch (otherRegion) + + const double keyMinPx = mKeyAxis->coordToPixel( keyMin ); + const double keyMaxPx = mKeyAxis->coordToPixel( keyMax ); + const double valueMinPx = mValueAxis->coordToPixel( valueMin ); + const double valueMaxPx = mValueAxis->coordToPixel( valueMax ); + const double otherValuePx = mValueAxis->coordToPixel( otherValue ); + const double valuePx = mValueAxis->coordToPixel( value ); + const double otherKeyPx = mKeyAxis->coordToPixel( otherKey ); + const double keyPx = mKeyAxis->coordToPixel( key ); + double intersectKeyPx = keyMinPx; // initial key just a fail-safe + double intersectValuePx = valueMinPx; // initial value just a fail-safe + switch( otherRegion ) { - case 1: // top and left edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 2: // left edge + case 1: // top and left edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + if( intersectKeyPx < qMin( keyMinPx, keyMaxPx ) || intersectKeyPx > qMax( keyMinPx, keyMaxPx ) ) // check whether top edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) { intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); } - case 3: // bottom and left edge + break; + } + case 2: // left edge + { + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + break; + } + case 3: // bottom and left edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + if( intersectKeyPx < qMin( keyMinPx, keyMaxPx ) || intersectKeyPx > qMax( keyMinPx, keyMaxPx ) ) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be left edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; + intersectKeyPx = keyMinPx; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); } - case 4: // top edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 5: - { - break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table - } - case 6: // bottom edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - break; - } - case 7: // top and right edge - { - intersectValuePx = valueMaxPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; - } - case 8: // right edge + break; + } + case 4: // top edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + break; + } + case 5: { + break; // case 5 shouldn't happen for this function but we add it anyway to prevent potential discontinuity in branch table + } + case 6: // bottom edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + break; + } + case 7: // top and right edge + { + intersectValuePx = valueMaxPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + if( intersectKeyPx < qMin( keyMinPx, keyMaxPx ) || intersectKeyPx > qMax( keyMinPx, keyMaxPx ) ) // check whether top edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) { intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - break; - } - case 9: // bottom and right edge - { - intersectValuePx = valueMinPx; - intersectKeyPx = otherKeyPx + (keyPx-otherKeyPx)/(valuePx-otherValuePx)*(intersectValuePx-otherValuePx); - if (intersectKeyPx < qMin(keyMinPx, keyMaxPx) || intersectKeyPx > qMax(keyMinPx, keyMaxPx)) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) - { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); - } - break; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); } + break; } - if (mKeyAxis->orientation() == Qt::Horizontal) - return QPointF(intersectKeyPx, intersectValuePx); + case 8: // right edge + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + break; + } + case 9: // bottom and right edge + { + intersectValuePx = valueMinPx; + intersectKeyPx = otherKeyPx + ( keyPx - otherKeyPx ) / ( valuePx - otherValuePx ) * ( intersectValuePx - otherValuePx ); + if( intersectKeyPx < qMin( keyMinPx, keyMaxPx ) || intersectKeyPx > qMax( keyMinPx, keyMaxPx ) ) // check whether bottom edge is not intersected, then it must be right edge (qMin/qMax necessary since axes may be reversed) + { + intersectKeyPx = keyMaxPx; + intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + } + break; + } + } + if( mKeyAxis->orientation() == Qt::Horizontal ) + return QPointF( intersectKeyPx, intersectValuePx ); else - return QPointF(intersectValuePx, intersectKeyPx); + return QPointF( intersectValuePx, intersectKeyPx ); } /*! \internal @@ -22634,154 +22874,365 @@ QPointF QCPCurve::getOptimizedPoint(int otherRegion, double otherKey, double oth the top left corner, making the optimized curve correctly pass from region 4 to 1 to 2 without traversing 5. */ -QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const +QVector QCPCurve::getOptimizedCornerPoints( int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const { QVector result; - switch (prevRegion) + switch( prevRegion ) { - case 1: + case 1: { + switch( currentRegion ) { - switch (currentRegion) + case 2: { + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 4: { + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 3: { + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMin, valueMin ); + break; + } + case 7: { + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMax, valueMax ); + break; + } + case 6: { + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + break; + } + case 8: { + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + break; + } + case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if( ( value - prevValue ) / ( key - prevKey ) * ( keyMin - key ) + value < valueMin ) // segment passes below R { - case 2: { result << coordsToPixels(keyMin, valueMax); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); break; } - case 6: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 9: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - else - { result << coordsToPixels(keyMin, valueMax) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); } - break; - } + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMin ); + } + else + { + result << coordsToPixels( keyMin, valueMax ) << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMin ); } break; } - case 2: + } + break; + } + case 2: { + switch( currentRegion ) { - switch (currentRegion) + case 1: { + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 3: { + result << coordsToPixels( keyMin, valueMin ); + break; + } + case 4: { + result << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + break; + } + case 6: { + result << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + break; + } + case 7: { + result << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 9: { + result << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMin ); + break; + } + } + break; + } + case 3: { + switch( currentRegion ) + { + case 2: { + result << coordsToPixels( keyMin, valueMin ); + break; + } + case 6: { + result << coordsToPixels( keyMin, valueMin ); + break; + } + case 1: { + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMin, valueMax ); + break; + } + case 9: { + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMax, valueMin ); + break; + } + case 4: { + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + break; + } + case 8: { + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + break; + } + case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if( ( value - prevValue ) / ( key - prevKey ) * ( keyMax - key ) + value < valueMin ) // segment passes below R { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 7: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMax ); + } + else + { + result << coordsToPixels( keyMin, valueMin ) << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMax ); } break; } - case 3: + } + break; + } + case 4: { + switch( currentRegion ) { - switch (currentRegion) + case 1: { + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 7: { + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 2: { + result << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + break; + } + case 8: { + result << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + break; + } + case 3: { + result << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMin ); + break; + } + case 9: { + result << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMin ); + break; + } + } + break; + } + case 5: { + switch( currentRegion ) + { + case 1: { + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 7: { + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 9: { + result << coordsToPixels( keyMax, valueMin ); + break; + } + case 3: { + result << coordsToPixels( keyMin, valueMin ); + break; + } + } + break; + } + case 6: { + switch( currentRegion ) + { + case 3: { + result << coordsToPixels( keyMin, valueMin ); + break; + } + case 9: { + result << coordsToPixels( keyMax, valueMin ); + break; + } + case 2: { + result << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + break; + } + case 8: { + result << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + break; + } + case 1: { + result << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 7: { + result << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMax, valueMax ); + break; + } + } + break; + } + case 7: { + switch( currentRegion ) + { + case 4: { + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 8: { + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 1: { + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMin, valueMax ); + break; + } + case 9: { + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMax, valueMin ); + break; + } + case 2: { + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + break; + } + case 6: { + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + break; + } + case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if( ( value - prevValue ) / ( key - prevKey ) * ( keyMax - key ) + value < valueMin ) // segment passes below R { - case 2: { result << coordsToPixels(keyMin, valueMin); break; } - case 6: { result << coordsToPixels(keyMin, valueMin); break; } - case 1: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 7: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - else - { result << coordsToPixels(keyMin, valueMin) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); } - break; - } + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMin ); + } + else + { + result << coordsToPixels( keyMax, valueMax ) << coordsToPixels( keyMin, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMin ); } break; } - case 4: + } + break; + } + case 8: { + switch( currentRegion ) { - switch (currentRegion) + case 7: { + result << coordsToPixels( keyMax, valueMax ); + break; + } + case 9: { + result << coordsToPixels( keyMax, valueMin ); + break; + } + case 4: { + result << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + break; + } + case 6: { + result << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + break; + } + case 1: { + result << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMax ); + break; + } + case 3: { + result << coordsToPixels( keyMax, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMin ); + break; + } + } + break; + } + case 9: { + switch( currentRegion ) + { + case 6: { + result << coordsToPixels( keyMax, valueMin ); + break; + } + case 8: { + result << coordsToPixels( keyMax, valueMin ); + break; + } + case 3: { + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMin, valueMin ); + break; + } + case 7: { + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMax, valueMax ); + break; + } + case 2: { + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + break; + } + case 4: { + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + break; + } + case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points + if( ( value - prevValue ) / ( key - prevKey ) * ( keyMin - key ) + value < valueMin ) // segment passes below R { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 3: { result << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMax, valueMin); break; } + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMin, valueMin ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMax ); + } + else + { + result << coordsToPixels( keyMax, valueMin ) << coordsToPixels( keyMax, valueMax ); + result.append( result.last() ); + result << coordsToPixels( keyMin, valueMax ); } break; } - case 5: - { - switch (currentRegion) - { - case 1: { result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 6: - { - switch (currentRegion) - { - case 3: { result << coordsToPixels(keyMin, valueMin); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 7: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMax, valueMax); break; } - } - break; - } - case 7: - { - switch (currentRegion) - { - case 4: { result << coordsToPixels(keyMax, valueMax); break; } - case 8: { result << coordsToPixels(keyMax, valueMax); break; } - case 1: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); break; } - case 2: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 3: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMax-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - else - { result << coordsToPixels(keyMax, valueMax) << coordsToPixels(keyMin, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); } - break; - } - } - break; - } - case 8: - { - switch (currentRegion) - { - case 7: { result << coordsToPixels(keyMax, valueMax); break; } - case 9: { result << coordsToPixels(keyMax, valueMin); break; } - case 4: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 6: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); break; } - case 1: { result << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); break; } - case 3: { result << coordsToPixels(keyMax, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMin); break; } - } - break; - } - case 9: - { - switch (currentRegion) - { - case 6: { result << coordsToPixels(keyMax, valueMin); break; } - case 8: { result << coordsToPixels(keyMax, valueMin); break; } - case 3: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); break; } - case 7: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); break; } - case 2: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); break; } - case 4: { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); break; } - case 1: { // in this case we need another distinction of cases: segment may pass below or above rect, requiring either bottom right or top left corner points - if ((value-prevValue)/(key-prevKey)*(keyMin-key)+value < valueMin) // segment passes below R - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMin, valueMin); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - else - { result << coordsToPixels(keyMax, valueMin) << coordsToPixels(keyMax, valueMax); result.append(result.last()); result << coordsToPixels(keyMin, valueMax); } - break; - } - } - break; } + break; + } } return result; } @@ -22798,96 +23249,105 @@ QVector QCPCurve::getOptimizedCornerPoints(int prevRegion, int currentR segment may or may not pass region 5 and a more fine-grained calculation must be used (\ref getTraverse). */ -bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const +bool QCPCurve::mayTraverse( int prevRegion, int currentRegion ) const { - switch (prevRegion) + switch( prevRegion ) { - case 1: + case 1: { + switch( currentRegion ) { - switch (currentRegion) - { - case 4: - case 7: - case 2: - case 3: return false; - default: return true; - } - } - case 2: - { - switch (currentRegion) - { - case 1: - case 3: return false; - default: return true; - } - } - case 3: - { - switch (currentRegion) - { - case 1: - case 2: - case 6: - case 9: return false; - default: return true; - } - } case 4: - { - switch (currentRegion) - { - case 1: - case 7: return false; - default: return true; - } - } - case 5: return false; // should never occur - case 6: - { - switch (currentRegion) - { - case 3: - case 9: return false; - default: return true; - } - } case 7: - { - switch (currentRegion) - { - case 1: - case 4: - case 8: - case 9: return false; - default: return true; - } + case 2: + case 3: + return false; + default: + return true; } - case 8: + } + case 2: { + switch( currentRegion ) { - switch (currentRegion) - { - case 7: - case 9: return false; - default: return true; - } + case 1: + case 3: + return false; + default: + return true; } + } + case 3: { + switch( currentRegion ) + { + case 1: + case 2: + case 6: case 9: - { - switch (currentRegion) - { - case 3: - case 6: - case 8: - case 7: return false; - default: return true; - } + return false; + default: + return true; } - default: return true; + } + case 4: { + switch( currentRegion ) + { + case 1: + case 7: + return false; + default: + return true; + } + } + case 5: + return false; // should never occur + case 6: { + switch( currentRegion ) + { + case 3: + case 9: + return false; + default: + return true; + } + } + case 7: { + switch( currentRegion ) + { + case 1: + case 4: + case 8: + case 9: + return false; + default: + return true; + } + } + case 8: { + switch( currentRegion ) + { + case 7: + case 9: + return false; + default: + return true; + } + } + case 9: { + switch( currentRegion ) + { + case 3: + case 6: + case 8: + case 7: + return false; + default: + return true; + } + } + default: + return true; } } - /*! \internal This function is part of the curve optimization algorithm of \ref getCurveLines. @@ -22901,91 +23361,94 @@ bool QCPCurve::mayTraverse(int prevRegion, int currentRegion) const If the segment traverses 5, the output parameters \a crossA and \a crossB indicate the entry and exit points of region 5. They will become the optimized points for that segment. */ -bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const +bool QCPCurve::getTraverse( double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF& crossA, QPointF& crossB ) const { // The intersection point interpolation here is done in pixel coordinates, so we don't need to // differentiate between different axis scale types. Note that the nomenclature // top/left/bottom/right/min/max is with respect to the rect in plot coordinates, wich may be // different in pixel coordinates (horz/vert key axes, reversed ranges) - + QList intersections; - const double valueMinPx = mValueAxis->coordToPixel(valueMin); - const double valueMaxPx = mValueAxis->coordToPixel(valueMax); - const double keyMinPx = mKeyAxis->coordToPixel(keyMin); - const double keyMaxPx = mKeyAxis->coordToPixel(keyMax); - const double keyPx = mKeyAxis->coordToPixel(key); - const double valuePx = mValueAxis->coordToPixel(value); - const double prevKeyPx = mKeyAxis->coordToPixel(prevKey); - const double prevValuePx = mValueAxis->coordToPixel(prevValue); - if (qFuzzyIsNull(key-prevKey)) // line is parallel to value axis + const double valueMinPx = mValueAxis->coordToPixel( valueMin ); + const double valueMaxPx = mValueAxis->coordToPixel( valueMax ); + const double keyMinPx = mKeyAxis->coordToPixel( keyMin ); + const double keyMaxPx = mKeyAxis->coordToPixel( keyMax ); + const double keyPx = mKeyAxis->coordToPixel( key ); + const double valuePx = mValueAxis->coordToPixel( value ); + const double prevKeyPx = mKeyAxis->coordToPixel( prevKey ); + const double prevValuePx = mValueAxis->coordToPixel( prevValue ); + if( qFuzzyIsNull( key - prevKey ) ) // line is parallel to value axis { // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMinPx) : QPointF(valueMinPx, keyPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyPx, valueMaxPx) : QPointF(valueMaxPx, keyPx)); - } else if (qFuzzyIsNull(value-prevValue)) // line is parallel to key axis + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyPx, valueMinPx ) : QPointF( valueMinPx, keyPx ) ); // direction will be taken care of at end of method + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyPx, valueMaxPx ) : QPointF( valueMaxPx, keyPx ) ); + } + else if( qFuzzyIsNull( value - prevValue ) ) // line is parallel to key axis { // due to region filter in mayTraverse(), if line is parallel to value or key axis, region 5 is traversed here - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, valuePx) : QPointF(valuePx, keyMinPx)); // direction will be taken care of at end of method - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, valuePx) : QPointF(valuePx, keyMaxPx)); - } else // line is skewed + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyMinPx, valuePx ) : QPointF( valuePx, keyMinPx ) ); // direction will be taken care of at end of method + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyMaxPx, valuePx ) : QPointF( valuePx, keyMaxPx ) ); + } + else // line is skewed { double gamma; - double keyPerValuePx = (keyPx-prevKeyPx)/(valuePx-prevValuePx); + double keyPerValuePx = ( keyPx - prevKeyPx ) / ( valuePx - prevValuePx ); // check top of rect: - gamma = prevKeyPx + (valueMaxPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMaxPx) : QPointF(valueMaxPx, gamma)); + gamma = prevKeyPx + ( valueMaxPx - prevValuePx ) * keyPerValuePx; + if( gamma >= qMin( keyMinPx, keyMaxPx ) && gamma <= qMax( keyMinPx, keyMaxPx ) ) // qMin/qMax necessary since axes may be reversed + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( gamma, valueMaxPx ) : QPointF( valueMaxPx, gamma ) ); // check bottom of rect: - gamma = prevKeyPx + (valueMinPx-prevValuePx)*keyPerValuePx; - if (gamma >= qMin(keyMinPx, keyMaxPx) && gamma <= qMax(keyMinPx, keyMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(gamma, valueMinPx) : QPointF(valueMinPx, gamma)); - const double valuePerKeyPx = 1.0/keyPerValuePx; + gamma = prevKeyPx + ( valueMinPx - prevValuePx ) * keyPerValuePx; + if( gamma >= qMin( keyMinPx, keyMaxPx ) && gamma <= qMax( keyMinPx, keyMaxPx ) ) // qMin/qMax necessary since axes may be reversed + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( gamma, valueMinPx ) : QPointF( valueMinPx, gamma ) ); + const double valuePerKeyPx = 1.0 / keyPerValuePx; // check left of rect: - gamma = prevValuePx + (keyMinPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMinPx, gamma) : QPointF(gamma, keyMinPx)); + gamma = prevValuePx + ( keyMinPx - prevKeyPx ) * valuePerKeyPx; + if( gamma >= qMin( valueMinPx, valueMaxPx ) && gamma <= qMax( valueMinPx, valueMaxPx ) ) // qMin/qMax necessary since axes may be reversed + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyMinPx, gamma ) : QPointF( gamma, keyMinPx ) ); // check right of rect: - gamma = prevValuePx + (keyMaxPx-prevKeyPx)*valuePerKeyPx; - if (gamma >= qMin(valueMinPx, valueMaxPx) && gamma <= qMax(valueMinPx, valueMaxPx)) // qMin/qMax necessary since axes may be reversed - intersections.append(mKeyAxis->orientation() == Qt::Horizontal ? QPointF(keyMaxPx, gamma) : QPointF(gamma, keyMaxPx)); + gamma = prevValuePx + ( keyMaxPx - prevKeyPx ) * valuePerKeyPx; + if( gamma >= qMin( valueMinPx, valueMaxPx ) && gamma <= qMax( valueMinPx, valueMaxPx ) ) // qMin/qMax necessary since axes may be reversed + intersections.append( mKeyAxis->orientation() == Qt::Horizontal ? QPointF( keyMaxPx, gamma ) : QPointF( gamma, keyMaxPx ) ); } - + // handle cases where found points isn't exactly 2: - if (intersections.size() > 2) + if( intersections.size() > 2 ) { // line probably goes through corner of rect, and we got duplicate points there. single out the point pair with greatest distance in between: double distSqrMax = 0; QPointF pv1, pv2; - for (int i=0; i distSqrMax) + QPointF distPoint = intersections.at( i ) - intersections.at( k ); + double distSqr = distPoint.x() * distPoint.x() + distPoint.y() + distPoint.y(); + if( distSqr > distSqrMax ) { - pv1 = intersections.at(i); - pv2 = intersections.at(k); + pv1 = intersections.at( i ); + pv2 = intersections.at( k ); distSqrMax = distSqr; } } } intersections = QList() << pv1 << pv2; - } else if (intersections.size() != 2) + } + else if( intersections.size() != 2 ) { // one or even zero points found (shouldn't happen unless line perfectly tangent to corner), no need to draw segment return false; } - + // possibly re-sort points so optimized point segment has same direction as original segment: - double xDelta = keyPx-prevKeyPx; - double yDelta = valuePx-prevValuePx; - if (mKeyAxis->orientation() != Qt::Horizontal) - qSwap(xDelta, yDelta); - if (xDelta*(intersections.at(1).x()-intersections.at(0).x()) + yDelta*(intersections.at(1).y()-intersections.at(0).y()) < 0) // scalar product of both segments < 0 -> opposite direction - intersections.move(0, 1); - crossA = intersections.at(0); - crossB = intersections.at(1); + double xDelta = keyPx - prevKeyPx; + double yDelta = valuePx - prevValuePx; + if( mKeyAxis->orientation() != Qt::Horizontal ) + qSwap( xDelta, yDelta ); + if( xDelta * ( intersections.at( 1 ).x() - intersections.at( 0 ).x() ) + yDelta * ( intersections.at( 1 ).y() - intersections.at( 0 ).y() ) < 0 ) // scalar product of both segments < 0 -> opposite direction + intersections.move( 0, 1 ); + crossA = intersections.at( 0 ); + crossB = intersections.at( 1 ); return true; } @@ -23014,87 +23477,145 @@ bool QCPCurve::getTraverse(double prevKey, double prevValue, double key, double corner points before and after the traverse. Then both \a beforeTraverse and \a afterTraverse return the respective corner points. */ -void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const +void QCPCurve::getTraverseCornerPoints( int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector& beforeTraverse, QVector& afterTraverse ) const { - switch (prevRegion) + switch( prevRegion ) { - case 1: + case 1: { + switch( currentRegion ) { - switch (currentRegion) - { - case 6: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - case 9: { beforeTraverse << coordsToPixels(keyMin, valueMax); afterTraverse << coordsToPixels(keyMax, valueMin); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMax); break; } - } + case 6: { + beforeTraverse << coordsToPixels( keyMin, valueMax ); break; } - case 2: - { - switch (currentRegion) - { - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } + case 9: { + beforeTraverse << coordsToPixels( keyMin, valueMax ); + afterTraverse << coordsToPixels( keyMax, valueMin ); break; } - case 3: - { - switch (currentRegion) - { - case 4: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - case 7: { beforeTraverse << coordsToPixels(keyMin, valueMin); afterTraverse << coordsToPixels(keyMax, valueMax); break; } - case 8: { beforeTraverse << coordsToPixels(keyMin, valueMin); break; } - } + case 8: { + beforeTraverse << coordsToPixels( keyMin, valueMax ); break; } - case 4: + } + break; + } + case 2: { + switch( currentRegion ) { - switch (currentRegion) - { - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } - } + case 7: { + afterTraverse << coordsToPixels( keyMax, valueMax ); break; } - case 5: { break; } // shouldn't happen because this method only handles full traverses - case 6: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } - } + case 9: { + afterTraverse << coordsToPixels( keyMax, valueMin ); break; } - case 7: + } + break; + } + case 3: { + switch( currentRegion ) { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - case 3: { beforeTraverse << coordsToPixels(keyMax, valueMax); afterTraverse << coordsToPixels(keyMin, valueMin); break; } - case 6: { beforeTraverse << coordsToPixels(keyMax, valueMax); break; } - } + case 4: { + beforeTraverse << coordsToPixels( keyMin, valueMin ); break; } - case 8: - { - switch (currentRegion) - { - case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } - } + case 7: { + beforeTraverse << coordsToPixels( keyMin, valueMin ); + afterTraverse << coordsToPixels( keyMax, valueMax ); break; } - case 9: - { - switch (currentRegion) - { - case 2: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - case 1: { beforeTraverse << coordsToPixels(keyMax, valueMin); afterTraverse << coordsToPixels(keyMin, valueMax); break; } - case 4: { beforeTraverse << coordsToPixels(keyMax, valueMin); break; } - } + case 8: { + beforeTraverse << coordsToPixels( keyMin, valueMin ); break; } + } + break; + } + case 4: { + switch( currentRegion ) + { + case 3: { + afterTraverse << coordsToPixels( keyMin, valueMin ); + break; + } + case 9: { + afterTraverse << coordsToPixels( keyMax, valueMin ); + break; + } + } + break; + } + case 5: { + break; + } // shouldn't happen because this method only handles full traverses + case 6: { + switch( currentRegion ) + { + case 1: { + afterTraverse << coordsToPixels( keyMin, valueMax ); + break; + } + case 7: { + afterTraverse << coordsToPixels( keyMax, valueMax ); + break; + } + } + break; + } + case 7: { + switch( currentRegion ) + { + case 2: { + beforeTraverse << coordsToPixels( keyMax, valueMax ); + break; + } + case 3: { + beforeTraverse << coordsToPixels( keyMax, valueMax ); + afterTraverse << coordsToPixels( keyMin, valueMin ); + break; + } + case 6: { + beforeTraverse << coordsToPixels( keyMax, valueMax ); + break; + } + } + break; + } + case 8: { + switch( currentRegion ) + { + case 1: { + afterTraverse << coordsToPixels( keyMin, valueMax ); + break; + } + case 3: { + afterTraverse << coordsToPixels( keyMin, valueMin ); + break; + } + } + break; + } + case 9: { + switch( currentRegion ) + { + case 2: { + beforeTraverse << coordsToPixels( keyMax, valueMin ); + break; + } + case 1: { + beforeTraverse << coordsToPixels( keyMax, valueMin ); + afterTraverse << coordsToPixels( keyMin, valueMax ); + break; + } + case 4: { + beforeTraverse << coordsToPixels( keyMax, valueMin ); + break; + } + } + break; + } } } @@ -23110,58 +23631,56 @@ void QCPCurve::getTraverseCornerPoints(int prevRegion, int currentRegion, double is \ref QCPScatterStyle::ssNone (i.e. there is no visual representation of the curve), returns -1.0. */ -double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const +double QCPCurve::pointDistance( const QPointF& pixelPoint, QCPCurveDataContainer::const_iterator& closestData ) const { closestData = mDataContainer->constEnd(); - if (mDataContainer->isEmpty()) + if( mDataContainer->isEmpty() ) return -1.0; - if (mLineStyle == lsNone && mScatterStyle.isNone()) + if( mLineStyle == lsNone && mScatterStyle.isNone() ) return -1.0; - - if (mDataContainer->size() == 1) + + if( mDataContainer->size() == 1 ) { - QPointF dataPoint = coordsToPixels(mDataContainer->constBegin()->key, mDataContainer->constBegin()->value); + QPointF dataPoint = coordsToPixels( mDataContainer->constBegin()->key, mDataContainer->constBegin()->value ); closestData = mDataContainer->constBegin(); - return QCPVector2D(dataPoint-pixelPoint).length(); + return QCPVector2D( dataPoint - pixelPoint ).length(); } - + // calculate minimum distances to curve data points and find closestData iterator: - double minDistSqr = (std::numeric_limits::max)(); + double minDistSqr = ( std::numeric_limits::max )(); // iterate over found data points and then choose the one with the shortest distance to pos: QCPCurveDataContainer::const_iterator begin = mDataContainer->constBegin(); QCPCurveDataContainer::const_iterator end = mDataContainer->constEnd(); - for (QCPCurveDataContainer::const_iterator it=begin; it!=end; ++it) + for( QCPCurveDataContainer::const_iterator it = begin; it != end; ++it ) { - const double currentDistSqr = QCPVector2D(coordsToPixels(it->key, it->value)-pixelPoint).lengthSquared(); - if (currentDistSqr < minDistSqr) + const double currentDistSqr = QCPVector2D( coordsToPixels( it->key, it->value ) - pixelPoint ).lengthSquared(); + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestData = it; } } - + // calculate distance to line if there is one (if so, will probably be smaller than distance to closest data point): - if (mLineStyle != lsNone) + if( mLineStyle != lsNone ) { QVector lines; - getCurveLines(&lines, QCPDataRange(0, dataCount()), mParentPlot->selectionTolerance()*1.2); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width - for (int i=0; iselectionTolerance() * 1.2 ); // optimized lines outside axis rect shouldn't respond to clicks at the edge, so use 1.2*tolerance as pen width + for( int i = 0; i < lines.size() - 1; ++i ) { - double currentDistSqr = QCPVector2D(pixelPoint).distanceSquaredToLine(lines.at(i), lines.at(i+1)); - if (currentDistSqr < minDistSqr) + double currentDistSqr = QCPVector2D( pixelPoint ).distanceSquaredToLine( lines.at( i ), lines.at( i + 1 ) ); + if( currentDistSqr < minDistSqr ) minDistSqr = currentDistSqr; } } - - return qSqrt(minDistSqr); + + return qSqrt( minDistSqr ); } /* end of 'src/plottables/plottable-curve.cpp' */ - /* including file 'src/plottables/plottable-bars.cpp', size 43725 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPBarsGroup //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -23233,11 +23752,8 @@ double QCPCurve::pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer: /*! Constructs a new bars group for the specified QCustomPlot instance. */ -QCPBarsGroup::QCPBarsGroup(QCustomPlot *parentPlot) : - QObject(parentPlot), - mParentPlot(parentPlot), - mSpacingType(stAbsolute), - mSpacing(4) +QCPBarsGroup::QCPBarsGroup( QCustomPlot* parentPlot ) + : QObject( parentPlot ), mParentPlot( parentPlot ), mSpacingType( stAbsolute ), mSpacing( 4 ) { } @@ -23253,7 +23769,7 @@ QCPBarsGroup::~QCPBarsGroup() \see setSpacing */ -void QCPBarsGroup::setSpacingType(SpacingType spacingType) +void QCPBarsGroup::setSpacingType( SpacingType spacingType ) { mSpacingType = spacingType; } @@ -23264,7 +23780,7 @@ void QCPBarsGroup::setSpacingType(SpacingType spacingType) \see setSpacingType */ -void QCPBarsGroup::setSpacing(double spacing) +void QCPBarsGroup::setSpacing( double spacing ) { mSpacing = spacing; } @@ -23275,12 +23791,13 @@ void QCPBarsGroup::setSpacing(double spacing) \see bars(), size */ -QCPBars *QCPBarsGroup::bars(int index) const +QCPBars* QCPBarsGroup::bars( int index ) const { - if (index >= 0 && index < mBars.size()) + if( index >= 0 && index < mBars.size() ) { - return mBars.at(index); - } else + return mBars.at( index ); + } + else { qDebug() << Q_FUNC_INFO << "index out of bounds:" << index; return 0; @@ -23294,8 +23811,8 @@ QCPBars *QCPBarsGroup::bars(int index) const */ void QCPBarsGroup::clear() { - foreach (QCPBars *bars, mBars) // since foreach takes a copy, removing bars in the loop is okay - bars->setBarsGroup(0); // removes itself via removeBars + foreach( QCPBars* bars, mBars ) // since foreach takes a copy, removing bars in the loop is okay + bars->setBarsGroup( 0 ); // removes itself via removeBars } /*! @@ -23304,18 +23821,18 @@ void QCPBarsGroup::clear() \see insert, remove */ -void QCPBarsGroup::append(QCPBars *bars) +void QCPBarsGroup::append( QCPBars* bars ) { - if (!bars) + if( !bars ) { qDebug() << Q_FUNC_INFO << "bars is 0"; return; } - - if (!mBars.contains(bars)) - bars->setBarsGroup(this); + + if( !mBars.contains( bars ) ) + bars->setBarsGroup( this ); else - qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast(bars); + qDebug() << Q_FUNC_INFO << "bars plottable is already in this bars group:" << reinterpret_cast( bars ); } /*! @@ -23327,19 +23844,19 @@ void QCPBarsGroup::append(QCPBars *bars) \see append, remove */ -void QCPBarsGroup::insert(int i, QCPBars *bars) +void QCPBarsGroup::insert( int i, QCPBars* bars ) { - if (!bars) + if( !bars ) { qDebug() << Q_FUNC_INFO << "bars is 0"; return; } - + // first append to bars list normally: - if (!mBars.contains(bars)) - bars->setBarsGroup(this); + if( !mBars.contains( bars ) ) + bars->setBarsGroup( this ); // then move to according position: - mBars.move(mBars.indexOf(bars), qBound(0, i, mBars.size()-1)); + mBars.move( mBars.indexOf( bars ), qBound( 0, i, mBars.size() - 1 ) ); } /*! @@ -23347,18 +23864,18 @@ void QCPBarsGroup::insert(int i, QCPBars *bars) \see contains, clear */ -void QCPBarsGroup::remove(QCPBars *bars) +void QCPBarsGroup::remove( QCPBars* bars ) { - if (!bars) + if( !bars ) { qDebug() << Q_FUNC_INFO << "bars is 0"; return; } - - if (mBars.contains(bars)) - bars->setBarsGroup(0); + + if( mBars.contains( bars ) ) + bars->setBarsGroup( 0 ); else - qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast(bars); + qDebug() << Q_FUNC_INFO << "bars plottable is not in this bars group:" << reinterpret_cast( bars ); } /*! \internal @@ -23368,10 +23885,10 @@ void QCPBarsGroup::remove(QCPBars *bars) \see unregisterBars */ -void QCPBarsGroup::registerBars(QCPBars *bars) +void QCPBarsGroup::registerBars( QCPBars* bars ) { - if (!mBars.contains(bars)) - mBars.append(bars); + if( !mBars.contains( bars ) ) + mBars.append( bars ); } /*! \internal @@ -23381,9 +23898,9 @@ void QCPBarsGroup::registerBars(QCPBars *bars) \see registerBars */ -void QCPBarsGroup::unregisterBars(QCPBars *bars) +void QCPBarsGroup::unregisterBars( QCPBars* bars ) { - mBars.removeOne(bars); + mBars.removeOne( bars ); } /*! \internal @@ -23392,57 +23909,59 @@ void QCPBarsGroup::unregisterBars(QCPBars *bars) given key coordinate \a keyCoord. The offset is relative to the pixel position of the key coordinate \a keyCoord. */ -double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) +double QCPBarsGroup::keyPixelOffset( const QCPBars* bars, double keyCoord ) { // find list of all base bars in case some mBars are stacked: QList baseBars; - foreach (const QCPBars *b, mBars) + foreach( const QCPBars* b, mBars ) { - while (b->barBelow()) + while( b->barBelow() ) b = b->barBelow(); - if (!baseBars.contains(b)) - baseBars.append(b); + if( !baseBars.contains( b ) ) + baseBars.append( b ); } // find base bar this "bars" is stacked on: - const QCPBars *thisBase = bars; - while (thisBase->barBelow()) + const QCPBars* thisBase = bars; + while( thisBase->barBelow() ) thisBase = thisBase->barBelow(); - + // determine key pixel offset of this base bars considering all other base bars in this barsgroup: double result = 0; - int index = baseBars.indexOf(thisBase); - if (index >= 0) + int index = baseBars.indexOf( thisBase ); + if( index >= 0 ) { - if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose) + if( baseBars.size() % 2 == 1 && index == ( baseBars.size() - 1 ) / 2 ) // is center bar (int division on purpose) { return result; - } else + } + else { double lowerPixelWidth, upperPixelWidth; int startIndex; - int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative - if (baseBars.size() % 2 == 0) // even number of bars + int dir = ( index <= ( baseBars.size() - 1 ) / 2 ) ? -1 : 1; // if bar is to lower keys of center, dir is negative + if( baseBars.size() % 2 == 0 ) // even number of bars { - startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0); - result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing - } else // uneven number of bars - { - startIndex = (baseBars.size()-1)/2+dir; - baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar - result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing + startIndex = baseBars.size() / 2 + ( dir < 0 ? -1 : 0 ); + result += getPixelSpacing( baseBars.at( startIndex ), keyCoord ) * 0.5; // half of middle spacing } - for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars + else // uneven number of bars { - baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth); - result += getPixelSpacing(baseBars.at(i), keyCoord); + startIndex = ( baseBars.size() - 1 ) / 2 + dir; + baseBars.at( ( baseBars.size() - 1 ) / 2 )->getPixelWidth( keyCoord, lowerPixelWidth, upperPixelWidth ); + result += qAbs( upperPixelWidth - lowerPixelWidth ) * 0.5; // half of center bar + result += getPixelSpacing( baseBars.at( ( baseBars.size() - 1 ) / 2 ), keyCoord ); // center bar spacing + } + for( int i = startIndex; i != index; i += dir ) // add widths and spacings of bars in between center and our bars + { + baseBars.at( i )->getPixelWidth( keyCoord, lowerPixelWidth, upperPixelWidth ); + result += qAbs( upperPixelWidth - lowerPixelWidth ); + result += getPixelSpacing( baseBars.at( i ), keyCoord ); } // finally half of our bars width: - baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth); - result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; + baseBars.at( index )->getPixelWidth( keyCoord, lowerPixelWidth, upperPixelWidth ); + result += qAbs( upperPixelWidth - lowerPixelWidth ) * 0.5; // correct sign of result depending on orientation and direction of key axis: - result *= dir*thisBase->keyAxis()->pixelOrientation(); + result *= dir * thisBase->keyAxis()->pixelOrientation(); } } return result; @@ -23458,31 +23977,27 @@ double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord) stAxisRectRatio and \ref stPlotCoords. The \a keyCoord is only relevant for spacings given in \ref stPlotCoords on a logarithmic axis. */ -double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) +double QCPBarsGroup::getPixelSpacing( const QCPBars* bars, double keyCoord ) { - switch (mSpacingType) + switch( mSpacingType ) { - case stAbsolute: - { - return mSpacing; - } - case stAxisRectRatio: - { - if (bars->keyAxis()->orientation() == Qt::Horizontal) - return bars->keyAxis()->axisRect()->width()*mSpacing; - else - return bars->keyAxis()->axisRect()->height()*mSpacing; - } - case stPlotCoords: - { - double keyPixel = bars->keyAxis()->coordToPixel(keyCoord); - return qAbs(bars->keyAxis()->coordToPixel(keyCoord+mSpacing)-keyPixel); - } + case stAbsolute: { + return mSpacing; + } + case stAxisRectRatio: { + if( bars->keyAxis()->orientation() == Qt::Horizontal ) + return bars->keyAxis()->axisRect()->width() * mSpacing; + else + return bars->keyAxis()->axisRect()->height() * mSpacing; + } + case stPlotCoords: { + double keyPixel = bars->keyAxis()->coordToPixel( keyCoord ); + return qAbs( bars->keyAxis()->coordToPixel( keyCoord + mSpacing ) - keyPixel ); + } } return 0; } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPBarsData //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -23557,22 +24072,19 @@ double QCPBarsGroup::getPixelSpacing(const QCPBars *bars, double keyCoord) /*! Constructs a bar data point with key and value set to zero. */ -QCPBarsData::QCPBarsData() : - key(0), - value(0) +QCPBarsData::QCPBarsData() + : key( 0 ), value( 0 ) { } /*! Constructs a bar data point with the specified \a key and \a value. */ -QCPBarsData::QCPBarsData(double key, double value) : - key(key), - value(value) +QCPBarsData::QCPBarsData( double key, double value ) + : key( key ), value( value ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPBars //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -23647,27 +24159,22 @@ QCPBarsData::QCPBarsData(double key, double value) : keyAxis. This QCustomPlot instance takes ownership of the QCPBars, so do not delete it manually but use QCustomPlot::removePlottable() instead. */ -QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.75), - mWidthType(wtPlotCoords), - mBarsGroup(0), - mBaseValue(0), - mStackingGap(0) +QCPBars::QCPBars( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable1D( keyAxis, valueAxis ), mWidth( 0.75 ), mWidthType( wtPlotCoords ), mBarsGroup( 0 ), mBaseValue( 0 ), mStackingGap( 0 ) { // modify inherited properties from abstract plottable: - mPen.setColor(Qt::blue); - mPen.setStyle(Qt::SolidLine); - mBrush.setColor(QColor(40, 50, 255, 30)); - mBrush.setStyle(Qt::SolidPattern); - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); + mPen.setColor( Qt::blue ); + mPen.setStyle( Qt::SolidLine ); + mBrush.setColor( QColor( 40, 50, 255, 30 ) ); + mBrush.setStyle( Qt::SolidPattern ); + mSelectionDecorator->setBrush( QBrush( QColor( 160, 160, 255 ) ) ); } QCPBars::~QCPBars() { - setBarsGroup(0); - if (mBarBelow || mBarAbove) - connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking + setBarsGroup( 0 ); + if( mBarBelow || mBarAbove ) + connectBars( mBarBelow.data(), mBarAbove.data() ); // take this bar out of any stacking } /*! \overload @@ -23685,7 +24192,7 @@ QCPBars::~QCPBars() \see addData */ -void QCPBars::setData(QSharedPointer data) +void QCPBars::setData( QSharedPointer data ) { mDataContainer = data; } @@ -23701,10 +24208,10 @@ void QCPBars::setData(QSharedPointer data) \see addData */ -void QCPBars::setData(const QVector &keys, const QVector &values, bool alreadySorted) +void QCPBars::setData( const QVector& keys, const QVector& values, bool alreadySorted ) { mDataContainer->clear(); - addData(keys, values, alreadySorted); + addData( keys, values, alreadySorted ); } /*! @@ -23713,7 +24220,7 @@ void QCPBars::setData(const QVector &keys, const QVector &values How the number passed as \a width is interpreted (e.g. screen pixels, plot coordinates,...), depends on the currently set width type, see \ref setWidthType and \ref WidthType. */ -void QCPBars::setWidth(double width) +void QCPBars::setWidth( double width ) { mWidth = width; } @@ -23726,7 +24233,7 @@ void QCPBars::setWidth(double width) \see setWidth */ -void QCPBars::setWidthType(QCPBars::WidthType widthType) +void QCPBars::setWidthType( QCPBars::WidthType widthType ) { mWidthType = widthType; } @@ -23737,15 +24244,15 @@ void QCPBars::setWidthType(QCPBars::WidthType widthType) To remove this QCPBars from any group, set \a barsGroup to 0. */ -void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) +void QCPBars::setBarsGroup( QCPBarsGroup* barsGroup ) { // deregister at old group: - if (mBarsGroup) - mBarsGroup->unregisterBars(this); + if( mBarsGroup ) + mBarsGroup->unregisterBars( this ); mBarsGroup = barsGroup; // register at new group: - if (mBarsGroup) - mBarsGroup->registerBars(this); + if( mBarsGroup ) + mBarsGroup->registerBars( this ); } /*! @@ -23760,7 +24267,7 @@ void QCPBars::setBarsGroup(QCPBarsGroup *barsGroup) The default base value is 0. */ -void QCPBars::setBaseValue(double baseValue) +void QCPBars::setBaseValue( double baseValue ) { mBaseValue = baseValue; } @@ -23770,7 +24277,7 @@ void QCPBars::setBaseValue(double baseValue) allows specifying a distance in \a pixels, by which the drawn bar rectangles will be separated by the bars below it. */ -void QCPBars::setStackingGap(double pixels) +void QCPBars::setStackingGap( double pixels ) { mStackingGap = pixels; } @@ -23787,23 +24294,23 @@ void QCPBars::setStackingGap(double pixels) Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPBars::addData(const QVector &keys, const QVector &values, bool alreadySorted) +void QCPBars::addData( const QVector& keys, const QVector& values, bool alreadySorted ) { - if (keys.size() != values.size()) + if( keys.size() != values.size() ) qDebug() << Q_FUNC_INFO << "keys and values have different sizes:" << keys.size() << values.size(); - const int n = qMin(keys.size(), values.size()); - QVector tempData(n); + const int n = qMin( keys.size(), values.size() ); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->key = keys[i]; it->value = values[i]; ++it; ++i; } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, alreadySorted ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -23812,9 +24319,9 @@ void QCPBars::addData(const QVector &keys, const QVector &values Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPBars::addData(double key, double value) +void QCPBars::addData( double key, double value ) { - mDataContainer->add(QCPBarsData(key, value)); + mDataContainer->add( QCPBarsData( key, value ) ); } /*! @@ -23831,22 +24338,23 @@ void QCPBars::addData(double key, double value) \see moveBelow, barAbove, barBelow */ -void QCPBars::moveBelow(QCPBars *bars) +void QCPBars::moveBelow( QCPBars* bars ) { - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + if( bars == this ) + return; + if( bars && ( bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data() ) ) { qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; return; } // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + connectBars( mBarBelow.data(), mBarAbove.data() ); // Note: also works if one (or both) of them is 0 // if new bar given, insert this bar below it: - if (bars) + if( bars ) { - if (bars->mBarBelow) - connectBars(bars->mBarBelow.data(), this); - connectBars(this, bars); + if( bars->mBarBelow ) + connectBars( bars->mBarBelow.data(), this ); + connectBars( this, bars ); } } @@ -23864,43 +24372,44 @@ void QCPBars::moveBelow(QCPBars *bars) \see moveBelow, barBelow, barAbove */ -void QCPBars::moveAbove(QCPBars *bars) +void QCPBars::moveAbove( QCPBars* bars ) { - if (bars == this) return; - if (bars && (bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data())) + if( bars == this ) + return; + if( bars && ( bars->keyAxis() != mKeyAxis.data() || bars->valueAxis() != mValueAxis.data() ) ) { qDebug() << Q_FUNC_INFO << "passed QCPBars* doesn't have same key and value axis as this QCPBars"; return; } // remove from stacking: - connectBars(mBarBelow.data(), mBarAbove.data()); // Note: also works if one (or both) of them is 0 + connectBars( mBarBelow.data(), mBarAbove.data() ); // Note: also works if one (or both) of them is 0 // if new bar given, insert this bar above it: - if (bars) + if( bars ) { - if (bars->mBarAbove) - connectBars(this, bars->mBarAbove.data()); - connectBars(bars, this); + if( bars->mBarAbove ) + connectBars( this, bars->mBarAbove.data() ); + connectBars( bars, this ); } } /*! \copydoc QCPPlottableInterface1D::selectTestRect */ -QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +QCPDataSelection QCPBars::selectTestRect( const QRectF& rect, bool onlySelectable ) const { QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return result; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return result; - + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + getVisibleDataBounds( visibleBegin, visibleEnd ); + + for( QCPBarsDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { - if (rect.intersects(getBarRect(it->key, it->value))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + if( rect.intersects( getBarRect( it->key, it->value ) ) ) + result.addDataRange( QCPDataRange( it - mDataContainer->constBegin(), it - mDataContainer->constBegin() + 1 ), false ); } result.simplify(); return result; @@ -23914,29 +24423,29 @@ QCPDataSelection QCPBars::selectTestRect(const QRectF &rect, bool onlySelectable \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPBars::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + Q_UNUSED( details ) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { // get visible data range: QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - for (QCPBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + getVisibleDataBounds( visibleBegin, visibleEnd ); + for( QCPBarsDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { - if (getBarRect(it->key, it->value).contains(pos)) + if( getBarRect( it->key, it->value ).contains( pos ) ) { - if (details) + if( details ) { - int pointIndex = it-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = it - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } - return mParentPlot->selectionTolerance()*0.99; + return mParentPlot->selectionTolerance() * 0.99; } } } @@ -23944,7 +24453,7 @@ double QCPBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *de } /* inherits documentation from base class */ -QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPBars::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { /* Note: If this QCPBars uses absolute pixels as width (or is in a QCPBarsGroup with spacing in absolute pixels), using this method to adapt the key axis range to fit the bars into the @@ -23956,89 +24465,95 @@ QCPRange QCPBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) co better fit, he should call the corresponding axis rescale multiple times in a row. */ QCPRange range; - range = mDataContainer->keyRange(foundRange, inSignDomain); - + range = mDataContainer->keyRange( foundRange, inSignDomain ); + // determine exact range of bars by including bar width and barsgroup offset: - if (foundRange && mKeyAxis) + if( foundRange && mKeyAxis ) { double lowerPixelWidth, upperPixelWidth, keyPixel; // lower range bound: - getPixelWidth(range.lower, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.lower) + lowerPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.lower); - const double lowerCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(lowerCorrected) && qIsFinite(lowerCorrected) && range.lower > lowerCorrected) + getPixelWidth( range.lower, lowerPixelWidth, upperPixelWidth ); + keyPixel = mKeyAxis.data()->coordToPixel( range.lower ) + lowerPixelWidth; + if( mBarsGroup ) + keyPixel += mBarsGroup->keyPixelOffset( this, range.lower ); + const double lowerCorrected = mKeyAxis.data()->pixelToCoord( keyPixel ); + if( !qIsNaN( lowerCorrected ) && qIsFinite( lowerCorrected ) && range.lower > lowerCorrected ) range.lower = lowerCorrected; // upper range bound: - getPixelWidth(range.upper, lowerPixelWidth, upperPixelWidth); - keyPixel = mKeyAxis.data()->coordToPixel(range.upper) + upperPixelWidth; - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, range.upper); - const double upperCorrected = mKeyAxis.data()->pixelToCoord(keyPixel); - if (!qIsNaN(upperCorrected) && qIsFinite(upperCorrected) && range.upper < upperCorrected) + getPixelWidth( range.upper, lowerPixelWidth, upperPixelWidth ); + keyPixel = mKeyAxis.data()->coordToPixel( range.upper ) + upperPixelWidth; + if( mBarsGroup ) + keyPixel += mBarsGroup->keyPixelOffset( this, range.upper ); + const double upperCorrected = mKeyAxis.data()->pixelToCoord( keyPixel ); + if( !qIsNaN( upperCorrected ) && qIsFinite( upperCorrected ) && range.upper < upperCorrected ) range.upper = upperCorrected; } return range; } /* inherits documentation from base class */ -QCPRange QCPBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPBars::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { // Note: can't simply use mDataContainer->valueRange here because we need to // take into account bar base value and possible stacking of multiple bars QCPRange range; range.lower = mBaseValue; range.upper = mBaseValue; - bool haveLower = true; // set to true, because baseValue should always be visible in bar charts - bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts + bool haveLower = true; // set to true, because baseValue should always be visible in bar charts + bool haveUpper = true; // set to true, because baseValue should always be visible in bar charts QCPBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); QCPBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (inKeyRange != QCPRange()) + if( inKeyRange != QCPRange() ) { - itBegin = mDataContainer->findBegin(inKeyRange.lower); - itEnd = mDataContainer->findEnd(inKeyRange.upper); + itBegin = mDataContainer->findBegin( inKeyRange.lower ); + itEnd = mDataContainer->findEnd( inKeyRange.upper ); } - for (QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + for( QCPBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it ) { - const double current = it->value + getStackedBaseValue(it->key, it->value >= 0); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + const double current = it->value + getStackedBaseValue( it->key, it->value >= 0 ); + if( qIsNaN( current ) ) + continue; + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; } - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; } } } - - foundRange = true; // return true because bar charts always have the 0-line visible + + foundRange = true; // return true because bar charts always have the 0-line visible return range; } /* inherits documentation from base class */ -QPointF QCPBars::dataPixelPosition(int index) const +QPointF QCPBars::dataPixelPosition( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } - - const QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - const double valuePixel = valueAxis->coordToPixel(getStackedBaseValue(it->key, it->value >= 0) + it->value); - const double keyPixel = keyAxis->coordToPixel(it->key) + (mBarsGroup ? mBarsGroup->keyPixelOffset(this, it->key) : 0); - if (keyAxis->orientation() == Qt::Horizontal) - return QPointF(keyPixel, valuePixel); + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QPointF(); + } + + const QCPDataContainer::const_iterator it = mDataContainer->constBegin() + index; + const double valuePixel = valueAxis->coordToPixel( getStackedBaseValue( it->key, it->value >= 0 ) + it->value ); + const double keyPixel = keyAxis->coordToPixel( it->key ) + ( mBarsGroup ? mBarsGroup->keyPixelOffset( this, it->key ) : 0 ); + if( keyAxis->orientation() == Qt::Horizontal ) + return QPointF( keyPixel, valuePixel ); else - return QPointF(valuePixel, keyPixel); - } else + return QPointF( valuePixel, keyPixel ); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return QPointF(); @@ -24046,64 +24561,71 @@ QPointF QCPBars::dataPixelPosition(int index) const } /* inherits documentation from base class */ -void QCPBars::draw(QCPPainter *painter) +void QCPBars::draw( QCPPainter* painter ) { - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mDataContainer->isEmpty()) return; - + if( !mKeyAxis || !mValueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + if( mDataContainer->isEmpty() ) + return; + QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - + getVisibleDataBounds( visibleBegin, visibleEnd ); + // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); QCPBarsDataContainer::const_iterator begin = visibleBegin; QCPBarsDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) + mDataContainer->limitIteratorsToDataRange( begin, end, allSegments.at( i ) ); + if( begin == end ) continue; - - for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it) + + for( QCPBarsDataContainer::const_iterator it = begin; it != end; ++it ) { // check data validity if flag set: #ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->value)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); + if( QCP::isInvalidData( it->key, it->value ) ) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range invalid." + << "Plottable name:" << name(); #endif // draw bar: - if (isSelectedSegment && mSelectionDecorator) + if( isSelectedSegment && mSelectionDecorator ) { - mSelectionDecorator->applyBrush(painter); - mSelectionDecorator->applyPen(painter); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); + mSelectionDecorator->applyBrush( painter ); + mSelectionDecorator->applyPen( painter ); } - applyDefaultAntialiasingHint(painter); - painter->drawPolygon(getBarRect(it->key, it->value)); + else + { + painter->setBrush( mBrush ); + painter->setPen( mPen ); + } + applyDefaultAntialiasingHint( painter ); + painter->drawPolygon( getBarRect( it->key, it->value ) ); } } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPBars::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setBrush(mBrush); - painter->setPen(mPen); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); + applyDefaultAntialiasingHint( painter ); + painter->setBrush( mBrush ); + painter->setPen( mPen ); + QRectF r = QRectF( 0, 0, rect.width() * 0.67, rect.height() * 0.67 ); + r.moveCenter( rect.center() ); + painter->drawRect( r ); } /*! \internal @@ -24120,54 +24642,54 @@ void QCPBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const if the plottable contains no data, both \a begin and \a end point to constEnd. */ -void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const +void QCPBars::getVisibleDataBounds( QCPBarsDataContainer::const_iterator& begin, QCPBarsDataContainer::const_iterator& end ) const { - if (!mKeyAxis) + if( !mKeyAxis ) { qDebug() << Q_FUNC_INFO << "invalid key axis"; begin = mDataContainer->constEnd(); end = mDataContainer->constEnd(); return; } - if (mDataContainer->isEmpty()) + if( mDataContainer->isEmpty() ) { begin = mDataContainer->constEnd(); end = mDataContainer->constEnd(); return; } - + // get visible data range as QMap iterators - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower); - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper); - double lowerPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().lower); - double upperPixelBound = mKeyAxis.data()->coordToPixel(mKeyAxis.data()->range().upper); + begin = mDataContainer->findBegin( mKeyAxis.data()->range().lower ); + end = mDataContainer->findEnd( mKeyAxis.data()->range().upper ); + double lowerPixelBound = mKeyAxis.data()->coordToPixel( mKeyAxis.data()->range().lower ); + double upperPixelBound = mKeyAxis.data()->coordToPixel( mKeyAxis.data()->range().upper ); bool isVisible = false; // walk left from begin to find lower bar that actually is completely outside visible pixel range: QCPBarsDataContainer::const_iterator it = begin; - while (it != mDataContainer->constBegin()) + while( it != mDataContainer->constBegin() ) { --it; - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound)); - if (isVisible) + const QRectF barRect = getBarRect( it->key, it->value ); + if( mKeyAxis.data()->orientation() == Qt::Horizontal ) + isVisible = ( ( !mKeyAxis.data()->rangeReversed() && barRect.right() >= lowerPixelBound ) || ( mKeyAxis.data()->rangeReversed() && barRect.left() <= lowerPixelBound ) ); + else // keyaxis is vertical + isVisible = ( ( !mKeyAxis.data()->rangeReversed() && barRect.top() <= lowerPixelBound ) || ( mKeyAxis.data()->rangeReversed() && barRect.bottom() >= lowerPixelBound ) ); + if( isVisible ) begin = it; else break; } // walk right from ubound to find upper bar that actually is completely outside visible pixel range: it = end; - while (it != mDataContainer->constEnd()) + while( it != mDataContainer->constEnd() ) { - const QRectF barRect = getBarRect(it->key, it->value); - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound)); - else // keyaxis is vertical - isVisible = ((!mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound) || (mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound)); - if (isVisible) - end = it+1; + const QRectF barRect = getBarRect( it->key, it->value ); + if( mKeyAxis.data()->orientation() == Qt::Horizontal ) + isVisible = ( ( !mKeyAxis.data()->rangeReversed() && barRect.left() <= upperPixelBound ) || ( mKeyAxis.data()->rangeReversed() && barRect.right() >= upperPixelBound ) ); + else // keyaxis is vertical + isVisible = ( ( !mKeyAxis.data()->rangeReversed() && barRect.bottom() >= upperPixelBound ) || ( mKeyAxis.data()->rangeReversed() && barRect.top() <= upperPixelBound ) ); + if( isVisible ) + end = it + 1; else break; ++it; @@ -24180,31 +24702,36 @@ void QCPBars::getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, rect is shifted according to the bar stacking (see \ref moveAbove) and base value (see \ref setBaseValue), and to have non-overlapping border lines with the bars stacked below. */ -QRectF QCPBars::getBarRect(double key, double value) const +QRectF QCPBars::getBarRect( double key, double value ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QRectF(); + } + double lowerPixelWidth, upperPixelWidth; - getPixelWidth(key, lowerPixelWidth, upperPixelWidth); - double base = getStackedBaseValue(key, value >= 0); - double basePixel = valueAxis->coordToPixel(base); - double valuePixel = valueAxis->coordToPixel(base+value); - double keyPixel = keyAxis->coordToPixel(key); - if (mBarsGroup) - keyPixel += mBarsGroup->keyPixelOffset(this, key); - double bottomOffset = (mBarBelow && mPen != Qt::NoPen ? 1 : 0)*(mPen.isCosmetic() ? 1 : mPen.widthF()); + getPixelWidth( key, lowerPixelWidth, upperPixelWidth ); + double base = getStackedBaseValue( key, value >= 0 ); + double basePixel = valueAxis->coordToPixel( base ); + double valuePixel = valueAxis->coordToPixel( base + value ); + double keyPixel = keyAxis->coordToPixel( key ); + if( mBarsGroup ) + keyPixel += mBarsGroup->keyPixelOffset( this, key ); + double bottomOffset = ( mBarBelow && mPen != Qt::NoPen ? 1 : 0 ) * ( mPen.isCosmetic() ? 1 : mPen.widthF() ); bottomOffset += mBarBelow ? mStackingGap : 0; - bottomOffset *= (value<0 ? -1 : 1)*valueAxis->pixelOrientation(); - if (qAbs(valuePixel-basePixel) <= qAbs(bottomOffset)) - bottomOffset = valuePixel-basePixel; - if (keyAxis->orientation() == Qt::Horizontal) + bottomOffset *= ( value < 0 ? -1 : 1 ) * valueAxis->pixelOrientation(); + if( qAbs( valuePixel - basePixel ) <= qAbs( bottomOffset ) ) + bottomOffset = valuePixel - basePixel; + if( keyAxis->orientation() == Qt::Horizontal ) { - return QRectF(QPointF(keyPixel+lowerPixelWidth, valuePixel), QPointF(keyPixel+upperPixelWidth, basePixel+bottomOffset)).normalized(); - } else + return QRectF( QPointF( keyPixel + lowerPixelWidth, valuePixel ), QPointF( keyPixel + upperPixelWidth, basePixel + bottomOffset ) ).normalized(); + } + else { - return QRectF(QPointF(basePixel+bottomOffset, keyPixel+lowerPixelWidth), QPointF(valuePixel, keyPixel+upperPixelWidth)).normalized(); + return QRectF( QPointF( basePixel + bottomOffset, keyPixel + lowerPixelWidth ), QPointF( valuePixel, keyPixel + upperPixelWidth ) ).normalized(); } } @@ -24217,44 +24744,43 @@ QRectF QCPBars::getBarRect(double key, double value) const and higher keys, relative to the \a key coordinate (so with a non-reversed horizontal axis, \a lower is negative and \a upper positive). */ -void QCPBars::getPixelWidth(double key, double &lower, double &upper) const +void QCPBars::getPixelWidth( double key, double& lower, double& upper ) const { lower = 0; upper = 0; - switch (mWidthType) + switch( mWidthType ) { - case wtAbsolute: + case wtAbsolute: { + upper = mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); + lower = -upper; + break; + } + case wtAxisRectRatio: { + if( mKeyAxis && mKeyAxis.data()->axisRect() ) { - upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); + if( mKeyAxis.data()->orientation() == Qt::Horizontal ) + upper = mKeyAxis.data()->axisRect()->width() * mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); + else + upper = mKeyAxis.data()->axisRect()->height() * mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); lower = -upper; - break; } - case wtAxisRectRatio: + else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: { + if( mKeyAxis ) { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - upper = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - upper = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - lower = -upper; - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - { - double keyPixel = mKeyAxis.data()->coordToPixel(key); - upper = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; - lower = mKeyAxis.data()->coordToPixel(key-mWidth*0.5)-keyPixel; - // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by - // coordinate transform which includes range direction - } else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; + double keyPixel = mKeyAxis.data()->coordToPixel( key ); + upper = mKeyAxis.data()->coordToPixel( key + mWidth * 0.5 ) - keyPixel; + lower = mKeyAxis.data()->coordToPixel( key - mWidth * 0.5 ) - keyPixel; + // no need to qSwap(lower, higher) when range reversed, because higher/lower are gained by + // coordinate transform which includes range direction } + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } } } @@ -24267,30 +24793,31 @@ void QCPBars::getPixelWidth(double key, double &lower, double &upper) const negative are stacked below baseValue downwards). This can be indicated with \a positive. So if the bar for which we need the base value is negative, set \a positive to false. */ -double QCPBars::getStackedBaseValue(double key, bool positive) const +double QCPBars::getStackedBaseValue( double key, bool positive ) const { - if (mBarBelow) + if( mBarBelow ) { - double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack + double max = 0; // don't initialize with mBaseValue here because only base value of bottom-most bar has meaning in a bar stack // find bars of mBarBelow that are approximately at key and find largest one: - double epsilon = qAbs(key)*(sizeof(key)==4 ? 1e-6 : 1e-14); // should be safe even when changed to use float at some point - if (key == 0) - epsilon = (sizeof(key)==4 ? 1e-6 : 1e-14); - QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin(key-epsilon); - QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd(key+epsilon); - while (it != itEnd) + double epsilon = qAbs( key ) * ( sizeof( key ) == 4 ? 1e-6 : 1e-14 ); // should be safe even when changed to use float at some point + if( key == 0 ) + epsilon = ( sizeof( key ) == 4 ? 1e-6 : 1e-14 ); + QCPBarsDataContainer::const_iterator it = mBarBelow.data()->mDataContainer->findBegin( key - epsilon ); + QCPBarsDataContainer::const_iterator itEnd = mBarBelow.data()->mDataContainer->findEnd( key + epsilon ); + while( it != itEnd ) { - if (it->key > key-epsilon && it->key < key+epsilon) + if( it->key > key - epsilon && it->key < key + epsilon ) { - if ((positive && it->value > max) || - (!positive && it->value < max)) + if( ( positive && it->value > max ) || + ( !positive && it->value < max ) ) max = it->value; } ++it; } // recurse down the bar-stack to find the total height: - return max + mBarBelow.data()->getStackedBaseValue(key, positive); - } else + return max + mBarBelow.data()->getStackedBaseValue( key, positive ); + } + else return mBaseValue; } @@ -24302,29 +24829,32 @@ double QCPBars::getStackedBaseValue(double key, bool positive) const If lower is zero, upper will be disconnected at the bottom. If upper is zero, lower will be disconnected at the top. */ -void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) +void QCPBars::connectBars( QCPBars* lower, QCPBars* upper ) { - if (!lower && !upper) return; - - if (!lower) // disconnect upper at bottom + if( !lower && !upper ) + return; + + if( !lower ) // disconnect upper at bottom { // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + if( upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper ) upper->mBarBelow.data()->mBarAbove = 0; upper->mBarBelow = 0; - } else if (!upper) // disconnect lower at top + } + else if( !upper ) // disconnect lower at top { // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + if( lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower ) lower->mBarAbove.data()->mBarBelow = 0; lower->mBarAbove = 0; - } else // connect lower and upper + } + else // connect lower and upper { // disconnect old bar above lower: - if (lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower) + if( lower->mBarAbove && lower->mBarAbove.data()->mBarBelow.data() == lower ) lower->mBarAbove.data()->mBarBelow = 0; // disconnect old bar below upper: - if (upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper) + if( upper->mBarBelow && upper->mBarBelow.data()->mBarAbove.data() == upper ) upper->mBarBelow.data()->mBarAbove = 0; lower->mBarAbove = upper; upper->mBarBelow = lower; @@ -24332,7 +24862,6 @@ void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) } /* end of 'src/plottables/plottable-bars.cpp' */ - /* including file 'src/plottables/plottable-statisticalbox.cpp', size 28837 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -24432,13 +24961,8 @@ void QCPBars::connectBars(QCPBars *lower, QCPBars *upper) /*! Constructs a data point with key and all values set to zero. */ -QCPStatisticalBoxData::QCPStatisticalBoxData() : - key(0), - minimum(0), - lowerQuartile(0), - median(0), - upperQuartile(0), - maximum(0) +QCPStatisticalBoxData::QCPStatisticalBoxData() + : key( 0 ), minimum( 0 ), lowerQuartile( 0 ), median( 0 ), upperQuartile( 0 ), maximum( 0 ) { } @@ -24446,18 +24970,11 @@ QCPStatisticalBoxData::QCPStatisticalBoxData() : Constructs a data point with the specified \a key, \a minimum, \a lowerQuartile, \a median, \a upperQuartile, \a maximum and optionally a number of \a outliers. */ -QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers) : - key(key), - minimum(minimum), - lowerQuartile(lowerQuartile), - median(median), - upperQuartile(upperQuartile), - maximum(maximum), - outliers(outliers) +QCPStatisticalBoxData::QCPStatisticalBoxData( double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers ) + : key( key ), minimum( minimum ), lowerQuartile( lowerQuartile ), median( median ), upperQuartile( upperQuartile ), maximum( maximum ), outliers( outliers ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPStatisticalBox //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -24531,18 +25048,11 @@ QCPStatisticalBoxData::QCPStatisticalBoxData(double key, double minimum, double from \a keyAxis. This QCustomPlot instance takes ownership of the QCPStatisticalBox, so do not delete it manually but use QCustomPlot::removePlottable() instead. */ -QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mWidth(0.5), - mWhiskerWidth(0.2), - mWhiskerPen(Qt::black, 0, Qt::DashLine, Qt::FlatCap), - mWhiskerBarPen(Qt::black), - mWhiskerAntialiased(false), - mMedianPen(Qt::black, 3, Qt::SolidLine, Qt::FlatCap), - mOutlierStyle(QCPScatterStyle::ssCircle, Qt::blue, 6) +QCPStatisticalBox::QCPStatisticalBox( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable1D( keyAxis, valueAxis ), mWidth( 0.5 ), mWhiskerWidth( 0.2 ), mWhiskerPen( Qt::black, 0, Qt::DashLine, Qt::FlatCap ), mWhiskerBarPen( Qt::black ), mWhiskerAntialiased( false ), mMedianPen( Qt::black, 3, Qt::SolidLine, Qt::FlatCap ), mOutlierStyle( QCPScatterStyle::ssCircle, Qt::blue, 6 ) { - setPen(QPen(Qt::black)); - setBrush(Qt::NoBrush); + setPen( QPen( Qt::black ) ); + setBrush( Qt::NoBrush ); } /*! \overload @@ -24561,7 +25071,7 @@ QCPStatisticalBox::QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis) : \see addData */ -void QCPStatisticalBox::setData(QSharedPointer data) +void QCPStatisticalBox::setData( QSharedPointer data ) { mDataContainer = data; } @@ -24576,10 +25086,10 @@ void QCPStatisticalBox::setData(QSharedPointer d \see addData */ -void QCPStatisticalBox::setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +void QCPStatisticalBox::setData( const QVector& keys, const QVector& minimum, const QVector& lowerQuartile, const QVector& median, const QVector& upperQuartile, const QVector& maximum, bool alreadySorted ) { mDataContainer->clear(); - addData(keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted); + addData( keys, minimum, lowerQuartile, median, upperQuartile, maximum, alreadySorted ); } /*! @@ -24587,7 +25097,7 @@ void QCPStatisticalBox::setData(const QVector &keys, const QVector &outliers) */ -void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) +void QCPStatisticalBox::setOutlierStyle( const QCPScatterStyle& style ) { mOutlierStyle = style; } @@ -24677,18 +25187,18 @@ void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) Alternatively, you can also access and modify the data directly via the \ref data method, which returns a pointer to the internal data container. */ -void QCPStatisticalBox::addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted) +void QCPStatisticalBox::addData( const QVector& keys, const QVector& minimum, const QVector& lowerQuartile, const QVector& median, const QVector& upperQuartile, const QVector& maximum, bool alreadySorted ) { - if (keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || - median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size()) + if( keys.size() != minimum.size() || minimum.size() != lowerQuartile.size() || lowerQuartile.size() != median.size() || + median.size() != upperQuartile.size() || upperQuartile.size() != maximum.size() || maximum.size() != keys.size() ) qDebug() << Q_FUNC_INFO << "keys, minimum, lowerQuartile, median, upperQuartile, maximum have different sizes:" << keys.size() << minimum.size() << lowerQuartile.size() << median.size() << upperQuartile.size() << maximum.size(); - const int n = qMin(keys.size(), qMin(minimum.size(), qMin(lowerQuartile.size(), qMin(median.size(), qMin(upperQuartile.size(), maximum.size()))))); - QVector tempData(n); + const int n = qMin( keys.size(), qMin( minimum.size(), qMin( lowerQuartile.size(), qMin( median.size(), qMin( upperQuartile.size(), maximum.size() ) ) ) ) ); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->key = keys[i]; it->minimum = minimum[i]; @@ -24699,7 +25209,7 @@ void QCPStatisticalBox::addData(const QVector &keys, const QVectoradd(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, alreadySorted ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -24710,29 +25220,29 @@ void QCPStatisticalBox::addData(const QVector &keys, const QVector &outliers) +void QCPStatisticalBox::addData( double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers ) { - mDataContainer->add(QCPStatisticalBoxData(key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers)); + mDataContainer->add( QCPStatisticalBoxData( key, minimum, lowerQuartile, median, upperQuartile, maximum, outliers ) ); } /*! \copydoc QCPPlottableInterface1D::selectTestRect */ -QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool onlySelectable) const +QCPDataSelection QCPStatisticalBox::selectTestRect( const QRectF& rect, bool onlySelectable ) const { QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return result; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return result; - + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + getVisibleDataBounds( visibleBegin, visibleEnd ); + + for( QCPStatisticalBoxDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { - if (rect.intersects(getQuartileBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + if( rect.intersects( getQuartileBox( it ) ) ) + result.addDataRange( QCPDataRange( it - mDataContainer->constBegin(), it - mDataContainer->constBegin() + 1 ), false ); } result.simplify(); return result; @@ -24746,38 +25256,39 @@ QCPDataSelection QCPStatisticalBox::selectTestRect(const QRectF &rect, bool only \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPStatisticalBox::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + Q_UNUSED( details ) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis->axisRect()->rect().contains( pos.toPoint() ) ) { // get visible data range: QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); - double minDistSqr = (std::numeric_limits::max)(); - for (QCPStatisticalBoxDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + getVisibleDataBounds( visibleBegin, visibleEnd ); + double minDistSqr = ( std::numeric_limits::max )(); + for( QCPStatisticalBoxDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { - if (getQuartileBox(it).contains(pos)) // quartile box + if( getQuartileBox( it ).contains( pos ) ) // quartile box { - double currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - if (currentDistSqr < minDistSqr) + double currentDistSqr = mParentPlot->selectionTolerance() * 0.99 * mParentPlot->selectionTolerance() * 0.99; + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestDataPoint = it; } - } else // whiskers + } + else // whiskers { - const QVector whiskerBackbones(getWhiskerBackboneLines(it)); - for (int i=0; i whiskerBackbones( getWhiskerBackboneLines( it ) ); + for( int i = 0; i < whiskerBackbones.size(); ++i ) { - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(whiskerBackbones.at(i)); - if (currentDistSqr < minDistSqr) + double currentDistSqr = QCPVector2D( pos ).distanceSquaredToLine( whiskerBackbones.at( i ) ); + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestDataPoint = it; @@ -24785,105 +25296,113 @@ double QCPStatisticalBox::selectTest(const QPointF &pos, bool onlySelectable, QV } } } - if (details) + if( details ) { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = closestDataPoint - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } - return qSqrt(minDistSqr); + return qSqrt( minDistSqr ); } return -1; } /* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPStatisticalBox::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + QCPRange range = mDataContainer->keyRange( foundRange, inSignDomain ); // determine exact range by including width of bars/flags: - if (foundRange) + if( foundRange ) { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; + if( inSignDomain != QCP::sdPositive || range.lower - mWidth * 0.5 > 0 ) + range.lower -= mWidth * 0.5; + if( inSignDomain != QCP::sdNegative || range.upper + mWidth * 0.5 < 0 ) + range.upper += mWidth * 0.5; } return range; } /* inherits documentation from base class */ -QCPRange QCPStatisticalBox::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPStatisticalBox::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); + return mDataContainer->valueRange( foundRange, inSignDomain, inKeyRange ); } /* inherits documentation from base class */ -void QCPStatisticalBox::draw(QCPPainter *painter) +void QCPStatisticalBox::draw( QCPPainter* painter ) { - if (mDataContainer->isEmpty()) return; - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - + if( mDataContainer->isEmpty() ) + return; + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - + getVisibleDataBounds( visibleBegin, visibleEnd ); + // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); QCPStatisticalBoxDataContainer::const_iterator begin = visibleBegin; QCPStatisticalBoxDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) + mDataContainer->limitIteratorsToDataRange( begin, end, allSegments.at( i ) ); + if( begin == end ) continue; - - for (QCPStatisticalBoxDataContainer::const_iterator it=begin; it!=end; ++it) + + for( QCPStatisticalBoxDataContainer::const_iterator it = begin; it != end; ++it ) { // check data validity if flag set: -# ifdef QCUSTOMPLOT_CHECK_DATA - if (QCP::isInvalidData(it->key, it->minimum) || - QCP::isInvalidData(it->lowerQuartile, it->median) || - QCP::isInvalidData(it->upperQuartile, it->maximum)) - qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." << "Plottable name:" << name(); - for (int i=0; ioutliers.size(); ++i) - if (QCP::isInvalidData(it->outliers.at(i))) - qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." << "Plottable name:" << name(); -# endif - - if (isSelectedSegment && mSelectionDecorator) +#ifdef QCUSTOMPLOT_CHECK_DATA + if( QCP::isInvalidData( it->key, it->minimum ) || + QCP::isInvalidData( it->lowerQuartile, it->median ) || + QCP::isInvalidData( it->upperQuartile, it->maximum ) ) + qDebug() << Q_FUNC_INFO << "Data point at" << it->key << "of drawn range has invalid data." + << "Plottable name:" << name(); + for( int i = 0; i < it->outliers.size(); ++i ) + if( QCP::isInvalidData( it->outliers.at( i ) ) ) + qDebug() << Q_FUNC_INFO << "Data point outlier at" << it->key << "of drawn range invalid." + << "Plottable name:" << name(); +#endif + + if( isSelectedSegment && mSelectionDecorator ) { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else + mSelectionDecorator->applyPen( painter ); + mSelectionDecorator->applyBrush( painter ); + } + else { - painter->setPen(mPen); - painter->setBrush(mBrush); + painter->setPen( mPen ); + painter->setBrush( mBrush ); } QCPScatterStyle finalOutlierStyle = mOutlierStyle; - if (isSelectedSegment && mSelectionDecorator) - finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle(mOutlierStyle); - drawStatisticalBox(painter, it, finalOutlierStyle); + if( isSelectedSegment && mSelectionDecorator ) + finalOutlierStyle = mSelectionDecorator->getFinalScatterStyle( mOutlierStyle ); + drawStatisticalBox( painter, it, finalOutlierStyle ); } } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPStatisticalBox::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { // draw filled rect: - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - painter->setBrush(mBrush); - QRectF r = QRectF(0, 0, rect.width()*0.67, rect.height()*0.67); - r.moveCenter(rect.center()); - painter->drawRect(r); + applyDefaultAntialiasingHint( painter ); + painter->setPen( mPen ); + painter->setBrush( mBrush ); + QRectF r = QRectF( 0, 0, rect.width() * 0.67, rect.height() * 0.67 ); + r.moveCenter( rect.center() ); + painter->drawRect( r ); } /*! @@ -24894,29 +25413,29 @@ void QCPStatisticalBox::drawLegendIcon(QCPPainter *painter, const QRectF &rect) \see getQuartileBox, getWhiskerBackboneLines, getWhiskerBarLines */ -void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const +void QCPStatisticalBox::drawStatisticalBox( QCPPainter* painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle& outlierStyle ) const { // draw quartile box: - applyDefaultAntialiasingHint(painter); - const QRectF quartileBox = getQuartileBox(it); - painter->drawRect(quartileBox); + applyDefaultAntialiasingHint( painter ); + const QRectF quartileBox = getQuartileBox( it ); + painter->drawRect( quartileBox ); // draw median line with cliprect set to quartile box: painter->save(); - painter->setClipRect(quartileBox, Qt::IntersectClip); - painter->setPen(mMedianPen); - painter->drawLine(QLineF(coordsToPixels(it->key-mWidth*0.5, it->median), coordsToPixels(it->key+mWidth*0.5, it->median))); + painter->setClipRect( quartileBox, Qt::IntersectClip ); + painter->setPen( mMedianPen ); + painter->drawLine( QLineF( coordsToPixels( it->key - mWidth * 0.5, it->median ), coordsToPixels( it->key + mWidth * 0.5, it->median ) ) ); painter->restore(); // draw whisker lines: - applyAntialiasingHint(painter, mWhiskerAntialiased, QCP::aePlottables); - painter->setPen(mWhiskerPen); - painter->drawLines(getWhiskerBackboneLines(it)); - painter->setPen(mWhiskerBarPen); - painter->drawLines(getWhiskerBarLines(it)); + applyAntialiasingHint( painter, mWhiskerAntialiased, QCP::aePlottables ); + painter->setPen( mWhiskerPen ); + painter->drawLines( getWhiskerBackboneLines( it ) ); + painter->setPen( mWhiskerBarPen ); + painter->drawLines( getWhiskerBarLines( it ) ); // draw outliers: - applyScattersAntialiasingHint(painter); - outlierStyle.applyTo(painter, mPen); - for (int i=0; ioutliers.size(); ++i) - outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); + applyScattersAntialiasingHint( painter ); + outlierStyle.applyTo( painter, mPen ); + for( int i = 0; i < it->outliers.size(); ++i ) + outlierStyle.drawShape( painter, coordsToPixels( it->key, it->outliers.at( i ) ) ); } /*! \internal @@ -24933,17 +25452,17 @@ void QCPStatisticalBox::drawStatisticalBox(QCPPainter *painter, QCPStatisticalBo if the plottable contains no data, both \a begin and \a end point to constEnd. */ -void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const +void QCPStatisticalBox::getVisibleDataBounds( QCPStatisticalBoxDataContainer::const_iterator& begin, QCPStatisticalBoxDataContainer::const_iterator& end ) const { - if (!mKeyAxis) + if( !mKeyAxis ) { qDebug() << Q_FUNC_INFO << "invalid key axis"; begin = mDataContainer->constEnd(); end = mDataContainer->constEnd(); return; } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of box to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of box to include partially visible data points + begin = mDataContainer->findBegin( mKeyAxis.data()->range().lower - mWidth * 0.5 ); // subtract half width of box to include partially visible data points + end = mDataContainer->findEnd( mKeyAxis.data()->range().upper + mWidth * 0.5 ); // add half width of box to include partially visible data points } /*! \internal @@ -24953,11 +25472,11 @@ void QCPStatisticalBox::getVisibleDataBounds(QCPStatisticalBoxDataContainer::con \see drawStatisticalBox, getWhiskerBackboneLines, getWhiskerBarLines */ -QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const +QRectF QCPStatisticalBox::getQuartileBox( QCPStatisticalBoxDataContainer::const_iterator it ) const { QRectF result; - result.setTopLeft(coordsToPixels(it->key-mWidth*0.5, it->upperQuartile)); - result.setBottomRight(coordsToPixels(it->key+mWidth*0.5, it->lowerQuartile)); + result.setTopLeft( coordsToPixels( it->key - mWidth * 0.5, it->upperQuartile ) ); + result.setBottomRight( coordsToPixels( it->key + mWidth * 0.5, it->lowerQuartile ) ); return result; } @@ -24969,11 +25488,11 @@ QRectF QCPStatisticalBox::getQuartileBox(QCPStatisticalBoxDataContainer::const_i \see drawStatisticalBox, getQuartileBox, getWhiskerBarLines */ -QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const +QVector QCPStatisticalBox::getWhiskerBackboneLines( QCPStatisticalBoxDataContainer::const_iterator it ) const { - QVector result(2); - result[0].setPoints(coordsToPixels(it->key, it->lowerQuartile), coordsToPixels(it->key, it->minimum)); // min backbone - result[1].setPoints(coordsToPixels(it->key, it->upperQuartile), coordsToPixels(it->key, it->maximum)); // max backbone + QVector result( 2 ); + result[0].setPoints( coordsToPixels( it->key, it->lowerQuartile ), coordsToPixels( it->key, it->minimum ) ); // min backbone + result[1].setPoints( coordsToPixels( it->key, it->upperQuartile ), coordsToPixels( it->key, it->maximum ) ); // max backbone return result; } @@ -24984,16 +25503,15 @@ QVector QCPStatisticalBox::getWhiskerBackboneLines(QCPStatisticalBoxData \see drawStatisticalBox, getQuartileBox, getWhiskerBackboneLines */ -QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const +QVector QCPStatisticalBox::getWhiskerBarLines( QCPStatisticalBoxDataContainer::const_iterator it ) const { - QVector result(2); - result[0].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->minimum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->minimum)); // min bar - result[1].setPoints(coordsToPixels(it->key-mWhiskerWidth*0.5, it->maximum), coordsToPixels(it->key+mWhiskerWidth*0.5, it->maximum)); // max bar + QVector result( 2 ); + result[0].setPoints( coordsToPixels( it->key - mWhiskerWidth * 0.5, it->minimum ), coordsToPixels( it->key + mWhiskerWidth * 0.5, it->minimum ) ); // min bar + result[1].setPoints( coordsToPixels( it->key - mWhiskerWidth * 0.5, it->maximum ), coordsToPixels( it->key + mWhiskerWidth * 0.5, it->maximum ) ); // max bar return result; } /* end of 'src/plottables/plottable-statisticalbox.cpp' */ - /* including file 'src/plottables/plottable-colormap.cpp', size 47881 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -25051,38 +25569,26 @@ QVector QCPStatisticalBox::getWhiskerBarLines(QCPStatisticalBoxDataConta \see setSize, setKeySize, setValueSize, setRange, setKeyRange, setValueRange */ -QCPColorMapData::QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange) : - mKeySize(0), - mValueSize(0), - mKeyRange(keyRange), - mValueRange(valueRange), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) +QCPColorMapData::QCPColorMapData( int keySize, int valueSize, const QCPRange& keyRange, const QCPRange& valueRange ) + : mKeySize( 0 ), mValueSize( 0 ), mKeyRange( keyRange ), mValueRange( valueRange ), mIsEmpty( true ), mData( 0 ), mAlpha( 0 ), mDataModified( true ) { - setSize(keySize, valueSize); - fill(0); + setSize( keySize, valueSize ); + fill( 0 ); } QCPColorMapData::~QCPColorMapData() { - if (mData) + if( mData ) delete[] mData; - if (mAlpha) + if( mAlpha ) delete[] mAlpha; } /*! Constructs a new QCPColorMapData instance copying the data and range of \a other. */ -QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : - mKeySize(0), - mValueSize(0), - mIsEmpty(true), - mData(0), - mAlpha(0), - mDataModified(true) +QCPColorMapData::QCPColorMapData( const QCPColorMapData& other ) + : mKeySize( 0 ), mValueSize( 0 ), mIsEmpty( true ), mData( 0 ), mAlpha( 0 ), mDataModified( true ) { *this = other; } @@ -25091,23 +25597,23 @@ QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : Overwrites this color map data instance with the data stored in \a other. The alpha map state is transferred, too. */ -QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) +QCPColorMapData& QCPColorMapData::operator=( const QCPColorMapData& other ) { - if (&other != this) + if( &other != this ) { const int keySize = other.keySize(); const int valueSize = other.valueSize(); - if (!other.mAlpha && mAlpha) + if( !other.mAlpha && mAlpha ) clearAlpha(); - setSize(keySize, valueSize); - if (other.mAlpha && !mAlpha) - createAlpha(false); - setRange(other.keyRange(), other.valueRange()); - if (!isEmpty()) + setSize( keySize, valueSize ); + if( other.mAlpha && !mAlpha ) + createAlpha( false ); + setRange( other.keyRange(), other.valueRange() ); + if( !isEmpty() ) { - memcpy(mData, other.mData, sizeof(mData[0])*keySize*valueSize); - if (mAlpha) - memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*keySize*valueSize); + memcpy( mData, other.mData, sizeof( mData[0] ) * keySize * valueSize ); + if( mAlpha ) + memcpy( mAlpha, other.mAlpha, sizeof( mAlpha[0] ) * keySize * valueSize ); } mDataBounds = other.mDataBounds; mDataModified = true; @@ -25116,21 +25622,21 @@ QCPColorMapData &QCPColorMapData::operator=(const QCPColorMapData &other) } /* undocumented getter */ -double QCPColorMapData::data(double key, double value) +double QCPColorMapData::data( double key, double value ) { - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) - return mData[valueCell*mKeySize + keyCell]; + int keyCell = ( key - mKeyRange.lower ) / ( mKeyRange.upper - mKeyRange.lower ) * ( mKeySize - 1 ) + 0.5; + int valueCell = ( value - mValueRange.lower ) / ( mValueRange.upper - mValueRange.lower ) * ( mValueSize - 1 ) + 0.5; + if( keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize ) + return mData[valueCell * mKeySize + keyCell]; else return 0; } /* undocumented getter */ -double QCPColorMapData::cell(int keyIndex, int valueIndex) +double QCPColorMapData::cell( int keyIndex, int valueIndex ) { - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mData[valueIndex*mKeySize + keyIndex]; + if( keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize ) + return mData[valueIndex * mKeySize + keyIndex]; else return 0; } @@ -25143,10 +25649,10 @@ double QCPColorMapData::cell(int keyIndex, int valueIndex) \see setAlpha */ -unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) +unsigned char QCPColorMapData::alpha( int keyIndex, int valueIndex ) { - if (mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) - return mAlpha[valueIndex*mKeySize + keyIndex]; + if( mAlpha && keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize ) + return mAlpha[valueIndex * mKeySize + keyIndex]; else return 255; } @@ -25163,34 +25669,40 @@ unsigned char QCPColorMapData::alpha(int keyIndex, int valueIndex) \see setRange, setKeySize, setValueSize */ -void QCPColorMapData::setSize(int keySize, int valueSize) +void QCPColorMapData::setSize( int keySize, int valueSize ) { - if (keySize != mKeySize || valueSize != mValueSize) + if( keySize != mKeySize || valueSize != mValueSize ) { mKeySize = keySize; mValueSize = valueSize; - if (mData) + if( mData ) delete[] mData; mIsEmpty = mKeySize == 0 || mValueSize == 0; - if (!mIsEmpty) + if( !mIsEmpty ) { #ifdef __EXCEPTIONS - try { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message + try + { // 2D arrays get memory intensive fast. So if the allocation fails, at least output debug message #endif - mData = new double[mKeySize*mValueSize]; + mData = new double[mKeySize * mValueSize]; #ifdef __EXCEPTIONS - } catch (...) { mData = 0; } + } + catch( ... ) + { + mData = 0; + } #endif - if (mData) - fill(0); + if( mData ) + fill( 0 ); else - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; - } else + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions " << mKeySize << "*" << mValueSize; + } + else mData = 0; - - if (mAlpha) // if we had an alpha map, recreate it with new size + + if( mAlpha ) // if we had an alpha map, recreate it with new size createAlpha(); - + mDataModified = true; } } @@ -25205,9 +25717,9 @@ void QCPColorMapData::setSize(int keySize, int valueSize) \see setKeyRange, setSize, setValueSize */ -void QCPColorMapData::setKeySize(int keySize) +void QCPColorMapData::setKeySize( int keySize ) { - setSize(keySize, mValueSize); + setSize( keySize, mValueSize ); } /*! @@ -25220,9 +25732,9 @@ void QCPColorMapData::setKeySize(int keySize) \see setValueRange, setSize, setKeySize */ -void QCPColorMapData::setValueSize(int valueSize) +void QCPColorMapData::setValueSize( int valueSize ) { - setSize(mKeySize, valueSize); + setSize( mKeySize, valueSize ); } /*! @@ -25235,10 +25747,10 @@ void QCPColorMapData::setValueSize(int valueSize) \see setSize */ -void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRange) +void QCPColorMapData::setRange( const QCPRange& keyRange, const QCPRange& valueRange ) { - setKeyRange(keyRange); - setValueRange(valueRange); + setKeyRange( keyRange ); + setValueRange( valueRange ); } /*! @@ -25251,7 +25763,7 @@ void QCPColorMapData::setRange(const QCPRange &keyRange, const QCPRange &valueRa \see setRange, setValueRange, setSize */ -void QCPColorMapData::setKeyRange(const QCPRange &keyRange) +void QCPColorMapData::setKeyRange( const QCPRange& keyRange ) { mKeyRange = keyRange; } @@ -25266,7 +25778,7 @@ void QCPColorMapData::setKeyRange(const QCPRange &keyRange) \see setRange, setKeyRange, setSize */ -void QCPColorMapData::setValueRange(const QCPRange &valueRange) +void QCPColorMapData::setValueRange( const QCPRange& valueRange ) { mValueRange = valueRange; } @@ -25283,18 +25795,18 @@ void QCPColorMapData::setValueRange(const QCPRange &valueRange) \see setCell, setRange */ -void QCPColorMapData::setData(double key, double value, double z) +void QCPColorMapData::setData( double key, double value, double z ) { - int keyCell = (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5; - int valueCell = (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5; - if (keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize) + int keyCell = ( key - mKeyRange.lower ) / ( mKeyRange.upper - mKeyRange.lower ) * ( mKeySize - 1 ) + 0.5; + int valueCell = ( value - mValueRange.lower ) / ( mValueRange.upper - mValueRange.lower ) * ( mValueSize - 1 ) + 0.5; + if( keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize ) { - mData[valueCell*mKeySize + keyCell] = z; - if (z < mDataBounds.lower) + mData[valueCell * mKeySize + keyCell] = z; + if( z < mDataBounds.lower ) mDataBounds.lower = z; - if (z > mDataBounds.upper) + if( z > mDataBounds.upper ) mDataBounds.upper = z; - mDataModified = true; + mDataModified = true; } } @@ -25309,17 +25821,18 @@ void QCPColorMapData::setData(double key, double value, double z) \see setData, setSize */ -void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) +void QCPColorMapData::setCell( int keyIndex, int valueIndex, double z ) { - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + if( keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize ) { - mData[valueIndex*mKeySize + keyIndex] = z; - if (z < mDataBounds.lower) + mData[valueIndex * mKeySize + keyIndex] = z; + if( z < mDataBounds.lower ) mDataBounds.lower = z; - if (z > mDataBounds.upper) + if( z > mDataBounds.upper ) mDataBounds.upper = z; - mDataModified = true; - } else + mDataModified = true; + } + else qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; } @@ -25338,16 +25851,17 @@ void QCPColorMapData::setCell(int keyIndex, int valueIndex, double z) \see fillAlpha, clearAlpha */ -void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha) +void QCPColorMapData::setAlpha( int keyIndex, int valueIndex, unsigned char alpha ) { - if (keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize) + if( keyIndex >= 0 && keyIndex < mKeySize && valueIndex >= 0 && valueIndex < mValueSize ) { - if (mAlpha || createAlpha()) + if( mAlpha || createAlpha() ) { - mAlpha[valueIndex*mKeySize + keyIndex] = alpha; + mAlpha[valueIndex * mKeySize + keyIndex] = alpha; mDataModified = true; } - } else + } + else qDebug() << Q_FUNC_INFO << "index out of bounds:" << keyIndex << valueIndex; } @@ -25366,16 +25880,16 @@ void QCPColorMapData::setAlpha(int keyIndex, int valueIndex, unsigned char alpha */ void QCPColorMapData::recalculateDataBounds() { - if (mKeySize > 0 && mValueSize > 0) + if( mKeySize > 0 && mValueSize > 0 ) { double minHeight = mData[0]; double maxHeight = mData[0]; - const int dataCount = mValueSize*mKeySize; - for (int i=0; i maxHeight) + if( mData[i] > maxHeight ) maxHeight = mData[i]; - if (mData[i] < minHeight) + if( mData[i] < minHeight ) minHeight = mData[i]; } mDataBounds.lower = minHeight; @@ -25390,7 +25904,7 @@ void QCPColorMapData::recalculateDataBounds() */ void QCPColorMapData::clear() { - setSize(0, 0); + setSize( 0, 0 ); } /*! @@ -25398,7 +25912,7 @@ void QCPColorMapData::clear() */ void QCPColorMapData::clearAlpha() { - if (mAlpha) + if( mAlpha ) { delete[] mAlpha; mAlpha = 0; @@ -25409,12 +25923,12 @@ void QCPColorMapData::clearAlpha() /*! Sets all cells to the value \a z. */ -void QCPColorMapData::fill(double z) +void QCPColorMapData::fill( double z ) { - const int dataCount = mValueSize*mKeySize; - for (int i=0; i(data); + qDebug() << Q_FUNC_INFO << "The data pointer is already in (and owned by) this plottable" << reinterpret_cast( data ); return; } - if (copy) + if( copy ) { *mMapData = *data; - } else + } + else { delete mMapData; mMapData = data; @@ -25697,17 +26211,18 @@ void QCPColorMap::setData(QCPColorMapData *data, bool copy) \see QCPColorScale::setDataRange */ -void QCPColorMap::setDataRange(const QCPRange &dataRange) +void QCPColorMap::setDataRange( const QCPRange& dataRange ) { - if (!QCPRange::validRange(dataRange)) return; - if (mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper) + if( !QCPRange::validRange( dataRange ) ) + return; + if( mDataRange.lower != dataRange.lower || mDataRange.upper != dataRange.upper ) { - if (mDataScaleType == QCPAxis::stLogarithmic) + if( mDataScaleType == QCPAxis::stLogarithmic ) mDataRange = dataRange.sanitizedForLogScale(); else mDataRange = dataRange.sanitizedForLinScale(); mMapImageInvalidated = true; - emit dataRangeChanged(mDataRange); + emit dataRangeChanged( mDataRange ); } } @@ -25716,15 +26231,15 @@ void QCPColorMap::setDataRange(const QCPRange &dataRange) \see QCPColorScale::setDataScaleType */ -void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) +void QCPColorMap::setDataScaleType( QCPAxis::ScaleType scaleType ) { - if (mDataScaleType != scaleType) + if( mDataScaleType != scaleType ) { mDataScaleType = scaleType; mMapImageInvalidated = true; - emit dataScaleTypeChanged(mDataScaleType); - if (mDataScaleType == QCPAxis::stLogarithmic) - setDataRange(mDataRange.sanitizedForLogScale()); + emit dataScaleTypeChanged( mDataScaleType ); + if( mDataScaleType == QCPAxis::stLogarithmic ) + setDataRange( mDataRange.sanitizedForLogScale() ); } } @@ -25739,13 +26254,13 @@ void QCPColorMap::setDataScaleType(QCPAxis::ScaleType scaleType) \see QCPColorScale::setGradient */ -void QCPColorMap::setGradient(const QCPColorGradient &gradient) +void QCPColorMap::setGradient( const QCPColorGradient& gradient ) { - if (mGradient != gradient) + if( mGradient != gradient ) { mGradient = gradient; mMapImageInvalidated = true; - emit gradientChanged(mGradient); + emit gradientChanged( mGradient ); } } @@ -25755,10 +26270,10 @@ void QCPColorMap::setGradient(const QCPColorGradient &gradient) \image html QCPColorMap-interpolate.png "A 10*10 color map, with interpolation and without interpolation enabled" */ -void QCPColorMap::setInterpolate(bool enabled) +void QCPColorMap::setInterpolate( bool enabled ) { mInterpolate = enabled; - mMapImageInvalidated = true; // because oversampling factors might need to change + mMapImageInvalidated = true; // because oversampling factors might need to change } /*! @@ -25772,7 +26287,7 @@ void QCPColorMap::setInterpolate(bool enabled) \image html QCPColorMap-tightboundary.png "A color map, with tight boundary enabled and disabled" */ -void QCPColorMap::setTightBoundary(bool enabled) +void QCPColorMap::setTightBoundary( bool enabled ) { mTightBoundary = enabled; } @@ -25791,29 +26306,29 @@ void QCPColorMap::setTightBoundary(bool enabled) Pass 0 as \a colorScale to disconnect the color scale from this color map again. */ -void QCPColorMap::setColorScale(QCPColorScale *colorScale) +void QCPColorMap::setColorScale( QCPColorScale* colorScale ) { - if (mColorScale) // unconnect signals from old color scale + if( mColorScale ) // unconnect signals from old color scale { - disconnect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - disconnect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - disconnect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - disconnect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - disconnect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + disconnect( this, SIGNAL( dataRangeChanged( QCPRange ) ), mColorScale.data(), SLOT( setDataRange( QCPRange ) ) ); + disconnect( this, SIGNAL( dataScaleTypeChanged( QCPAxis::ScaleType ) ), mColorScale.data(), SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); + disconnect( this, SIGNAL( gradientChanged( QCPColorGradient ) ), mColorScale.data(), SLOT( setGradient( QCPColorGradient ) ) ); + disconnect( mColorScale.data(), SIGNAL( dataRangeChanged( QCPRange ) ), this, SLOT( setDataRange( QCPRange ) ) ); + disconnect( mColorScale.data(), SIGNAL( gradientChanged( QCPColorGradient ) ), this, SLOT( setGradient( QCPColorGradient ) ) ); + disconnect( mColorScale.data(), SIGNAL( dataScaleTypeChanged( QCPAxis::ScaleType ) ), this, SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); } mColorScale = colorScale; - if (mColorScale) // connect signals to new color scale + if( mColorScale ) // connect signals to new color scale { - setGradient(mColorScale.data()->gradient()); - setDataRange(mColorScale.data()->dataRange()); - setDataScaleType(mColorScale.data()->dataScaleType()); - connect(this, SIGNAL(dataRangeChanged(QCPRange)), mColorScale.data(), SLOT(setDataRange(QCPRange))); - connect(this, SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), mColorScale.data(), SLOT(setDataScaleType(QCPAxis::ScaleType))); - connect(this, SIGNAL(gradientChanged(QCPColorGradient)), mColorScale.data(), SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataRangeChanged(QCPRange)), this, SLOT(setDataRange(QCPRange))); - connect(mColorScale.data(), SIGNAL(gradientChanged(QCPColorGradient)), this, SLOT(setGradient(QCPColorGradient))); - connect(mColorScale.data(), SIGNAL(dataScaleTypeChanged(QCPAxis::ScaleType)), this, SLOT(setDataScaleType(QCPAxis::ScaleType))); + setGradient( mColorScale.data()->gradient() ); + setDataRange( mColorScale.data()->dataRange() ); + setDataScaleType( mColorScale.data()->dataScaleType() ); + connect( this, SIGNAL( dataRangeChanged( QCPRange ) ), mColorScale.data(), SLOT( setDataRange( QCPRange ) ) ); + connect( this, SIGNAL( dataScaleTypeChanged( QCPAxis::ScaleType ) ), mColorScale.data(), SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); + connect( this, SIGNAL( gradientChanged( QCPColorGradient ) ), mColorScale.data(), SLOT( setGradient( QCPColorGradient ) ) ); + connect( mColorScale.data(), SIGNAL( dataRangeChanged( QCPRange ) ), this, SLOT( setDataRange( QCPRange ) ) ); + connect( mColorScale.data(), SIGNAL( gradientChanged( QCPColorGradient ) ), this, SLOT( setGradient( QCPColorGradient ) ) ); + connect( mColorScale.data(), SIGNAL( dataScaleTypeChanged( QCPAxis::ScaleType ) ), this, SLOT( setDataScaleType( QCPAxis::ScaleType ) ) ); } } @@ -25837,11 +26352,11 @@ void QCPColorMap::setColorScale(QCPColorScale *colorScale) \see setDataRange */ -void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) +void QCPColorMap::rescaleDataRange( bool recalculateDataBounds ) { - if (recalculateDataBounds) + if( recalculateDataBounds ) mMapData->recalculateDataBounds(); - setDataRange(mMapData->dataBounds()); + setDataRange( mMapData->dataBounds() ); } /*! @@ -25858,90 +26373,92 @@ void QCPColorMap::rescaleDataRange(bool recalculateDataBounds) \see setDataRange */ -void QCPColorMap::updateLegendIcon(Qt::TransformationMode transformMode, const QSize &thumbSize) +void QCPColorMap::updateLegendIcon( Qt::TransformationMode transformMode, const QSize& thumbSize ) { - if (mMapImage.isNull() && !data()->isEmpty()) - updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) - - if (!mMapImage.isNull()) // might still be null, e.g. if data is empty, so check here again + if( mMapImage.isNull() && !data()->isEmpty() ) + updateMapImage(); // try to update map image if it's null (happens if no draw has happened yet) + + if( !mMapImage.isNull() ) // might still be null, e.g. if data is empty, so check here again { - bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - mLegendIcon = QPixmap::fromImage(mMapImage.mirrored(mirrorX, mirrorY)).scaled(thumbSize, Qt::KeepAspectRatio, transformMode); + bool mirrorX = ( keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis() )->rangeReversed(); + bool mirrorY = ( valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis() )->rangeReversed(); + mLegendIcon = QPixmap::fromImage( mMapImage.mirrored( mirrorX, mirrorY ) ).scaled( thumbSize, Qt::KeepAspectRatio, transformMode ); } } /* inherits documentation from base class */ -double QCPColorMap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPColorMap::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mMapData->isEmpty()) + Q_UNUSED( details ) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mMapData->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (mMapData->keyRange().contains(posKey) && mMapData->valueRange().contains(posValue)) + pixelsToCoords( pos, posKey, posValue ); + if( mMapData->keyRange().contains( posKey ) && mMapData->valueRange().contains( posValue ) ) { - if (details) - details->setValue(QCPDataSelection(QCPDataRange(0, 1))); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. - return mParentPlot->selectionTolerance()*0.99; + if( details ) + details->setValue( QCPDataSelection( QCPDataRange( 0, 1 ) ) ); // temporary solution, to facilitate whole-plottable selection. Replace in future version with segmented 2D selection. + return mParentPlot->selectionTolerance() * 0.99; } } return -1; } /* inherits documentation from base class */ -QCPRange QCPColorMap::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPColorMap::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { foundRange = true; QCPRange result = mMapData->keyRange(); result.normalize(); - if (inSignDomain == QCP::sdPositive) + if( inSignDomain == QCP::sdPositive ) { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) + if( result.lower <= 0 && result.upper > 0 ) + result.lower = result.upper * 1e-3; + else if( result.lower <= 0 && result.upper <= 0 ) foundRange = false; - } else if (inSignDomain == QCP::sdNegative) + } + else if( inSignDomain == QCP::sdNegative ) { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) + if( result.upper >= 0 && result.lower < 0 ) + result.upper = result.lower * 1e-3; + else if( result.upper >= 0 && result.lower >= 0 ) foundRange = false; } return result; } /* inherits documentation from base class */ -QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPColorMap::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - if (inKeyRange != QCPRange()) + if( inKeyRange != QCPRange() ) { - if (mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper) + if( mMapData->keyRange().upper < inKeyRange.lower || mMapData->keyRange().lower > inKeyRange.upper ) { foundRange = false; return QCPRange(); } } - + foundRange = true; QCPRange result = mMapData->valueRange(); result.normalize(); - if (inSignDomain == QCP::sdPositive) + if( inSignDomain == QCP::sdPositive ) { - if (result.lower <= 0 && result.upper > 0) - result.lower = result.upper*1e-3; - else if (result.lower <= 0 && result.upper <= 0) + if( result.lower <= 0 && result.upper > 0 ) + result.lower = result.upper * 1e-3; + else if( result.lower <= 0 && result.upper <= 0 ) foundRange = false; - } else if (inSignDomain == QCP::sdNegative) + } + else if( inSignDomain == QCP::sdNegative ) { - if (result.upper >= 0 && result.lower < 0) - result.upper = result.lower*1e-3; - else if (result.upper >= 0 && result.lower >= 0) + if( result.upper >= 0 && result.lower < 0 ) + result.upper = result.lower * 1e-3; + else if( result.upper >= 0 && result.lower >= 0 ) foundRange = false; } return result; @@ -25963,75 +26480,80 @@ QCPRange QCPColorMap::getValueRange(bool &foundRange, QCP::SignDomain inSignDoma */ void QCPColorMap::updateMapImage() { - QCPAxis *keyAxis = mKeyAxis.data(); - if (!keyAxis) return; - if (mMapData->isEmpty()) return; - + QCPAxis* keyAxis = mKeyAxis.data(); + if( !keyAxis ) + return; + if( mMapData->isEmpty() ) + return; + const QImage::Format format = QImage::Format_ARGB32_Premultiplied; const int keySize = mMapData->keySize(); const int valueSize = mMapData->valueSize(); - int keyOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)keySize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - int valueOversamplingFactor = mInterpolate ? 1 : (int)(1.0+100.0/(double)valueSize); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on - + int keyOversamplingFactor = mInterpolate ? 1 : (int)( 1.0 + 100.0 / (double)keySize ); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + int valueOversamplingFactor = mInterpolate ? 1 : (int)( 1.0 + 100.0 / (double)valueSize ); // make mMapImage have at least size 100, factor becomes 1 if size > 200 or interpolation is on + // resize mMapImage to correct dimensions including possible oversampling factors, according to key/value axes orientation: - if (keyAxis->orientation() == Qt::Horizontal && (mMapImage.width() != keySize*keyOversamplingFactor || mMapImage.height() != valueSize*valueOversamplingFactor)) - mMapImage = QImage(QSize(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor), format); - else if (keyAxis->orientation() == Qt::Vertical && (mMapImage.width() != valueSize*valueOversamplingFactor || mMapImage.height() != keySize*keyOversamplingFactor)) - mMapImage = QImage(QSize(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor), format); - - if (mMapImage.isNull()) + if( keyAxis->orientation() == Qt::Horizontal && ( mMapImage.width() != keySize * keyOversamplingFactor || mMapImage.height() != valueSize * valueOversamplingFactor ) ) + mMapImage = QImage( QSize( keySize * keyOversamplingFactor, valueSize * valueOversamplingFactor ), format ); + else if( keyAxis->orientation() == Qt::Vertical && ( mMapImage.width() != valueSize * valueOversamplingFactor || mMapImage.height() != keySize * keyOversamplingFactor ) ) + mMapImage = QImage( QSize( valueSize * valueOversamplingFactor, keySize * keyOversamplingFactor ), format ); + + if( mMapImage.isNull() ) { qDebug() << Q_FUNC_INFO << "Couldn't create map image (possibly too large for memory)"; - mMapImage = QImage(QSize(10, 10), format); - mMapImage.fill(Qt::black); - } else + mMapImage = QImage( QSize( 10, 10 ), format ); + mMapImage.fill( Qt::black ); + } + else { - QImage *localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + QImage* localMapImage = &mMapImage; // this is the image on which the colorization operates. Either the final mMapImage, or if we need oversampling, mUndersampledMapImage + if( keyOversamplingFactor > 1 || valueOversamplingFactor > 1 ) { // resize undersampled map image to actual key/value cell sizes: - if (keyAxis->orientation() == Qt::Horizontal && (mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize)) - mUndersampledMapImage = QImage(QSize(keySize, valueSize), format); - else if (keyAxis->orientation() == Qt::Vertical && (mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize)) - mUndersampledMapImage = QImage(QSize(valueSize, keySize), format); - localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image - } else if (!mUndersampledMapImage.isNull()) - mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it - - const double *rawData = mMapData->mData; - const unsigned char *rawAlpha = mMapData->mAlpha; - if (keyAxis->orientation() == Qt::Horizontal) + if( keyAxis->orientation() == Qt::Horizontal && ( mUndersampledMapImage.width() != keySize || mUndersampledMapImage.height() != valueSize ) ) + mUndersampledMapImage = QImage( QSize( keySize, valueSize ), format ); + else if( keyAxis->orientation() == Qt::Vertical && ( mUndersampledMapImage.width() != valueSize || mUndersampledMapImage.height() != keySize ) ) + mUndersampledMapImage = QImage( QSize( valueSize, keySize ), format ); + localMapImage = &mUndersampledMapImage; // make the colorization run on the undersampled image + } + else if( !mUndersampledMapImage.isNull() ) + mUndersampledMapImage = QImage(); // don't need oversampling mechanism anymore (map size has changed) but mUndersampledMapImage still has nonzero size, free it + + const double* rawData = mMapData->mData; + const unsigned char* rawAlpha = mMapData->mAlpha; + if( keyAxis->orientation() == Qt::Horizontal ) { const int lineCount = valueSize; const int rowCount = keySize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line*rowCount, rawAlpha+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + QRgb* pixels = reinterpret_cast( localMapImage->scanLine( lineCount - 1 - line ) ); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if( rawAlpha ) + mGradient.colorize( rawData + line * rowCount, rawAlpha + line * rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType == QCPAxis::stLogarithmic ); else - mGradient.colorize(rawData+line*rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType==QCPAxis::stLogarithmic); + mGradient.colorize( rawData + line * rowCount, mDataRange, pixels, rowCount, 1, mDataScaleType == QCPAxis::stLogarithmic ); } - } else // keyAxis->orientation() == Qt::Vertical + } + else // keyAxis->orientation() == Qt::Vertical { const int lineCount = keySize; const int rowCount = valueSize; - for (int line=0; line(localMapImage->scanLine(lineCount-1-line)); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) - if (rawAlpha) - mGradient.colorize(rawData+line, rawAlpha+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + QRgb* pixels = reinterpret_cast( localMapImage->scanLine( lineCount - 1 - line ) ); // invert scanline index because QImage counts scanlines from top, but our vertical index counts from bottom (mathematical coordinate system) + if( rawAlpha ) + mGradient.colorize( rawData + line, rawAlpha + line, mDataRange, pixels, rowCount, lineCount, mDataScaleType == QCPAxis::stLogarithmic ); else - mGradient.colorize(rawData+line, mDataRange, pixels, rowCount, lineCount, mDataScaleType==QCPAxis::stLogarithmic); + mGradient.colorize( rawData + line, mDataRange, pixels, rowCount, lineCount, mDataScaleType == QCPAxis::stLogarithmic ); } } - - if (keyOversamplingFactor > 1 || valueOversamplingFactor > 1) + + if( keyOversamplingFactor > 1 || valueOversamplingFactor > 1 ) { - if (keyAxis->orientation() == Qt::Horizontal) - mMapImage = mUndersampledMapImage.scaled(keySize*keyOversamplingFactor, valueSize*valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + if( keyAxis->orientation() == Qt::Horizontal ) + mMapImage = mUndersampledMapImage.scaled( keySize * keyOversamplingFactor, valueSize * valueOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation ); else - mMapImage = mUndersampledMapImage.scaled(valueSize*valueOversamplingFactor, keySize*keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation); + mMapImage = mUndersampledMapImage.scaled( valueSize * valueOversamplingFactor, keySize * keyOversamplingFactor, Qt::IgnoreAspectRatio, Qt::FastTransformation ); } } mMapData->mDataModified = false; @@ -26039,85 +26561,90 @@ void QCPColorMap::updateMapImage() } /* inherits documentation from base class */ -void QCPColorMap::draw(QCPPainter *painter) +void QCPColorMap::draw( QCPPainter* painter ) { - if (mMapData->isEmpty()) return; - if (!mKeyAxis || !mValueAxis) return; - applyDefaultAntialiasingHint(painter); - - if (mMapData->mDataModified || mMapImageInvalidated) + if( mMapData->isEmpty() ) + return; + if( !mKeyAxis || !mValueAxis ) + return; + applyDefaultAntialiasingHint( painter ); + + if( mMapData->mDataModified || mMapImageInvalidated ) updateMapImage(); - + // use buffer if painting vectorized (PDF): - const bool useBuffer = painter->modes().testFlag(QCPPainter::pmVectorized); - QCPPainter *localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized - QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in + const bool useBuffer = painter->modes().testFlag( QCPPainter::pmVectorized ); + QCPPainter* localPainter = painter; // will be redirected to paint on mapBuffer if painting vectorized + QRectF mapBufferTarget; // the rect in absolute widget coordinates where the visible map portion/buffer will end up in QPixmap mapBuffer; - if (useBuffer) + if( useBuffer ) { - const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps + const double mapBufferPixelRatio = 3; // factor by which DPI is increased in embedded bitmaps mapBufferTarget = painter->clipRegion().boundingRect(); - mapBuffer = QPixmap((mapBufferTarget.size()*mapBufferPixelRatio).toSize()); - mapBuffer.fill(Qt::transparent); - localPainter = new QCPPainter(&mapBuffer); - localPainter->scale(mapBufferPixelRatio, mapBufferPixelRatio); - localPainter->translate(-mapBufferTarget.topLeft()); + mapBuffer = QPixmap( ( mapBufferTarget.size() * mapBufferPixelRatio ).toSize() ); + mapBuffer.fill( Qt::transparent ); + localPainter = new QCPPainter( &mapBuffer ); + localPainter->scale( mapBufferPixelRatio, mapBufferPixelRatio ); + localPainter->translate( -mapBufferTarget.topLeft() ); } - - QRectF imageRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); + + QRectF imageRect = QRectF( coordsToPixels( mMapData->keyRange().lower, mMapData->valueRange().lower ), + coordsToPixels( mMapData->keyRange().upper, mMapData->valueRange().upper ) ) + .normalized(); // extend imageRect to contain outer halves/quarters of bordering/cornering pixels (cells are centered on map range boundary): - double halfCellWidth = 0; // in pixels - double halfCellHeight = 0; // in pixels - if (keyAxis()->orientation() == Qt::Horizontal) + double halfCellWidth = 0; // in pixels + double halfCellHeight = 0; // in pixels + if( keyAxis()->orientation() == Qt::Horizontal ) { - if (mMapData->keySize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->valueSize()-1); - } else // keyAxis orientation is Qt::Vertical - { - if (mMapData->keySize() > 1) - halfCellHeight = 0.5*imageRect.height()/(double)(mMapData->keySize()-1); - if (mMapData->valueSize() > 1) - halfCellWidth = 0.5*imageRect.width()/(double)(mMapData->valueSize()-1); + if( mMapData->keySize() > 1 ) + halfCellWidth = 0.5 * imageRect.width() / (double)( mMapData->keySize() - 1 ); + if( mMapData->valueSize() > 1 ) + halfCellHeight = 0.5 * imageRect.height() / (double)( mMapData->valueSize() - 1 ); } - imageRect.adjust(-halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight); - const bool mirrorX = (keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis())->rangeReversed(); - const bool mirrorY = (valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis())->rangeReversed(); - const bool smoothBackup = localPainter->renderHints().testFlag(QPainter::SmoothPixmapTransform); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, mInterpolate); + else // keyAxis orientation is Qt::Vertical + { + if( mMapData->keySize() > 1 ) + halfCellHeight = 0.5 * imageRect.height() / (double)( mMapData->keySize() - 1 ); + if( mMapData->valueSize() > 1 ) + halfCellWidth = 0.5 * imageRect.width() / (double)( mMapData->valueSize() - 1 ); + } + imageRect.adjust( -halfCellWidth, -halfCellHeight, halfCellWidth, halfCellHeight ); + const bool mirrorX = ( keyAxis()->orientation() == Qt::Horizontal ? keyAxis() : valueAxis() )->rangeReversed(); + const bool mirrorY = ( valueAxis()->orientation() == Qt::Vertical ? valueAxis() : keyAxis() )->rangeReversed(); + const bool smoothBackup = localPainter->renderHints().testFlag( QPainter::SmoothPixmapTransform ); + localPainter->setRenderHint( QPainter::SmoothPixmapTransform, mInterpolate ); QRegion clipBackup; - if (mTightBoundary) + if( mTightBoundary ) { clipBackup = localPainter->clipRegion(); - QRectF tightClipRect = QRectF(coordsToPixels(mMapData->keyRange().lower, mMapData->valueRange().lower), - coordsToPixels(mMapData->keyRange().upper, mMapData->valueRange().upper)).normalized(); - localPainter->setClipRect(tightClipRect, Qt::IntersectClip); + QRectF tightClipRect = QRectF( coordsToPixels( mMapData->keyRange().lower, mMapData->valueRange().lower ), + coordsToPixels( mMapData->keyRange().upper, mMapData->valueRange().upper ) ) + .normalized(); + localPainter->setClipRect( tightClipRect, Qt::IntersectClip ); } - localPainter->drawImage(imageRect, mMapImage.mirrored(mirrorX, mirrorY)); - if (mTightBoundary) - localPainter->setClipRegion(clipBackup); - localPainter->setRenderHint(QPainter::SmoothPixmapTransform, smoothBackup); - - if (useBuffer) // localPainter painted to mapBuffer, so now draw buffer with original painter + localPainter->drawImage( imageRect, mMapImage.mirrored( mirrorX, mirrorY ) ); + if( mTightBoundary ) + localPainter->setClipRegion( clipBackup ); + localPainter->setRenderHint( QPainter::SmoothPixmapTransform, smoothBackup ); + + if( useBuffer ) // localPainter painted to mapBuffer, so now draw buffer with original painter { delete localPainter; - painter->drawPixmap(mapBufferTarget.toRect(), mapBuffer); + painter->drawPixmap( mapBufferTarget.toRect(), mapBuffer ); } } /* inherits documentation from base class */ -void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPColorMap::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { - applyDefaultAntialiasingHint(painter); + applyDefaultAntialiasingHint( painter ); // draw map thumbnail: - if (!mLegendIcon.isNull()) + if( !mLegendIcon.isNull() ) { - QPixmap scaledIcon = mLegendIcon.scaled(rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation); - QRectF iconRect = QRectF(0, 0, scaledIcon.width(), scaledIcon.height()); - iconRect.moveCenter(rect.center()); - painter->drawPixmap(iconRect.topLeft(), scaledIcon); + QPixmap scaledIcon = mLegendIcon.scaled( rect.size().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation ); + QRectF iconRect = QRectF( 0, 0, scaledIcon.width(), scaledIcon.height() ); + iconRect.moveCenter( rect.center() ); + painter->drawPixmap( iconRect.topLeft(), scaledIcon ); } /* // draw frame: @@ -26128,7 +26655,6 @@ void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const } /* end of 'src/plottables/plottable-colormap.cpp' */ - /* including file 'src/plottables/plottable-financial.cpp', size 42827 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -26209,28 +26735,19 @@ void QCPColorMap::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const /*! Constructs a data point with key and all values set to zero. */ -QCPFinancialData::QCPFinancialData() : - key(0), - open(0), - high(0), - low(0), - close(0) +QCPFinancialData::QCPFinancialData() + : key( 0 ), open( 0 ), high( 0 ), low( 0 ), close( 0 ) { } /*! Constructs a data point with the specified \a key and OHLC values. */ -QCPFinancialData::QCPFinancialData(double key, double open, double high, double low, double close) : - key(key), - open(open), - high(high), - low(low), - close(close) +QCPFinancialData::QCPFinancialData( double key, double open, double high, double low, double close ) + : key( key ), open( open ), high( high ), low( low ), close( close ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPFinancial //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -26305,18 +26822,10 @@ QCPFinancialData::QCPFinancialData(double key, double open, double high, double keyAxis. This QCustomPlot instance takes ownership of the QCPFinancial, so do not delete it manually but use QCustomPlot::removePlottable() instead. */ -QCPFinancial::QCPFinancial(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable1D(keyAxis, valueAxis), - mChartStyle(csCandlestick), - mWidth(0.5), - mWidthType(wtPlotCoords), - mTwoColored(true), - mBrushPositive(QBrush(QColor(50, 160, 0))), - mBrushNegative(QBrush(QColor(180, 0, 15))), - mPenPositive(QPen(QColor(40, 150, 0))), - mPenNegative(QPen(QColor(170, 5, 5))) +QCPFinancial::QCPFinancial( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable1D( keyAxis, valueAxis ), mChartStyle( csCandlestick ), mWidth( 0.5 ), mWidthType( wtPlotCoords ), mTwoColored( true ), mBrushPositive( QBrush( QColor( 50, 160, 0 ) ) ), mBrushNegative( QBrush( QColor( 180, 0, 15 ) ) ), mPenPositive( QPen( QColor( 40, 150, 0 ) ) ), mPenNegative( QPen( QColor( 170, 5, 5 ) ) ) { - mSelectionDecorator->setBrush(QBrush(QColor(160, 160, 255))); + mSelectionDecorator->setBrush( QBrush( QColor( 160, 160, 255 ) ) ); } QCPFinancial::~QCPFinancial() @@ -26338,7 +26847,7 @@ QCPFinancial::~QCPFinancial() \see addData, timeSeriesToOhlc */ -void QCPFinancial::setData(QSharedPointer data) +void QCPFinancial::setData( QSharedPointer data ) { mDataContainer = data; } @@ -26354,16 +26863,16 @@ void QCPFinancial::setData(QSharedPointer data) \see addData, timeSeriesToOhlc */ -void QCPFinancial::setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +void QCPFinancial::setData( const QVector& keys, const QVector& open, const QVector& high, const QVector& low, const QVector& close, bool alreadySorted ) { mDataContainer->clear(); - addData(keys, open, high, low, close, alreadySorted); + addData( keys, open, high, low, close, alreadySorted ); } /*! Sets which representation style shall be used to display the OHLC data. */ -void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) +void QCPFinancial::setChartStyle( QCPFinancial::ChartStyle style ) { mChartStyle = style; } @@ -26373,7 +26882,7 @@ void QCPFinancial::setChartStyle(QCPFinancial::ChartStyle style) A typical choice is to set it to (or slightly less than) one bin interval width. */ -void QCPFinancial::setWidth(double width) +void QCPFinancial::setWidth( double width ) { mWidth = width; } @@ -26386,7 +26895,7 @@ void QCPFinancial::setWidth(double width) \see setWidth */ -void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) +void QCPFinancial::setWidthType( QCPFinancial::WidthType widthType ) { mWidthType = widthType; } @@ -26400,7 +26909,7 @@ void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative */ -void QCPFinancial::setTwoColored(bool twoColored) +void QCPFinancial::setTwoColored( bool twoColored ) { mTwoColored = twoColored; } @@ -26414,7 +26923,7 @@ void QCPFinancial::setTwoColored(bool twoColored) \see setBrushNegative, setPenPositive, setPenNegative */ -void QCPFinancial::setBrushPositive(const QBrush &brush) +void QCPFinancial::setBrushPositive( const QBrush& brush ) { mBrushPositive = brush; } @@ -26428,7 +26937,7 @@ void QCPFinancial::setBrushPositive(const QBrush &brush) \see setBrushPositive, setPenNegative, setPenPositive */ -void QCPFinancial::setBrushNegative(const QBrush &brush) +void QCPFinancial::setBrushNegative( const QBrush& brush ) { mBrushNegative = brush; } @@ -26442,7 +26951,7 @@ void QCPFinancial::setBrushNegative(const QBrush &brush) \see setPenNegative, setBrushPositive, setBrushNegative */ -void QCPFinancial::setPenPositive(const QPen &pen) +void QCPFinancial::setPenPositive( const QPen& pen ) { mPenPositive = pen; } @@ -26456,7 +26965,7 @@ void QCPFinancial::setPenPositive(const QPen &pen) \see setPenPositive, setBrushNegative, setBrushPositive */ -void QCPFinancial::setPenNegative(const QPen &pen) +void QCPFinancial::setPenNegative( const QPen& pen ) { mPenNegative = pen; } @@ -26475,16 +26984,16 @@ void QCPFinancial::setPenNegative(const QPen &pen) \see timeSeriesToOhlc */ -void QCPFinancial::addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted) +void QCPFinancial::addData( const QVector& keys, const QVector& open, const QVector& high, const QVector& low, const QVector& close, bool alreadySorted ) { - if (keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size()) + if( keys.size() != open.size() || open.size() != high.size() || high.size() != low.size() || low.size() != close.size() || close.size() != keys.size() ) qDebug() << Q_FUNC_INFO << "keys, open, high, low, close have different sizes:" << keys.size() << open.size() << high.size() << low.size() << close.size(); - const int n = qMin(keys.size(), qMin(open.size(), qMin(high.size(), qMin(low.size(), close.size())))); - QVector tempData(n); + const int n = qMin( keys.size(), qMin( open.size(), qMin( high.size(), qMin( low.size(), close.size() ) ) ) ); + QVector tempData( n ); QVector::iterator it = tempData.begin(); const QVector::iterator itEnd = tempData.end(); int i = 0; - while (it != itEnd) + while( it != itEnd ) { it->key = keys[i]; it->open = open[i]; @@ -26494,7 +27003,7 @@ void QCPFinancial::addData(const QVector &keys, const QVector &o ++it; ++i; } - mDataContainer->add(tempData, alreadySorted); // don't modify tempData beyond this to prevent copy on write + mDataContainer->add( tempData, alreadySorted ); // don't modify tempData beyond this to prevent copy on write } /*! \overload @@ -26507,29 +27016,29 @@ void QCPFinancial::addData(const QVector &keys, const QVector &o \see timeSeriesToOhlc */ -void QCPFinancial::addData(double key, double open, double high, double low, double close) +void QCPFinancial::addData( double key, double open, double high, double low, double close ) { - mDataContainer->add(QCPFinancialData(key, open, high, low, close)); + mDataContainer->add( QCPFinancialData( key, open, high, low, close ) ); } /*! \copydoc QCPPlottableInterface1D::selectTestRect */ -QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelectable) const +QCPDataSelection QCPFinancial::selectTestRect( const QRectF& rect, bool onlySelectable ) const { QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return result; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return result; - + QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - - for (QCPFinancialDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + getVisibleDataBounds( visibleBegin, visibleEnd ); + + for( QCPFinancialDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { - if (rect.intersects(selectionHitBox(it))) - result.addDataRange(QCPDataRange(it-mDataContainer->constBegin(), it-mDataContainer->constBegin()+1), false); + if( rect.intersects( selectionHitBox( it ) ) ) + result.addDataRange( QCPDataRange( it - mDataContainer->constBegin(), it - mDataContainer->constBegin() + 1 ), false ); } result.simplify(); return result; @@ -26543,59 +27052,61 @@ QCPDataSelection QCPFinancial::selectTestRect(const QRectF &rect, bool onlySelec \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPFinancial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPFinancial::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + Q_UNUSED( details ) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { // get visible data range: QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; QCPFinancialDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds(visibleBegin, visibleEnd); + getVisibleDataBounds( visibleBegin, visibleEnd ); // perform select test according to configured style: double result = -1; - switch (mChartStyle) + switch( mChartStyle ) { - case QCPFinancial::csOhlc: - result = ohlcSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; - case QCPFinancial::csCandlestick: - result = candlestickSelectTest(pos, visibleBegin, visibleEnd, closestDataPoint); break; + case QCPFinancial::csOhlc: + result = ohlcSelectTest( pos, visibleBegin, visibleEnd, closestDataPoint ); + break; + case QCPFinancial::csCandlestick: + result = candlestickSelectTest( pos, visibleBegin, visibleEnd, closestDataPoint ); + break; } - if (details) + if( details ) { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = closestDataPoint - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } return result; } - + return -1; } /* inherits documentation from base class */ -QCPRange QCPFinancial::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPFinancial::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { - QCPRange range = mDataContainer->keyRange(foundRange, inSignDomain); + QCPRange range = mDataContainer->keyRange( foundRange, inSignDomain ); // determine exact range by including width of bars/flags: - if (foundRange) + if( foundRange ) { - if (inSignDomain != QCP::sdPositive || range.lower-mWidth*0.5 > 0) - range.lower -= mWidth*0.5; - if (inSignDomain != QCP::sdNegative || range.upper+mWidth*0.5 < 0) - range.upper += mWidth*0.5; + if( inSignDomain != QCP::sdPositive || range.lower - mWidth * 0.5 > 0 ) + range.lower -= mWidth * 0.5; + if( inSignDomain != QCP::sdNegative || range.upper + mWidth * 0.5 < 0 ) + range.upper += mWidth * 0.5; } return range; } /* inherits documentation from base class */ -QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPFinancial::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - return mDataContainer->valueRange(foundRange, inSignDomain, inKeyRange); + return mDataContainer->valueRange( foundRange, inSignDomain, inKeyRange ); } /*! @@ -26612,135 +27123,143 @@ QCPRange QCPFinancial::getValueRange(bool &foundRange, QCP::SignDomain inSignDom It merely defines the mathematical offset/phase of the bins that will be used to process the data. */ -QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset) +QCPFinancialDataContainer QCPFinancial::timeSeriesToOhlc( const QVector& time, const QVector& value, double timeBinSize, double timeBinOffset ) { QCPFinancialDataContainer data; - int count = qMin(time.size(), value.size()); - if (count == 0) + int count = qMin( time.size(), value.size() ); + if( count == 0 ) return QCPFinancialDataContainer(); - - QCPFinancialData currentBinData(0, value.first(), value.first(), value.first(), value.first()); - int currentBinIndex = qFloor((time.first()-timeBinOffset)/timeBinSize+0.5); - for (int i=0; i currentBinData.high) currentBinData.high = value.at(i); - if (i == count-1) // last data point is in current bin, finalize bin: + if( value.at( i ) < currentBinData.low ) + currentBinData.low = value.at( i ); + if( value.at( i ) > currentBinData.high ) + currentBinData.high = value.at( i ); + if( i == count - 1 ) // last data point is in current bin, finalize bin: { - currentBinData.close = value.at(i); - currentBinData.key = timeBinOffset+(index)*timeBinSize; - data.add(currentBinData); + currentBinData.close = value.at( i ); + currentBinData.key = timeBinOffset + (index)*timeBinSize; + data.add( currentBinData ); } - } else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: + } + else // data point not anymore in current bin, set close of old and open of new bin, and add old to map: { // finalize current bin: - currentBinData.close = value.at(i-1); - currentBinData.key = timeBinOffset+(index-1)*timeBinSize; - data.add(currentBinData); + currentBinData.close = value.at( i - 1 ); + currentBinData.key = timeBinOffset + ( index - 1 ) * timeBinSize; + data.add( currentBinData ); // start next bin: currentBinIndex = index; - currentBinData.open = value.at(i); - currentBinData.high = value.at(i); - currentBinData.low = value.at(i); + currentBinData.open = value.at( i ); + currentBinData.high = value.at( i ); + currentBinData.low = value.at( i ); } } - + return data; } /* inherits documentation from base class */ -void QCPFinancial::draw(QCPPainter *painter) +void QCPFinancial::draw( QCPPainter* painter ) { // get visible data range: QCPFinancialDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd); - + getVisibleDataBounds( visibleBegin, visibleEnd ); + // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; - for (int i=0; i= unselectedSegments.size(); QCPFinancialDataContainer::const_iterator begin = visibleBegin; QCPFinancialDataContainer::const_iterator end = visibleEnd; - mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i)); - if (begin == end) + mDataContainer->limitIteratorsToDataRange( begin, end, allSegments.at( i ) ); + if( begin == end ) continue; - + // draw data segment according to configured style: - switch (mChartStyle) + switch( mChartStyle ) { - case QCPFinancial::csOhlc: - drawOhlcPlot(painter, begin, end, isSelectedSegment); break; - case QCPFinancial::csCandlestick: - drawCandlestickPlot(painter, begin, end, isSelectedSegment); break; + case QCPFinancial::csOhlc: + drawOhlcPlot( painter, begin, end, isSelectedSegment ); + break; + case QCPFinancial::csCandlestick: + drawCandlestickPlot( painter, begin, end, isSelectedSegment ); + break; } } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPFinancial::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { - painter->setAntialiasing(false); // legend icon especially of csCandlestick looks better without antialiasing - if (mChartStyle == csOhlc) + painter->setAntialiasing( false ); // legend icon especially of csCandlestick looks better without antialiasing + if( mChartStyle == csOhlc ) { - if (mTwoColored) + if( mTwoColored ) { // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + painter->setBrush( mBrushPositive ); + painter->setPen( mPenPositive ); + painter->setClipRegion( QRegion( QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint() ) ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.2, rect.height() * 0.3, rect.width() * 0.2, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.8, rect.height() * 0.5, rect.width() * 0.8, rect.height() * 0.7 ).translated( rect.topLeft() ) ); // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); - } else - { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.2, rect.height()*0.3, rect.width()*0.2, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.8, rect.height()*0.5, rect.width()*0.8, rect.height()*0.7).translated(rect.topLeft())); + painter->setBrush( mBrushNegative ); + painter->setPen( mPenNegative ); + painter->setClipRegion( QRegion( QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint() ) ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.2, rect.height() * 0.3, rect.width() * 0.2, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.8, rect.height() * 0.5, rect.width() * 0.8, rect.height() * 0.7 ).translated( rect.topLeft() ) ); } - } else if (mChartStyle == csCandlestick) + else + { + painter->setBrush( mBrush ); + painter->setPen( mPen ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.2, rect.height() * 0.3, rect.width() * 0.2, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.8, rect.height() * 0.5, rect.width() * 0.8, rect.height() * 0.7 ).translated( rect.topLeft() ) ); + } + } + else if( mChartStyle == csCandlestick ) { - if (mTwoColored) + if( mTwoColored ) { // draw upper left half icon with positive color: - painter->setBrush(mBrushPositive); - painter->setPen(mPenPositive); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + painter->setBrush( mBrushPositive ); + painter->setPen( mPenPositive ); + painter->setClipRegion( QRegion( QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.topLeft().toPoint() ) ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width() * 0.25, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.75, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawRect( QRectF( rect.width() * 0.25, rect.height() * 0.25, rect.width() * 0.5, rect.height() * 0.5 ).translated( rect.topLeft() ) ); // draw bottom right half icon with negative color: - painter->setBrush(mBrushNegative); - painter->setPen(mPenNegative); - painter->setClipRegion(QRegion(QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint())); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); - } else + painter->setBrush( mBrushNegative ); + painter->setPen( mPenNegative ); + painter->setClipRegion( QRegion( QPolygon() << rect.bottomLeft().toPoint() << rect.topRight().toPoint() << rect.bottomRight().toPoint() ) ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width() * 0.25, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.75, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawRect( QRectF( rect.width() * 0.25, rect.height() * 0.25, rect.width() * 0.5, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + } + else { - painter->setBrush(mBrush); - painter->setPen(mPen); - painter->drawLine(QLineF(0, rect.height()*0.5, rect.width()*0.25, rect.height()*0.5).translated(rect.topLeft())); - painter->drawLine(QLineF(rect.width()*0.75, rect.height()*0.5, rect.width(), rect.height()*0.5).translated(rect.topLeft())); - painter->drawRect(QRectF(rect.width()*0.25, rect.height()*0.25, rect.width()*0.5, rect.height()*0.5).translated(rect.topLeft())); + painter->setBrush( mBrush ); + painter->setPen( mPen ); + painter->drawLine( QLineF( 0, rect.height() * 0.5, rect.width() * 0.25, rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawLine( QLineF( rect.width() * 0.75, rect.height() * 0.5, rect.width(), rect.height() * 0.5 ).translated( rect.topLeft() ) ); + painter->drawRect( QRectF( rect.width() * 0.25, rect.height() * 0.25, rect.width() * 0.5, rect.height() * 0.5 ).translated( rect.topLeft() ) ); } } } @@ -26751,53 +27270,58 @@ void QCPFinancial::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const This method is a helper function for \ref draw. It is used when the chart style is \ref csOhlc. */ -void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +void QCPFinancial::drawOhlcPlot( QCPPainter* painter, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, bool isSelected ) { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + if( keyAxis->orientation() == Qt::Horizontal ) + { + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + if( isSelected && mSelectionDecorator ) + mSelectionDecorator->applyPen( painter ); + else if( mTwoColored ) + painter->setPen( it->close >= it->open ? mPenPositive : mPenNegative ); else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); + painter->setPen( mPen ); + double keyPixel = keyAxis->coordToPixel( it->key ); + double openPixel = valueAxis->coordToPixel( it->open ); + double closePixel = valueAxis->coordToPixel( it->close ); // draw backbone: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(it->low))); + painter->drawLine( QPointF( keyPixel, valueAxis->coordToPixel( it->high ) ), QPointF( keyPixel, valueAxis->coordToPixel( it->low ) ) ); // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(keyPixel-pixelWidth, openPixel), QPointF(keyPixel, openPixel)); + double pixelWidth = getPixelWidth( it->key, keyPixel ); // sign of this makes sure open/close are on correct sides + painter->drawLine( QPointF( keyPixel - pixelWidth, openPixel ), QPointF( keyPixel, openPixel ) ); // draw close: - painter->drawLine(QPointF(keyPixel, closePixel), QPointF(keyPixel+pixelWidth, closePixel)); + painter->drawLine( QPointF( keyPixel, closePixel ), QPointF( keyPixel + pixelWidth, closePixel ) ); } - } else + } + else { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { - if (isSelected && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); - else if (mTwoColored) - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); + if( isSelected && mSelectionDecorator ) + mSelectionDecorator->applyPen( painter ); + else if( mTwoColored ) + painter->setPen( it->close >= it->open ? mPenPositive : mPenNegative ); else - painter->setPen(mPen); - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); + painter->setPen( mPen ); + double keyPixel = keyAxis->coordToPixel( it->key ); + double openPixel = valueAxis->coordToPixel( it->open ); + double closePixel = valueAxis->coordToPixel( it->close ); // draw backbone: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(it->low), keyPixel)); + painter->drawLine( QPointF( valueAxis->coordToPixel( it->high ), keyPixel ), QPointF( valueAxis->coordToPixel( it->low ), keyPixel ) ); // draw open: - double pixelWidth = getPixelWidth(it->key, keyPixel); // sign of this makes sure open/close are on correct sides - painter->drawLine(QPointF(openPixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel)); + double pixelWidth = getPixelWidth( it->key, keyPixel ); // sign of this makes sure open/close are on correct sides + painter->drawLine( QPointF( openPixel, keyPixel - pixelWidth ), QPointF( openPixel, keyPixel ) ); // draw close: - painter->drawLine(QPointF(closePixel, keyPixel), QPointF(closePixel, keyPixel+pixelWidth)); + painter->drawLine( QPointF( closePixel, keyPixel ), QPointF( closePixel, keyPixel + pixelWidth ) ); } } } @@ -26808,67 +27332,76 @@ void QCPFinancial::drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataConta This method is a helper function for \ref draw. It is used when the chart style is \ref csCandlestick. */ -void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected) +void QCPFinancial::drawCandlestickPlot( QCPPainter* painter, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, bool isSelected ) { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - - if (keyAxis->orientation() == Qt::Horizontal) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + + if( keyAxis->orientation() == Qt::Horizontal ) + { + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { - if (isSelected && mSelectionDecorator) + if( isSelected && mSelectionDecorator ) { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); + mSelectionDecorator->applyPen( painter ); + mSelectionDecorator->applyBrush( painter ); } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); + else if( mTwoColored ) + { + painter->setPen( it->close >= it->open ? mPenPositive : mPenNegative ); + painter->setBrush( it->close >= it->open ? mBrushPositive : mBrushNegative ); + } + else + { + painter->setPen( mPen ); + painter->setBrush( mBrush ); + } + double keyPixel = keyAxis->coordToPixel( it->key ); + double openPixel = valueAxis->coordToPixel( it->open ); + double closePixel = valueAxis->coordToPixel( it->close ); // draw high: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->high)), QPointF(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); + painter->drawLine( QPointF( keyPixel, valueAxis->coordToPixel( it->high ) ), QPointF( keyPixel, valueAxis->coordToPixel( qMax( it->open, it->close ) ) ) ); // draw low: - painter->drawLine(QPointF(keyPixel, valueAxis->coordToPixel(it->low)), QPointF(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); + painter->drawLine( QPointF( keyPixel, valueAxis->coordToPixel( it->low ) ), QPointF( keyPixel, valueAxis->coordToPixel( qMin( it->open, it->close ) ) ) ); // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(keyPixel-pixelWidth, closePixel), QPointF(keyPixel+pixelWidth, openPixel))); + double pixelWidth = getPixelWidth( it->key, keyPixel ); + painter->drawRect( QRectF( QPointF( keyPixel - pixelWidth, closePixel ), QPointF( keyPixel + pixelWidth, openPixel ) ) ); } - } else // keyAxis->orientation() == Qt::Vertical + } + else // keyAxis->orientation() == Qt::Vertical { - for (QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it) + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { - if (isSelected && mSelectionDecorator) + if( isSelected && mSelectionDecorator ) { - mSelectionDecorator->applyPen(painter); - mSelectionDecorator->applyBrush(painter); - } else if (mTwoColored) - { - painter->setPen(it->close >= it->open ? mPenPositive : mPenNegative); - painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); - } else - { - painter->setPen(mPen); - painter->setBrush(mBrush); + mSelectionDecorator->applyPen( painter ); + mSelectionDecorator->applyBrush( painter ); } - double keyPixel = keyAxis->coordToPixel(it->key); - double openPixel = valueAxis->coordToPixel(it->open); - double closePixel = valueAxis->coordToPixel(it->close); + else if( mTwoColored ) + { + painter->setPen( it->close >= it->open ? mPenPositive : mPenNegative ); + painter->setBrush( it->close >= it->open ? mBrushPositive : mBrushNegative ); + } + else + { + painter->setPen( mPen ); + painter->setBrush( mBrush ); + } + double keyPixel = keyAxis->coordToPixel( it->key ); + double openPixel = valueAxis->coordToPixel( it->open ); + double closePixel = valueAxis->coordToPixel( it->close ); // draw high: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->high), keyPixel), QPointF(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); + painter->drawLine( QPointF( valueAxis->coordToPixel( it->high ), keyPixel ), QPointF( valueAxis->coordToPixel( qMax( it->open, it->close ) ), keyPixel ) ); // draw low: - painter->drawLine(QPointF(valueAxis->coordToPixel(it->low), keyPixel), QPointF(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); + painter->drawLine( QPointF( valueAxis->coordToPixel( it->low ), keyPixel ), QPointF( valueAxis->coordToPixel( qMin( it->open, it->close ) ), keyPixel ) ); // draw open-close box: - double pixelWidth = getPixelWidth(it->key, keyPixel); - painter->drawRect(QRectF(QPointF(closePixel, keyPixel-pixelWidth), QPointF(openPixel, keyPixel+pixelWidth))); + double pixelWidth = getPixelWidth( it->key, keyPixel ); + painter->drawRect( QRectF( QPointF( closePixel, keyPixel - pixelWidth ), QPointF( openPixel, keyPixel + pixelWidth ) ) ); } } } @@ -26885,37 +27418,35 @@ void QCPFinancial::drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDa horizontal axis, the return value is negative. This is important so the open/close flags on the \ref csOhlc bar are drawn to the correct side. */ -double QCPFinancial::getPixelWidth(double key, double keyPixel) const +double QCPFinancial::getPixelWidth( double key, double keyPixel ) const { double result = 0; - switch (mWidthType) + switch( mWidthType ) { - case wtAbsolute: + case wtAbsolute: { + if( mKeyAxis ) + result = mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); + break; + } + case wtAxisRectRatio: { + if( mKeyAxis && mKeyAxis.data()->axisRect() ) { - if (mKeyAxis) - result = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: - { - if (mKeyAxis && mKeyAxis.data()->axisRect()) - { - if (mKeyAxis.data()->orientation() == Qt::Horizontal) - result = mKeyAxis.data()->axisRect()->width()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - else - result = mKeyAxis.data()->axisRect()->height()*mWidth*0.5*mKeyAxis.data()->pixelOrientation(); - } else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: - { - if (mKeyAxis) - result = mKeyAxis.data()->coordToPixel(key+mWidth*0.5)-keyPixel; + if( mKeyAxis.data()->orientation() == Qt::Horizontal ) + result = mKeyAxis.data()->axisRect()->width() * mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; + result = mKeyAxis.data()->axisRect()->height() * mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); } + else + qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; + break; + } + case wtPlotCoords: { + if( mKeyAxis ) + result = mKeyAxis.data()->coordToPixel( key + mWidth * 0.5 ) - keyPixel; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; + } } return result; } @@ -26928,42 +27459,47 @@ double QCPFinancial::getPixelWidth(double key, double keyPixel) const Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical representation of the plottable, and \a closestDataPoint will point to the respective data point. */ -double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +double QCPFinancial::ohlcSelectTest( const QPointF& pos, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, QCPFinancialDataContainer::const_iterator& closestDataPoint ) const { closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1; + } - double minDistSqr = (std::numeric_limits::max)(); - if (keyAxis->orientation() == Qt::Horizontal) + double minDistSqr = ( std::numeric_limits::max )(); + if( keyAxis->orientation() == Qt::Horizontal ) { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { - double keyPixel = keyAxis->coordToPixel(it->key); + double keyPixel = keyAxis->coordToPixel( it->key ); // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low))); - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double keyPixel = keyAxis->coordToPixel(it->key); - // calculate distance to backbone: - double currentDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel)); - if (currentDistSqr < minDistSqr) + double currentDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( keyPixel, valueAxis->coordToPixel( it->high ) ), QCPVector2D( keyPixel, valueAxis->coordToPixel( it->low ) ) ); + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestDataPoint = it; } } } - return qSqrt(minDistSqr); + else // keyAxis->orientation() == Qt::Vertical + { + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) + { + double keyPixel = keyAxis->coordToPixel( it->key ); + // calculate distance to backbone: + double currentDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( valueAxis->coordToPixel( it->high ), keyPixel ), QCPVector2D( valueAxis->coordToPixel( it->low ), keyPixel ) ); + if( currentDistSqr < minDistSqr ) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt( minDistSqr ); } /*! \internal @@ -26975,70 +27511,77 @@ double QCPFinancial::ohlcSelectTest(const QPointF &pos, const QCPFinancialDataCo Like \ref selectTest, this method returns the shortest distance of \a pos to the graphical representation of the plottable, and \a closestDataPoint will point to the respective data point. */ -double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const +double QCPFinancial::candlestickSelectTest( const QPointF& pos, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, QCPFinancialDataContainer::const_iterator& closestDataPoint ) const { closestDataPoint = mDataContainer->constEnd(); - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1; } + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return -1; + } - double minDistSqr = (std::numeric_limits::max)(); - if (keyAxis->orientation() == Qt::Horizontal) + double minDistSqr = ( std::numeric_limits::max )(); + if( keyAxis->orientation() == Qt::Horizontal ) { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) { double currentDistSqr; // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); + QCPRange boxKeyRange( it->key - mWidth * 0.5, it->key + mWidth * 0.5 ); + QCPRange boxValueRange( it->close, it->open ); double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box + pixelsToCoords( pos, posKey, posValue ); + if( boxKeyRange.contains( posKey ) && boxValueRange.contains( posValue ) ) // is in open-close-box { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else + currentDistSqr = mParentPlot->selectionTolerance() * 0.99 * mParentPlot->selectionTolerance() * 0.99; + } + else { // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->high)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMax(it->open, it->close)))); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(keyPixel, valueAxis->coordToPixel(it->low)), QCPVector2D(keyPixel, valueAxis->coordToPixel(qMin(it->open, it->close)))); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); + double keyPixel = keyAxis->coordToPixel( it->key ); + double highLineDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( keyPixel, valueAxis->coordToPixel( it->high ) ), QCPVector2D( keyPixel, valueAxis->coordToPixel( qMax( it->open, it->close ) ) ) ); + double lowLineDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( keyPixel, valueAxis->coordToPixel( it->low ) ), QCPVector2D( keyPixel, valueAxis->coordToPixel( qMin( it->open, it->close ) ) ) ); + currentDistSqr = qMin( highLineDistSqr, lowLineDistSqr ); } - if (currentDistSqr < minDistSqr) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } else // keyAxis->orientation() == Qt::Vertical - { - for (QCPFinancialDataContainer::const_iterator it=begin; it!=end; ++it) - { - double currentDistSqr; - // determine whether pos is in open-close-box: - QCPRange boxKeyRange(it->key-mWidth*0.5, it->key+mWidth*0.5); - QCPRange boxValueRange(it->close, it->open); - double posKey, posValue; - pixelsToCoords(pos, posKey, posValue); - if (boxKeyRange.contains(posKey) && boxValueRange.contains(posValue)) // is in open-close-box - { - currentDistSqr = mParentPlot->selectionTolerance()*0.99 * mParentPlot->selectionTolerance()*0.99; - } else - { - // calculate distance to high/low lines: - double keyPixel = keyAxis->coordToPixel(it->key); - double highLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->high), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMax(it->open, it->close)), keyPixel)); - double lowLineDistSqr = QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(valueAxis->coordToPixel(it->low), keyPixel), QCPVector2D(valueAxis->coordToPixel(qMin(it->open, it->close)), keyPixel)); - currentDistSqr = qMin(highLineDistSqr, lowLineDistSqr); - } - if (currentDistSqr < minDistSqr) + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; closestDataPoint = it; } } } - return qSqrt(minDistSqr); + else // keyAxis->orientation() == Qt::Vertical + { + for( QCPFinancialDataContainer::const_iterator it = begin; it != end; ++it ) + { + double currentDistSqr; + // determine whether pos is in open-close-box: + QCPRange boxKeyRange( it->key - mWidth * 0.5, it->key + mWidth * 0.5 ); + QCPRange boxValueRange( it->close, it->open ); + double posKey, posValue; + pixelsToCoords( pos, posKey, posValue ); + if( boxKeyRange.contains( posKey ) && boxValueRange.contains( posValue ) ) // is in open-close-box + { + currentDistSqr = mParentPlot->selectionTolerance() * 0.99 * mParentPlot->selectionTolerance() * 0.99; + } + else + { + // calculate distance to high/low lines: + double keyPixel = keyAxis->coordToPixel( it->key ); + double highLineDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( valueAxis->coordToPixel( it->high ), keyPixel ), QCPVector2D( valueAxis->coordToPixel( qMax( it->open, it->close ) ), keyPixel ) ); + double lowLineDistSqr = QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( valueAxis->coordToPixel( it->low ), keyPixel ), QCPVector2D( valueAxis->coordToPixel( qMin( it->open, it->close ) ), keyPixel ) ); + currentDistSqr = qMin( highLineDistSqr, lowLineDistSqr ); + } + if( currentDistSqr < minDistSqr ) + { + minDistSqr = currentDistSqr; + closestDataPoint = it; + } + } + } + return qSqrt( minDistSqr ); } /*! \internal @@ -27055,17 +27598,17 @@ double QCPFinancial::candlestickSelectTest(const QPointF &pos, const QCPFinancia if the plottable contains no data, both \a begin and \a end point to \c constEnd. */ -void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const +void QCPFinancial::getVisibleDataBounds( QCPFinancialDataContainer::const_iterator& begin, QCPFinancialDataContainer::const_iterator& end ) const { - if (!mKeyAxis) + if( !mKeyAxis ) { qDebug() << Q_FUNC_INFO << "invalid key axis"; begin = mDataContainer->constEnd(); end = mDataContainer->constEnd(); return; } - begin = mDataContainer->findBegin(mKeyAxis.data()->range().lower-mWidth*0.5); // subtract half width of ohlc/candlestick to include partially visible data points - end = mDataContainer->findEnd(mKeyAxis.data()->range().upper+mWidth*0.5); // add half width of ohlc/candlestick to include partially visible data points + begin = mDataContainer->findBegin( mKeyAxis.data()->range().lower - mWidth * 0.5 ); // subtract half width of ohlc/candlestick to include partially visible data points + end = mDataContainer->findEnd( mKeyAxis.data()->range().upper + mWidth * 0.5 ); // add half width of ohlc/candlestick to include partially visible data points } /*! \internal @@ -27073,24 +27616,27 @@ void QCPFinancial::getVisibleDataBounds(QCPFinancialDataContainer::const_iterato Returns the hit box in pixel coordinates that will be used for data selection with the selection rect (\ref selectTestRect), of the data point given by \a it. */ -QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator it) const +QRectF QCPFinancial::selectionHitBox( QCPFinancialDataContainer::const_iterator it ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QRectF(); } - - double keyPixel = keyAxis->coordToPixel(it->key); - double highPixel = valueAxis->coordToPixel(it->high); - double lowPixel = valueAxis->coordToPixel(it->low); - double keyWidthPixels = keyPixel-keyAxis->coordToPixel(it->key-mWidth*0.5); - if (keyAxis->orientation() == Qt::Horizontal) - return QRectF(keyPixel-keyWidthPixels, highPixel, keyWidthPixels*2, lowPixel-highPixel).normalized(); + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return QRectF(); + } + + double keyPixel = keyAxis->coordToPixel( it->key ); + double highPixel = valueAxis->coordToPixel( it->high ); + double lowPixel = valueAxis->coordToPixel( it->low ); + double keyWidthPixels = keyPixel - keyAxis->coordToPixel( it->key - mWidth * 0.5 ); + if( keyAxis->orientation() == Qt::Horizontal ) + return QRectF( keyPixel - keyWidthPixels, highPixel, keyWidthPixels * 2, lowPixel - highPixel ).normalized(); else - return QRectF(highPixel, keyPixel-keyWidthPixels, lowPixel-highPixel, keyWidthPixels*2).normalized(); + return QRectF( highPixel, keyPixel - keyWidthPixels, lowPixel - highPixel, keyWidthPixels * 2 ).normalized(); } /* end of 'src/plottables/plottable-financial.cpp' */ - /* including file 'src/plottables/plottable-errorbar.cpp', size 37570 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -27116,18 +27662,16 @@ QRectF QCPFinancial::selectionHitBox(QCPFinancialDataContainer::const_iterator i /*! Constructs an error bar with errors set to zero. */ -QCPErrorBarsData::QCPErrorBarsData() : - errorMinus(0), - errorPlus(0) +QCPErrorBarsData::QCPErrorBarsData() + : errorMinus( 0 ), errorPlus( 0 ) { } /*! Constructs an error bar with equal \a error in both negative and positive direction. */ -QCPErrorBarsData::QCPErrorBarsData(double error) : - errorMinus(error), - errorPlus(error) +QCPErrorBarsData::QCPErrorBarsData( double error ) + : errorMinus( error ), errorPlus( error ) { } @@ -27135,13 +27679,11 @@ QCPErrorBarsData::QCPErrorBarsData(double error) : Constructs an error bar with negative and positive errors set to \a errorMinus and \a errorPlus, respectively. */ -QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : - errorMinus(errorMinus), - errorPlus(errorPlus) +QCPErrorBarsData::QCPErrorBarsData( double errorMinus, double errorPlus ) + : errorMinus( errorMinus ), errorPlus( errorPlus ) { } - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPErrorBars //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -27199,15 +27741,11 @@ QCPErrorBarsData::QCPErrorBarsData(double errorMinus, double errorPlus) : from \a keyAxis. This QCustomPlot instance takes ownership of the \ref QCPErrorBars, so do not delete it manually but use \ref QCustomPlot::removePlottable() instead. */ -QCPErrorBars::QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QVector), - mErrorType(etValueError), - mWhiskerWidth(9), - mSymbolGap(10) +QCPErrorBars::QCPErrorBars( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable( keyAxis, valueAxis ), mDataContainer( new QVector ), mErrorType( etValueError ), mWhiskerWidth( 9 ), mSymbolGap( 10 ) { - setPen(QPen(Qt::black, 0)); - setBrush(Qt::NoBrush); + setPen( QPen( Qt::black, 0 ) ); + setBrush( Qt::NoBrush ); } QCPErrorBars::~QCPErrorBars() @@ -27232,7 +27770,7 @@ QCPErrorBars::~QCPErrorBars() \see addData */ -void QCPErrorBars::setData(QSharedPointer data) +void QCPErrorBars::setData( QSharedPointer data ) { mDataContainer = data; } @@ -27246,10 +27784,10 @@ void QCPErrorBars::setData(QSharedPointer data) \see addData */ -void QCPErrorBars::setData(const QVector &error) +void QCPErrorBars::setData( const QVector& error ) { mDataContainer->clear(); - addData(error); + addData( error ); } /*! \overload @@ -27262,10 +27800,10 @@ void QCPErrorBars::setData(const QVector &error) \see addData */ -void QCPErrorBars::setData(const QVector &errorMinus, const QVector &errorPlus) +void QCPErrorBars::setData( const QVector& errorMinus, const QVector& errorPlus ) { mDataContainer->clear(); - addData(errorMinus, errorPlus); + addData( errorMinus, errorPlus ); } /*! @@ -27282,21 +27820,21 @@ void QCPErrorBars::setData(const QVector &errorMinus, const QVector(plottable)) + if( plottable && qobject_cast( plottable ) ) { mDataPlottable = 0; qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; return; } - if (plottable && !plottable->interface1D()) + if( plottable && !plottable->interface1D() ) { mDataPlottable = 0; qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; return; } - + mDataPlottable = plottable; } @@ -27304,7 +27842,7 @@ void QCPErrorBars::setDataPlottable(QCPAbstractPlottable *plottable) Sets in which orientation the error bars shall appear on the data points. If your data needs both error dimensions, create two \ref QCPErrorBars with different \a type. */ -void QCPErrorBars::setErrorType(ErrorType type) +void QCPErrorBars::setErrorType( ErrorType type ) { mErrorType = type; } @@ -27313,7 +27851,7 @@ void QCPErrorBars::setErrorType(ErrorType type) Sets the width of the whiskers (the short bars at the end of the actual error bar backbones) to \a pixels. */ -void QCPErrorBars::setWhiskerWidth(double pixels) +void QCPErrorBars::setWhiskerWidth( double pixels ) { mWhiskerWidth = pixels; } @@ -27323,7 +27861,7 @@ void QCPErrorBars::setWhiskerWidth(double pixels) backbones. This gap prevents that error bars are drawn too close to or even through scatter points. */ -void QCPErrorBars::setSymbolGap(double pixels) +void QCPErrorBars::setSymbolGap( double pixels ) { mSymbolGap = pixels; } @@ -27337,9 +27875,9 @@ void QCPErrorBars::setSymbolGap(double pixels) \see setData */ -void QCPErrorBars::addData(const QVector &error) +void QCPErrorBars::addData( const QVector& error ) { - addData(error, error); + addData( error, error ); } /*! \overload @@ -27352,14 +27890,14 @@ void QCPErrorBars::addData(const QVector &error) \see setData */ -void QCPErrorBars::addData(const QVector &errorMinus, const QVector &errorPlus) +void QCPErrorBars::addData( const QVector& errorMinus, const QVector& errorPlus ) { - if (errorMinus.size() != errorPlus.size()) + if( errorMinus.size() != errorPlus.size() ) qDebug() << Q_FUNC_INFO << "minus and plus error vectors have different sizes:" << errorMinus.size() << errorPlus.size(); - const int n = qMin(errorMinus.size(), errorPlus.size()); - mDataContainer->reserve(n); - for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); + const int n = qMin( errorMinus.size(), errorPlus.size() ); + mDataContainer->reserve( n ); + for( int i = 0; i < n; ++i ) + mDataContainer->append( QCPErrorBarsData( errorMinus.at( i ), errorPlus.at( i ) ) ); } /*! \overload @@ -27371,9 +27909,9 @@ void QCPErrorBars::addData(const QVector &errorMinus, const QVectorappend(QCPErrorBarsData(error)); + mDataContainer->append( QCPErrorBarsData( error ) ); } /*! \overload @@ -27386,9 +27924,9 @@ void QCPErrorBars::addData(double error) \see setData */ -void QCPErrorBars::addData(double errorMinus, double errorPlus) +void QCPErrorBars::addData( double errorMinus, double errorPlus ) { - mDataContainer->append(QCPErrorBarsData(errorMinus, errorPlus)); + mDataContainer->append( QCPErrorBarsData( errorMinus, errorPlus ) ); } /* inherits documentation from base class */ @@ -27398,46 +27936,47 @@ int QCPErrorBars::dataCount() const } /* inherits documentation from base class */ -double QCPErrorBars::dataMainKey(int index) const +double QCPErrorBars::dataMainKey( int index ) const { - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainKey(index); + if( mDataPlottable ) + return mDataPlottable->interface1D()->dataMainKey( index ); else qDebug() << Q_FUNC_INFO << "no data plottable set"; return 0; } /* inherits documentation from base class */ -double QCPErrorBars::dataSortKey(int index) const +double QCPErrorBars::dataSortKey( int index ) const { - if (mDataPlottable) - return mDataPlottable->interface1D()->dataSortKey(index); + if( mDataPlottable ) + return mDataPlottable->interface1D()->dataSortKey( index ); else qDebug() << Q_FUNC_INFO << "no data plottable set"; return 0; } /* inherits documentation from base class */ -double QCPErrorBars::dataMainValue(int index) const +double QCPErrorBars::dataMainValue( int index ) const { - if (mDataPlottable) - return mDataPlottable->interface1D()->dataMainValue(index); + if( mDataPlottable ) + return mDataPlottable->interface1D()->dataMainValue( index ); else qDebug() << Q_FUNC_INFO << "no data plottable set"; return 0; } /* inherits documentation from base class */ -QCPRange QCPErrorBars::dataValueRange(int index) const +QCPRange QCPErrorBars::dataValueRange( int index ) const { - if (mDataPlottable) + if( mDataPlottable ) { - const double value = mDataPlottable->interface1D()->dataMainValue(index); - if (index >= 0 && index < mDataContainer->size() && mErrorType == etValueError) - return QCPRange(value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus); + const double value = mDataPlottable->interface1D()->dataMainValue( index ); + if( index >= 0 && index < mDataContainer->size() && mErrorType == etValueError ) + return QCPRange( value - mDataContainer->at( index ).errorMinus, value + mDataContainer->at( index ).errorPlus ); else - return QCPRange(value, value); - } else + return QCPRange( value, value ); + } + else { qDebug() << Q_FUNC_INFO << "no data plottable set"; return QCPRange(); @@ -27445,10 +27984,10 @@ QCPRange QCPErrorBars::dataValueRange(int index) const } /* inherits documentation from base class */ -QPointF QCPErrorBars::dataPixelPosition(int index) const +QPointF QCPErrorBars::dataPixelPosition( int index ) const { - if (mDataPlottable) - return mDataPlottable->interface1D()->dataPixelPosition(index); + if( mDataPlottable ) + return mDataPlottable->interface1D()->dataPixelPosition( index ); else qDebug() << Q_FUNC_INFO << "no data plottable set"; return QPointF(); @@ -27457,10 +27996,11 @@ QPointF QCPErrorBars::dataPixelPosition(int index) const /* inherits documentation from base class */ bool QCPErrorBars::sortKeyIsMainKey() const { - if (mDataPlottable) + if( mDataPlottable ) { return mDataPlottable->interface1D()->sortKeyIsMainKey(); - } else + } + else { qDebug() << Q_FUNC_INFO << "no data plottable set"; return true; @@ -27470,30 +28010,30 @@ bool QCPErrorBars::sortKeyIsMainKey() const /*! \copydoc QCPPlottableInterface1D::selectTestRect */ -QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelectable) const +QCPDataSelection QCPErrorBars::selectTestRect( const QRectF& rect, bool onlySelectable ) const { QCPDataSelection result; - if (!mDataPlottable) + if( !mDataPlottable ) return result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return result; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return result; - + QCPErrorBarsDataContainer::const_iterator visibleBegin, visibleEnd; - getVisibleDataBounds(visibleBegin, visibleEnd, QCPDataRange(0, dataCount())); - + getVisibleDataBounds( visibleBegin, visibleEnd, QCPDataRange( 0, dataCount() ) ); + QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=visibleBegin; it!=visibleEnd; ++it) + for( QCPErrorBarsDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) { backbones.clear(); whiskers.clear(); - getErrorBarLines(it, backbones, whiskers); - for (int i=0; iconstBegin(), it-mDataContainer->constBegin()+1), false); + result.addDataRange( QCPDataRange( it - mDataContainer->constBegin(), it - mDataContainer->constBegin() + 1 ), false ); break; } } @@ -27503,33 +28043,35 @@ QCPDataSelection QCPErrorBars::selectTestRect(const QRectF &rect, bool onlySelec } /* inherits documentation from base class */ -int QCPErrorBars::findBegin(double sortKey, bool expandedRange) const +int QCPErrorBars::findBegin( double sortKey, bool expandedRange ) const { - if (mDataPlottable) + if( mDataPlottable ) { - if (mDataContainer->isEmpty()) + if( mDataContainer->isEmpty() ) return 0; - int beginIndex = mDataPlottable->interface1D()->findBegin(sortKey, expandedRange); - if (beginIndex >= mDataContainer->size()) - beginIndex = mDataContainer->size()-1; + int beginIndex = mDataPlottable->interface1D()->findBegin( sortKey, expandedRange ); + if( beginIndex >= mDataContainer->size() ) + beginIndex = mDataContainer->size() - 1; return beginIndex; - } else + } + else qDebug() << Q_FUNC_INFO << "no data plottable set"; return 0; } /* inherits documentation from base class */ -int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const +int QCPErrorBars::findEnd( double sortKey, bool expandedRange ) const { - if (mDataPlottable) + if( mDataPlottable ) { - if (mDataContainer->isEmpty()) + if( mDataContainer->isEmpty() ) return 0; - int endIndex = mDataPlottable->interface1D()->findEnd(sortKey, expandedRange); - if (endIndex > mDataContainer->size()) + int endIndex = mDataPlottable->interface1D()->findEnd( sortKey, expandedRange ); + if( endIndex > mDataContainer->size() ) endIndex = mDataContainer->size(); return endIndex; - } else + } + else qDebug() << Q_FUNC_INFO << "no data plottable set"; return 0; } @@ -27542,161 +28084,174 @@ int QCPErrorBars::findEnd(double sortKey, bool expandedRange) const \seebaseclassmethod \ref QCPAbstractPlottable::selectTest */ -double QCPErrorBars::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPErrorBars::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if (!mDataPlottable) return -1; - - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( !mDataPlottable ) return -1; - if (!mKeyAxis || !mValueAxis) + + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - - if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint())) + if( !mKeyAxis || !mValueAxis ) + return -1; + + if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) ) { QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance(pos, closestDataPoint); - if (details) + double result = pointDistance( pos, closestDataPoint ); + if( details ) { - int pointIndex = closestDataPoint-mDataContainer->constBegin(); - details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); + int pointIndex = closestDataPoint - mDataContainer->constBegin(); + details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); } return result; - } else + } + else return -1; } /* inherits documentation from base class */ -void QCPErrorBars::draw(QCPPainter *painter) +void QCPErrorBars::draw( QCPPainter* painter ) { - if (!mDataPlottable) return; - if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } - if (mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty()) return; - + if( !mDataPlottable ) + return; + if( !mKeyAxis || !mValueAxis ) + { + qDebug() << Q_FUNC_INFO << "invalid key or value axis"; + return; + } + if( mKeyAxis.data()->range().size() <= 0 || mDataContainer->isEmpty() ) + return; + // if the sort key isn't the main key, we must check the visibility for each data point/error bar individually // (getVisibleDataBounds applies range restriction, but otherwise can only return full data range): bool checkPointVisibility = !mDataPlottable->interface1D()->sortKeyIsMainKey(); - - // check data validity if flag set: + + // check data validity if flag set: #ifdef QCUSTOMPLOT_CHECK_DATA QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + for( it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it ) { - if (QCP::isInvalidData(it->errorMinus, it->errorPlus)) - qDebug() << Q_FUNC_INFO << "Data point at index" << it-mDataContainer->constBegin() << "invalid." << "Plottable name:" << name(); + if( QCP::isInvalidData( it->errorMinus, it->errorPlus ) ) + qDebug() << Q_FUNC_INFO << "Data point at index" << it - mDataContainer->constBegin() << "invalid." + << "Plottable name:" << name(); } #endif - - applyDefaultAntialiasingHint(painter); - painter->setBrush(Qt::NoBrush); + + applyDefaultAntialiasingHint( painter ); + painter->setBrush( Qt::NoBrush ); // loop over and draw segments of unselected/selected data: QList selectedSegments, unselectedSegments, allSegments; - getDataSegments(selectedSegments, unselectedSegments); + getDataSegments( selectedSegments, unselectedSegments ); allSegments << unselectedSegments << selectedSegments; QVector backbones, whiskers; - for (int i=0; i= unselectedSegments.size(); - if (isSelectedSegment && mSelectionDecorator) - mSelectionDecorator->applyPen(painter); + if( isSelectedSegment && mSelectionDecorator ) + mSelectionDecorator->applyPen( painter ); else - painter->setPen(mPen); - if (painter->pen().capStyle() == Qt::SquareCap) + painter->setPen( mPen ); + if( painter->pen().capStyle() == Qt::SquareCap ) { - QPen capFixPen(painter->pen()); - capFixPen.setCapStyle(Qt::FlatCap); - painter->setPen(capFixPen); + QPen capFixPen( painter->pen() ); + capFixPen.setCapStyle( Qt::FlatCap ); + painter->setPen( capFixPen ); } backbones.clear(); whiskers.clear(); - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + for( QCPErrorBarsDataContainer::const_iterator it = begin; it != end; ++it ) { - if (!checkPointVisibility || errorBarVisible(it-mDataContainer->constBegin())) - getErrorBarLines(it, backbones, whiskers); + if( !checkPointVisibility || errorBarVisible( it - mDataContainer->constBegin() ) ) + getErrorBarLines( it, backbones, whiskers ); } - painter->drawLines(backbones); - painter->drawLines(whiskers); + painter->drawLines( backbones ); + painter->drawLines( whiskers ); } - + // draw other selection decoration that isn't just line/scatter pens and brushes: - if (mSelectionDecorator) - mSelectionDecorator->drawDecoration(painter, selection()); + if( mSelectionDecorator ) + mSelectionDecorator->drawDecoration( painter, selection() ); } /* inherits documentation from base class */ -void QCPErrorBars::drawLegendIcon(QCPPainter *painter, const QRectF &rect) const +void QCPErrorBars::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const { - applyDefaultAntialiasingHint(painter); - painter->setPen(mPen); - if (mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical) + applyDefaultAntialiasingHint( painter ); + painter->setPen( mPen ); + if( mErrorType == etValueError && mValueAxis && mValueAxis->orientation() == Qt::Vertical ) { - painter->drawLine(QLineF(rect.center().x(), rect.top()+2, rect.center().x(), rect.bottom()-1)); - painter->drawLine(QLineF(rect.center().x()-4, rect.top()+2, rect.center().x()+4, rect.top()+2)); - painter->drawLine(QLineF(rect.center().x()-4, rect.bottom()-1, rect.center().x()+4, rect.bottom()-1)); - } else + painter->drawLine( QLineF( rect.center().x(), rect.top() + 2, rect.center().x(), rect.bottom() - 1 ) ); + painter->drawLine( QLineF( rect.center().x() - 4, rect.top() + 2, rect.center().x() + 4, rect.top() + 2 ) ); + painter->drawLine( QLineF( rect.center().x() - 4, rect.bottom() - 1, rect.center().x() + 4, rect.bottom() - 1 ) ); + } + else { - painter->drawLine(QLineF(rect.left()+2, rect.center().y(), rect.right()-2, rect.center().y())); - painter->drawLine(QLineF(rect.left()+2, rect.center().y()-4, rect.left()+2, rect.center().y()+4)); - painter->drawLine(QLineF(rect.right()-2, rect.center().y()-4, rect.right()-2, rect.center().y()+4)); + painter->drawLine( QLineF( rect.left() + 2, rect.center().y(), rect.right() - 2, rect.center().y() ) ); + painter->drawLine( QLineF( rect.left() + 2, rect.center().y() - 4, rect.left() + 2, rect.center().y() + 4 ) ); + painter->drawLine( QLineF( rect.right() - 2, rect.center().y() - 4, rect.right() - 2, rect.center().y() + 4 ) ); } } /* inherits documentation from base class */ -QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const +QCPRange QCPErrorBars::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const { - if (!mDataPlottable) + if( !mDataPlottable ) { foundRange = false; return QCPRange(); } - + QCPRange range; bool haveLower = false; bool haveUpper = false; QCPErrorBarsDataContainer::const_iterator it; - for (it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it) + for( it = mDataContainer->constBegin(); it != mDataContainer->constEnd(); ++it ) { - if (mErrorType == etValueError) + if( mErrorType == etValueError ) { // error bar doesn't extend in key dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + const double current = mDataPlottable->interface1D()->dataMainKey( it - mDataContainer->constBegin() ); + if( qIsNaN( current ) ) + continue; + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; } - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; } } - } else // mErrorType == etKeyError + } + else // mErrorType == etKeyError { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (qIsNaN(dataKey)) continue; + const double dataKey = mDataPlottable->interface1D()->dataMainKey( it - mDataContainer->constBegin() ); + if( qIsNaN( dataKey ) ) + continue; // plus error: - double current = dataKey + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + double current = dataKey + ( qIsNaN( it->errorPlus ) ? 0 : it->errorPlus ); + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; } } // minus error: - current = dataKey - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + current = dataKey - ( qIsNaN( it->errorMinus ) ? 0 : it->errorMinus ); + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; @@ -27704,86 +28259,90 @@ QCPRange QCPErrorBars::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomai } } } - - if (haveUpper && !haveLower) + + if( haveUpper && !haveLower ) { range.lower = range.upper; haveLower = true; - } else if (haveLower && !haveUpper) + } + else if( haveLower && !haveUpper ) { range.upper = range.lower; haveUpper = true; } - + foundRange = haveLower && haveUpper; return range; } /* inherits documentation from base class */ -QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDomain, const QCPRange &inKeyRange) const +QCPRange QCPErrorBars::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const { - if (!mDataPlottable) + if( !mDataPlottable ) { foundRange = false; return QCPRange(); } - + QCPRange range; const bool restrictKeyRange = inKeyRange != QCPRange(); bool haveLower = false; bool haveUpper = false; QCPErrorBarsDataContainer::const_iterator itBegin = mDataContainer->constBegin(); QCPErrorBarsDataContainer::const_iterator itEnd = mDataContainer->constEnd(); - if (mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange) + if( mDataPlottable->interface1D()->sortKeyIsMainKey() && restrictKeyRange ) { - itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower); - itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper); + itBegin = mDataContainer->constBegin() + findBegin( inKeyRange.lower ); + itEnd = mDataContainer->constBegin() + findEnd( inKeyRange.upper ); } - for (QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + for( QCPErrorBarsDataContainer::const_iterator it = itBegin; it != itEnd; ++it ) { - if (restrictKeyRange) + if( restrictKeyRange ) { - const double dataKey = mDataPlottable->interface1D()->dataMainKey(it-mDataContainer->constBegin()); - if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) + const double dataKey = mDataPlottable->interface1D()->dataMainKey( it - mDataContainer->constBegin() ); + if( dataKey < inKeyRange.lower || dataKey > inKeyRange.upper ) continue; } - if (mErrorType == etValueError) + if( mErrorType == etValueError ) { - const double dataValue = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(dataValue)) continue; + const double dataValue = mDataPlottable->interface1D()->dataMainValue( it - mDataContainer->constBegin() ); + if( qIsNaN( dataValue ) ) + continue; // plus error: - double current = dataValue + (qIsNaN(it->errorPlus) ? 0 : it->errorPlus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + double current = dataValue + ( qIsNaN( it->errorPlus ) ? 0 : it->errorPlus ); + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; } } // minus error: - current = dataValue - (qIsNaN(it->errorMinus) ? 0 : it->errorMinus); - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + current = dataValue - ( qIsNaN( it->errorMinus ) ? 0 : it->errorMinus ); + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; } } - } else // mErrorType == etKeyError + } + else // mErrorType == etKeyError { // error bar doesn't extend in value dimension (except whisker but we ignore that here), so only use data point center - const double current = mDataPlottable->interface1D()->dataMainValue(it-mDataContainer->constBegin()); - if (qIsNaN(current)) continue; - if (inSignDomain == QCP::sdBoth || (inSignDomain == QCP::sdNegative && current < 0) || (inSignDomain == QCP::sdPositive && current > 0)) + const double current = mDataPlottable->interface1D()->dataMainValue( it - mDataContainer->constBegin() ); + if( qIsNaN( current ) ) + continue; + if( inSignDomain == QCP::sdBoth || ( inSignDomain == QCP::sdNegative && current < 0 ) || ( inSignDomain == QCP::sdPositive && current > 0 ) ) { - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; } - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; @@ -27791,17 +28350,18 @@ QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDom } } } - - if (haveUpper && !haveLower) + + if( haveUpper && !haveLower ) { range.lower = range.upper; haveLower = true; - } else if (haveLower && !haveUpper) + } + else if( haveLower && !haveUpper ) { range.upper = range.lower; haveUpper = true; } - + foundRange = haveLower && haveUpper; return range; } @@ -27817,53 +28377,56 @@ QCPRange QCPErrorBars::getValueRange(bool &foundRange, QCP::SignDomain inSignDom This method assumes that \a it is a valid iterator within the bounds of this \ref QCPErrorBars instance and within the bounds of the associated data plottable. */ -void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const +void QCPErrorBars::getErrorBarLines( QCPErrorBarsDataContainer::const_iterator it, QVector& backbones, QVector& whiskers ) const { - if (!mDataPlottable) return; - - int index = it-mDataContainer->constBegin(); - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); - if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) + if( !mDataPlottable ) return; - QCPAxis *errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); - QCPAxis *orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); + + int index = it - mDataContainer->constBegin(); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition( index ); + if( qIsNaN( centerPixel.x() ) || qIsNaN( centerPixel.y() ) ) + return; + QCPAxis* errorAxis = mErrorType == etValueError ? mValueAxis.data() : mKeyAxis.data(); + QCPAxis* orthoAxis = mErrorType == etValueError ? mKeyAxis.data() : mValueAxis.data(); const double centerErrorAxisPixel = errorAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); const double centerOrthoAxisPixel = orthoAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - const double centerErrorAxisCoord = errorAxis->pixelToCoord(centerErrorAxisPixel); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value - const double symbolGap = mSymbolGap*0.5*errorAxis->pixelOrientation(); + const double centerErrorAxisCoord = errorAxis->pixelToCoord( centerErrorAxisPixel ); // depending on plottable, this might be different from just mDataPlottable->interface1D()->dataMainKey/Value + const double symbolGap = mSymbolGap * 0.5 * errorAxis->pixelOrientation(); // plus error: double errorStart, errorEnd; - if (!qIsNaN(it->errorPlus)) + if( !qIsNaN( it->errorPlus ) ) { - errorStart = centerErrorAxisPixel+symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord+it->errorPlus); - if (errorAxis->orientation() == Qt::Vertical) + errorStart = centerErrorAxisPixel + symbolGap; + errorEnd = errorAxis->coordToPixel( centerErrorAxisCoord + it->errorPlus ); + if( errorAxis->orientation() == Qt::Vertical ) { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else + if( ( errorStart > errorEnd ) != errorAxis->rangeReversed() ) + backbones.append( QLineF( centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd ) ); + whiskers.append( QLineF( centerOrthoAxisPixel - mWhiskerWidth * 0.5, errorEnd, centerOrthoAxisPixel + mWhiskerWidth * 0.5, errorEnd ) ); + } + else { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + if( ( errorStart < errorEnd ) != errorAxis->rangeReversed() ) + backbones.append( QLineF( errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel ) ); + whiskers.append( QLineF( errorEnd, centerOrthoAxisPixel - mWhiskerWidth * 0.5, errorEnd, centerOrthoAxisPixel + mWhiskerWidth * 0.5 ) ); } } // minus error: - if (!qIsNaN(it->errorMinus)) + if( !qIsNaN( it->errorMinus ) ) { - errorStart = centerErrorAxisPixel-symbolGap; - errorEnd = errorAxis->coordToPixel(centerErrorAxisCoord-it->errorMinus); - if (errorAxis->orientation() == Qt::Vertical) + errorStart = centerErrorAxisPixel - symbolGap; + errorEnd = errorAxis->coordToPixel( centerErrorAxisCoord - it->errorMinus ); + if( errorAxis->orientation() == Qt::Vertical ) { - if ((errorStart < errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd)); - whiskers.append(QLineF(centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5, errorEnd)); - } else + if( ( errorStart < errorEnd ) != errorAxis->rangeReversed() ) + backbones.append( QLineF( centerOrthoAxisPixel, errorStart, centerOrthoAxisPixel, errorEnd ) ); + whiskers.append( QLineF( centerOrthoAxisPixel - mWhiskerWidth * 0.5, errorEnd, centerOrthoAxisPixel + mWhiskerWidth * 0.5, errorEnd ) ); + } + else { - if ((errorStart > errorEnd) != errorAxis->rangeReversed()) - backbones.append(QLineF(errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel)); - whiskers.append(QLineF(errorEnd, centerOrthoAxisPixel-mWhiskerWidth*0.5, errorEnd, centerOrthoAxisPixel+mWhiskerWidth*0.5)); + if( ( errorStart > errorEnd ) != errorAxis->rangeReversed() ) + backbones.append( QLineF( errorStart, centerOrthoAxisPixel, errorEnd, centerOrthoAxisPixel ) ); + whiskers.append( QLineF( errorEnd, centerOrthoAxisPixel - mWhiskerWidth * 0.5, errorEnd, centerOrthoAxisPixel + mWhiskerWidth * 0.5 ) ); } } } @@ -27886,57 +28449,57 @@ void QCPErrorBars::getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it range, only restricted by \a rangeRestriction. Drawing optimization then has to be done on a point-by-point basis in the \ref draw method. */ -void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const +void QCPErrorBars::getVisibleDataBounds( QCPErrorBarsDataContainer::const_iterator& begin, QCPErrorBarsDataContainer::const_iterator& end, const QCPDataRange& rangeRestriction ) const { - QCPAxis *keyAxis = mKeyAxis.data(); - QCPAxis *valueAxis = mValueAxis.data(); - if (!keyAxis || !valueAxis) + QCPAxis* keyAxis = mKeyAxis.data(); + QCPAxis* valueAxis = mValueAxis.data(); + if( !keyAxis || !valueAxis ) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; end = mDataContainer->constEnd(); begin = end; return; } - if (!mDataPlottable || rangeRestriction.isEmpty()) + if( !mDataPlottable || rangeRestriction.isEmpty() ) { end = mDataContainer->constEnd(); begin = end; return; } - if (!mDataPlottable->interface1D()->sortKeyIsMainKey()) + if( !mDataPlottable->interface1D()->sortKeyIsMainKey() ) { // if the sort key isn't the main key, it's not possible to find a contiguous range of visible // data points, so this method then only applies the range restriction and otherwise returns // the full data range. Visibility checks must be done on a per-datapoin-basis during drawing - QCPDataRange dataRange(0, mDataContainer->size()); - dataRange = dataRange.bounded(rangeRestriction); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); + QCPDataRange dataRange( 0, mDataContainer->size() ); + dataRange = dataRange.bounded( rangeRestriction ); + begin = mDataContainer->constBegin() + dataRange.begin(); + end = mDataContainer->constBegin() + dataRange.end(); return; } - + // get visible data range via interface from data plottable, and then restrict to available error data points: - const int n = qMin(mDataContainer->size(), mDataPlottable->interface1D()->dataCount()); - int beginIndex = mDataPlottable->interface1D()->findBegin(keyAxis->range().lower); - int endIndex = mDataPlottable->interface1D()->findEnd(keyAxis->range().upper); + const int n = qMin( mDataContainer->size(), mDataPlottable->interface1D()->dataCount() ); + int beginIndex = mDataPlottable->interface1D()->findBegin( keyAxis->range().lower ); + int endIndex = mDataPlottable->interface1D()->findEnd( keyAxis->range().upper ); int i = beginIndex; - while (i > 0 && i < n && i > rangeRestriction.begin()) + while( i > 0 && i < n && i > rangeRestriction.begin() ) { - if (errorBarVisible(i)) + if( errorBarVisible( i ) ) beginIndex = i; --i; } i = endIndex; - while (i >= 0 && i < n && i < rangeRestriction.end()) + while( i >= 0 && i < n && i < rangeRestriction.end() ) { - if (errorBarVisible(i)) - endIndex = i+1; + if( errorBarVisible( i ) ) + endIndex = i + 1; ++i; } - QCPDataRange dataRange(beginIndex, endIndex); - dataRange = dataRange.bounded(rangeRestriction.bounded(QCPDataRange(0, mDataContainer->size()))); - begin = mDataContainer->constBegin()+dataRange.begin(); - end = mDataContainer->constBegin()+dataRange.end(); + QCPDataRange dataRange( beginIndex, endIndex ); + dataRange = dataRange.bounded( rangeRestriction.bounded( QCPDataRange( 0, mDataContainer->size() ) ) ); + begin = mDataContainer->constBegin() + dataRange.begin(); + end = mDataContainer->constBegin() + dataRange.end(); } /*! \internal @@ -27945,37 +28508,37 @@ void QCPErrorBars::getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterato pixelPoint. This is used to determine whether the error bar was clicked or not, e.g. in \ref selectTest. The closest data point to \a pixelPoint is returned in \a closestData. */ -double QCPErrorBars::pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const +double QCPErrorBars::pointDistance( const QPointF& pixelPoint, QCPErrorBarsDataContainer::const_iterator& closestData ) const { closestData = mDataContainer->constEnd(); - if (!mDataPlottable || mDataContainer->isEmpty()) + if( !mDataPlottable || mDataContainer->isEmpty() ) return -1.0; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return -1.0; } - + QCPErrorBarsDataContainer::const_iterator begin, end; - getVisibleDataBounds(begin, end, QCPDataRange(0, dataCount())); - + getVisibleDataBounds( begin, end, QCPDataRange( 0, dataCount() ) ); + // calculate minimum distances to error backbones (whiskers are ignored for speed) and find closestData iterator: - double minDistSqr = (std::numeric_limits::max)(); + double minDistSqr = ( std::numeric_limits::max )(); QVector backbones, whiskers; - for (QCPErrorBarsDataContainer::const_iterator it=begin; it!=end; ++it) + for( QCPErrorBarsDataContainer::const_iterator it = begin; it != end; ++it ) { - getErrorBarLines(it, backbones, whiskers); - for (int i=0; i &selectedSegments, QList &unselectedSegments) const +void QCPErrorBars::getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const { selectedSegments.clear(); unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + if( mSelectable == QCP::stWhole ) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); + if( selected() ) + selectedSegments << QCPDataRange( 0, dataCount() ); else - unselectedSegments << QCPDataRange(0, dataCount()); - } else + unselectedSegments << QCPDataRange( 0, dataCount() ); + } + else { - QCPDataSelection sel(selection()); + QCPDataSelection sel( selection() ); sel.simplify(); selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + unselectedSegments = sel.inverse( QCPDataRange( 0, dataCount() ) ).dataRanges(); } } @@ -28013,27 +28577,28 @@ void QCPErrorBars::getDataSegments(QList &selectedSegments, QList< and the data plottable (\ref setDataPlottable) are not zero and that \a index is within valid bounds of this \ref QCPErrorBars instance and the bounds of the data plottable. */ -bool QCPErrorBars::errorBarVisible(int index) const +bool QCPErrorBars::errorBarVisible( int index ) const { - QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition( index ); const double centerKeyPixel = mKeyAxis->orientation() == Qt::Horizontal ? centerPixel.x() : centerPixel.y(); - if (qIsNaN(centerKeyPixel)) + if( qIsNaN( centerKeyPixel ) ) return false; - + double keyMin, keyMax; - if (mErrorType == etKeyError) + if( mErrorType == etKeyError ) { - const double centerKey = mKeyAxis->pixelToCoord(centerKeyPixel); - const double errorPlus = mDataContainer->at(index).errorPlus; - const double errorMinus = mDataContainer->at(index).errorMinus; - keyMax = centerKey+(qIsNaN(errorPlus) ? 0 : errorPlus); - keyMin = centerKey-(qIsNaN(errorMinus) ? 0 : errorMinus); - } else // mErrorType == etValueError - { - keyMax = mKeyAxis->pixelToCoord(centerKeyPixel+mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); - keyMin = mKeyAxis->pixelToCoord(centerKeyPixel-mWhiskerWidth*0.5*mKeyAxis->pixelOrientation()); + const double centerKey = mKeyAxis->pixelToCoord( centerKeyPixel ); + const double errorPlus = mDataContainer->at( index ).errorPlus; + const double errorMinus = mDataContainer->at( index ).errorMinus; + keyMax = centerKey + ( qIsNaN( errorPlus ) ? 0 : errorPlus ); + keyMin = centerKey - ( qIsNaN( errorMinus ) ? 0 : errorMinus ); } - return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); + else // mErrorType == etValueError + { + keyMax = mKeyAxis->pixelToCoord( centerKeyPixel + mWhiskerWidth * 0.5 * mKeyAxis->pixelOrientation() ); + keyMin = mKeyAxis->pixelToCoord( centerKeyPixel - mWhiskerWidth * 0.5 * mKeyAxis->pixelOrientation() ); + } + return ( ( keyMax > mKeyAxis->range().lower ) && ( keyMin < mKeyAxis->range().upper ) ); } /*! \internal @@ -28043,22 +28608,21 @@ bool QCPErrorBars::errorBarVisible(int index) const \a line is assumed to be either perfectly horizontal or perfectly vertical, as is the case for error bar lines. */ -bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const +bool QCPErrorBars::rectIntersectsLine( const QRectF& pixelRect, const QLineF& line ) const { - if (pixelRect.left() > line.x1() && pixelRect.left() > line.x2()) + if( pixelRect.left() > line.x1() && pixelRect.left() > line.x2() ) return false; - else if (pixelRect.right() < line.x1() && pixelRect.right() < line.x2()) + else if( pixelRect.right() < line.x1() && pixelRect.right() < line.x2() ) return false; - else if (pixelRect.top() > line.y1() && pixelRect.top() > line.y2()) + else if( pixelRect.top() > line.y1() && pixelRect.top() > line.y2() ) return false; - else if (pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2()) + else if( pixelRect.bottom() < line.y1() && pixelRect.bottom() < line.y2() ) return false; else return true; } /* end of 'src/plottables/plottable-errorbar.cpp' */ - /* including file 'src/items/item-straightline.cpp', size 7592 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -28080,16 +28644,14 @@ bool QCPErrorBars::rectIntersectsLine(const QRectF &pixelRect, const QLineF &lin The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemStraightLine::QCPItemStraightLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - point1(createPosition(QLatin1String("point1"))), - point2(createPosition(QLatin1String("point2"))) +QCPItemStraightLine::QCPItemStraightLine( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), point1( createPosition( QLatin1String( "point1" ) ) ), point2( createPosition( QLatin1String( "point2" ) ) ) { - point1->setCoords(0, 0); - point2->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); + point1->setCoords( 0, 0 ); + point2->setCoords( 1, 1 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); } QCPItemStraightLine::~QCPItemStraightLine() @@ -28101,7 +28663,7 @@ QCPItemStraightLine::~QCPItemStraightLine() \see setSelectedPen */ -void QCPItemStraightLine::setPen(const QPen &pen) +void QCPItemStraightLine::setPen( const QPen& pen ) { mPen = pen; } @@ -28111,34 +28673,34 @@ void QCPItemStraightLine::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemStraightLine::setSelectedPen(const QPen &pen) +void QCPItemStraightLine::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } /* inherits documentation from base class */ -double QCPItemStraightLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemStraightLine::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - return QCPVector2D(pos).distanceToStraightLine(point1->pixelPosition(), point2->pixelPosition()-point1->pixelPosition()); + + return QCPVector2D( pos ).distanceToStraightLine( point1->pixelPosition(), point2->pixelPosition() - point1->pixelPosition() ); } /* inherits documentation from base class */ -void QCPItemStraightLine::draw(QCPPainter *painter) +void QCPItemStraightLine::draw( QCPPainter* painter ) { - QCPVector2D start(point1->pixelPosition()); - QCPVector2D end(point2->pixelPosition()); + QCPVector2D start( point1->pixelPosition() ); + QCPVector2D end( point2->pixelPosition() ); // get visible segment of straight line inside clipRect: double clipPad = mainPen().widthF(); - QLineF line = getRectClippedStraightLine(start, end-start, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + QLineF line = getRectClippedStraightLine( start, end - start, clipRect().adjusted( -clipPad, -clipPad, clipPad, clipPad ) ); // paint visible segment, if existent: - if (!line.isNull()) + if( !line.isNull() ) { - painter->setPen(mainPen()); - painter->drawLine(line); + painter->setPen( mainPen() ); + painter->drawLine( line ); } } @@ -28149,80 +28711,83 @@ void QCPItemStraightLine::draw(QCPPainter *painter) This is a helper function for \ref draw. */ -QLineF QCPItemStraightLine::getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const +QLineF QCPItemStraightLine::getRectClippedStraightLine( const QCPVector2D& base, const QCPVector2D& vec, const QRect& rect ) const { double bx, by; double gamma; QLineF result; - if (vec.x() == 0 && vec.y() == 0) + if( vec.x() == 0 && vec.y() == 0 ) return result; - if (qFuzzyIsNull(vec.x())) // line is vertical + if( qFuzzyIsNull( vec.x() ) ) // line is vertical { // check top of rect: bx = rect.left(); by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - result.setLine(bx+gamma, rect.top(), bx+gamma, rect.bottom()); // no need to check bottom because we know line is vertical - } else if (qFuzzyIsNull(vec.y())) // line is horizontal + gamma = base.x() - bx + ( by - base.y() ) * vec.x() / vec.y(); + if( gamma >= 0 && gamma <= rect.width() ) + result.setLine( bx + gamma, rect.top(), bx + gamma, rect.bottom() ); // no need to check bottom because we know line is vertical + } + else if( qFuzzyIsNull( vec.y() ) ) // line is horizontal { // check left of rect: bx = rect.left(); by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - result.setLine(rect.left(), by+gamma, rect.right(), by+gamma); // no need to check right because we know line is horizontal - } else // line is skewed + gamma = base.y() - by + ( bx - base.x() ) * vec.y() / vec.x(); + if( gamma >= 0 && gamma <= rect.height() ) + result.setLine( rect.left(), by + gamma, rect.right(), by + gamma ); // no need to check right because we know line is horizontal + } + else // line is skewed { QList pointVectors; // check top of rect: bx = rect.left(); by = rect.top(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); + gamma = base.x() - bx + ( by - base.y() ) * vec.x() / vec.y(); + if( gamma >= 0 && gamma <= rect.width() ) + pointVectors.append( QCPVector2D( bx + gamma, by ) ); // check bottom of rect: bx = rect.left(); by = rect.bottom(); - gamma = base.x()-bx + (by-base.y())*vec.x()/vec.y(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); + gamma = base.x() - bx + ( by - base.y() ) * vec.x() / vec.y(); + if( gamma >= 0 && gamma <= rect.width() ) + pointVectors.append( QCPVector2D( bx + gamma, by ) ); // check left of rect: bx = rect.left(); by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); + gamma = base.y() - by + ( bx - base.x() ) * vec.y() / vec.x(); + if( gamma >= 0 && gamma <= rect.height() ) + pointVectors.append( QCPVector2D( bx, by + gamma ) ); // check right of rect: bx = rect.right(); by = rect.top(); - gamma = base.y()-by + (bx-base.x())*vec.y()/vec.x(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); - + gamma = base.y() - by + ( bx - base.x() ) * vec.y() / vec.x(); + if( gamma >= 0 && gamma <= rect.height() ) + pointVectors.append( QCPVector2D( bx, by + gamma ) ); + // evaluate points: - if (pointVectors.size() == 2) + if( pointVectors.size() == 2 ) { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) + result.setPoints( pointVectors.at( 0 ).toPointF(), pointVectors.at( 1 ).toPointF() ); + } + else if( pointVectors.size() > 2 ) { // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: double distSqrMax = 0; QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) + double distSqr = ( pointVectors.at( i ) - pointVectors.at( k ) ).lengthSquared(); + if( distSqr > distSqrMax ) { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); + pv1 = pointVectors.at( i ); + pv2 = pointVectors.at( k ); distSqrMax = distSqr; } } } - result.setPoints(pv1.toPointF(), pv2.toPointF()); + result.setPoints( pv1.toPointF(), pv2.toPointF() ); } } return result; @@ -28239,7 +28804,6 @@ QPen QCPItemStraightLine::mainPen() const } /* end of 'src/items/item-straightline.cpp' */ - /* including file 'src/items/item-line.cpp', size 8498 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -28263,16 +28827,14 @@ QPen QCPItemStraightLine::mainPen() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemLine::QCPItemLine(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - end(createPosition(QLatin1String("end"))) +QCPItemLine::QCPItemLine( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), start( createPosition( QLatin1String( "start" ) ) ), end( createPosition( QLatin1String( "end" ) ) ) { - start->setCoords(0, 0); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); + start->setCoords( 0, 0 ); + end->setCoords( 1, 1 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); } QCPItemLine::~QCPItemLine() @@ -28284,7 +28846,7 @@ QCPItemLine::~QCPItemLine() \see setSelectedPen */ -void QCPItemLine::setPen(const QPen &pen) +void QCPItemLine::setPen( const QPen& pen ) { mPen = pen; } @@ -28294,7 +28856,7 @@ void QCPItemLine::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemLine::setSelectedPen(const QPen &pen) +void QCPItemLine::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -28307,7 +28869,7 @@ void QCPItemLine::setSelectedPen(const QPen &pen) \see setTail */ -void QCPItemLine::setHead(const QCPLineEnding &head) +void QCPItemLine::setHead( const QCPLineEnding& head ) { mHead = head; } @@ -28320,42 +28882,42 @@ void QCPItemLine::setHead(const QCPLineEnding &head) \see setHead */ -void QCPItemLine::setTail(const QCPLineEnding &tail) +void QCPItemLine::setTail( const QCPLineEnding& tail ) { mTail = tail; } /* inherits documentation from base class */ -double QCPItemLine::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemLine::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - return qSqrt(QCPVector2D(pos).distanceSquaredToLine(start->pixelPosition(), end->pixelPosition())); + + return qSqrt( QCPVector2D( pos ).distanceSquaredToLine( start->pixelPosition(), end->pixelPosition() ) ); } /* inherits documentation from base class */ -void QCPItemLine::draw(QCPPainter *painter) +void QCPItemLine::draw( QCPPainter* painter ) { - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if (qFuzzyIsNull((startVec-endVec).lengthSquared())) + QCPVector2D startVec( start->pixelPosition() ); + QCPVector2D endVec( end->pixelPosition() ); + if( qFuzzyIsNull( ( startVec - endVec ).lengthSquared() ) ) return; // get visible segment of straight line inside clipRect: - double clipPad = qMax(mHead.boundingDistance(), mTail.boundingDistance()); - clipPad = qMax(clipPad, (double)mainPen().widthF()); - QLineF line = getRectClippedLine(startVec, endVec, clipRect().adjusted(-clipPad, -clipPad, clipPad, clipPad)); + double clipPad = qMax( mHead.boundingDistance(), mTail.boundingDistance() ); + clipPad = qMax( clipPad, (double)mainPen().widthF() ); + QLineF line = getRectClippedLine( startVec, endVec, clipRect().adjusted( -clipPad, -clipPad, clipPad, clipPad ) ); // paint visible segment, if existent: - if (!line.isNull()) + if( !line.isNull() ) { - painter->setPen(mainPen()); - painter->drawLine(line); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, startVec-endVec); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, endVec-startVec); + painter->setPen( mainPen() ); + painter->drawLine( line ); + painter->setBrush( Qt::SolidPattern ); + if( mTail.style() != QCPLineEnding::esNone ) + mTail.draw( painter, startVec, startVec - endVec ); + if( mHead.style() != QCPLineEnding::esNone ) + mHead.draw( painter, endVec, endVec - startVec ); } } @@ -28366,95 +28928,96 @@ void QCPItemLine::draw(QCPPainter *painter) This is a helper function for \ref draw. */ -QLineF QCPItemLine::getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const +QLineF QCPItemLine::getRectClippedLine( const QCPVector2D& start, const QCPVector2D& end, const QRect& rect ) const { - bool containsStart = rect.contains(start.x(), start.y()); - bool containsEnd = rect.contains(end.x(), end.y()); - if (containsStart && containsEnd) - return QLineF(start.toPointF(), end.toPointF()); - + bool containsStart = rect.contains( start.x(), start.y() ); + bool containsEnd = rect.contains( end.x(), end.y() ); + if( containsStart && containsEnd ) + return QLineF( start.toPointF(), end.toPointF() ); + QCPVector2D base = start; - QCPVector2D vec = end-start; + QCPVector2D vec = end - start; double bx, by; double gamma, mu; QLineF result; QList pointVectors; - if (!qFuzzyIsNull(vec.y())) // line is not horizontal + if( !qFuzzyIsNull( vec.y() ) ) // line is not horizontal { // check top of rect: bx = rect.left(); by = rect.top(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) + mu = ( by - base.y() ) / vec.y(); + if( mu >= 0 && mu <= 1 ) { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); + gamma = base.x() - bx + mu * vec.x(); + if( gamma >= 0 && gamma <= rect.width() ) + pointVectors.append( QCPVector2D( bx + gamma, by ) ); } // check bottom of rect: bx = rect.left(); by = rect.bottom(); - mu = (by-base.y())/vec.y(); - if (mu >= 0 && mu <= 1) + mu = ( by - base.y() ) / vec.y(); + if( mu >= 0 && mu <= 1 ) { - gamma = base.x()-bx + mu*vec.x(); - if (gamma >= 0 && gamma <= rect.width()) - pointVectors.append(QCPVector2D(bx+gamma, by)); + gamma = base.x() - bx + mu * vec.x(); + if( gamma >= 0 && gamma <= rect.width() ) + pointVectors.append( QCPVector2D( bx + gamma, by ) ); } } - if (!qFuzzyIsNull(vec.x())) // line is not vertical + if( !qFuzzyIsNull( vec.x() ) ) // line is not vertical { // check left of rect: bx = rect.left(); by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) + mu = ( bx - base.x() ) / vec.x(); + if( mu >= 0 && mu <= 1 ) { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); + gamma = base.y() - by + mu * vec.y(); + if( gamma >= 0 && gamma <= rect.height() ) + pointVectors.append( QCPVector2D( bx, by + gamma ) ); } // check right of rect: bx = rect.right(); by = rect.top(); - mu = (bx-base.x())/vec.x(); - if (mu >= 0 && mu <= 1) + mu = ( bx - base.x() ) / vec.x(); + if( mu >= 0 && mu <= 1 ) { - gamma = base.y()-by + mu*vec.y(); - if (gamma >= 0 && gamma <= rect.height()) - pointVectors.append(QCPVector2D(bx, by+gamma)); + gamma = base.y() - by + mu * vec.y(); + if( gamma >= 0 && gamma <= rect.height() ) + pointVectors.append( QCPVector2D( bx, by + gamma ) ); } } - - if (containsStart) - pointVectors.append(start); - if (containsEnd) - pointVectors.append(end); - + + if( containsStart ) + pointVectors.append( start ); + if( containsEnd ) + pointVectors.append( end ); + // evaluate points: - if (pointVectors.size() == 2) + if( pointVectors.size() == 2 ) { - result.setPoints(pointVectors.at(0).toPointF(), pointVectors.at(1).toPointF()); - } else if (pointVectors.size() > 2) + result.setPoints( pointVectors.at( 0 ).toPointF(), pointVectors.at( 1 ).toPointF() ); + } + else if( pointVectors.size() > 2 ) { // line probably goes through corner of rect, and we got two points there. single out the point pair with greatest distance: double distSqrMax = 0; QCPVector2D pv1, pv2; - for (int i=0; i distSqrMax) + double distSqr = ( pointVectors.at( i ) - pointVectors.at( k ) ).lengthSquared(); + if( distSqr > distSqrMax ) { - pv1 = pointVectors.at(i); - pv2 = pointVectors.at(k); + pv1 = pointVectors.at( i ); + pv2 = pointVectors.at( k ); distSqrMax = distSqr; } } } - result.setPoints(pv1.toPointF(), pv2.toPointF()); + result.setPoints( pv1.toPointF(), pv2.toPointF() ); } return result; } @@ -28470,7 +29033,6 @@ QPen QCPItemLine::mainPen() const } /* end of 'src/items/item-line.cpp' */ - /* including file 'src/items/item-curve.cpp', size 7248 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -28501,20 +29063,16 @@ QPen QCPItemLine::mainPen() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemCurve::QCPItemCurve(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - start(createPosition(QLatin1String("start"))), - startDir(createPosition(QLatin1String("startDir"))), - endDir(createPosition(QLatin1String("endDir"))), - end(createPosition(QLatin1String("end"))) +QCPItemCurve::QCPItemCurve( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), start( createPosition( QLatin1String( "start" ) ) ), startDir( createPosition( QLatin1String( "startDir" ) ) ), endDir( createPosition( QLatin1String( "endDir" ) ) ), end( createPosition( QLatin1String( "end" ) ) ) { - start->setCoords(0, 0); - startDir->setCoords(0.5, 0); - endDir->setCoords(0, 0.5); - end->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); + start->setCoords( 0, 0 ); + startDir->setCoords( 0.5, 0 ); + endDir->setCoords( 0, 0.5 ); + end->setCoords( 1, 1 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); } QCPItemCurve::~QCPItemCurve() @@ -28526,7 +29084,7 @@ QCPItemCurve::~QCPItemCurve() \see setSelectedPen */ -void QCPItemCurve::setPen(const QPen &pen) +void QCPItemCurve::setPen( const QPen& pen ) { mPen = pen; } @@ -28536,7 +29094,7 @@ void QCPItemCurve::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemCurve::setSelectedPen(const QPen &pen) +void QCPItemCurve::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -28549,7 +29107,7 @@ void QCPItemCurve::setSelectedPen(const QPen &pen) \see setTail */ -void QCPItemCurve::setHead(const QCPLineEnding &head) +void QCPItemCurve::setHead( const QCPLineEnding& head ) { mHead = head; } @@ -28562,68 +29120,68 @@ void QCPItemCurve::setHead(const QCPLineEnding &head) \see setHead */ -void QCPItemCurve::setTail(const QCPLineEnding &tail) +void QCPItemCurve::setTail( const QCPLineEnding& tail ) { mTail = tail; } /* inherits documentation from base class */ -double QCPItemCurve::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemCurve::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - QPointF startVec(start->pixelPosition()); - QPointF startDirVec(startDir->pixelPosition()); - QPointF endDirVec(endDir->pixelPosition()); - QPointF endVec(end->pixelPosition()); - QPainterPath cubicPath(startVec); - cubicPath.cubicTo(startDirVec, endDirVec, endVec); - + QPointF startVec( start->pixelPosition() ); + QPointF startDirVec( startDir->pixelPosition() ); + QPointF endDirVec( endDir->pixelPosition() ); + QPointF endVec( end->pixelPosition() ); + + QPainterPath cubicPath( startVec ); + cubicPath.cubicTo( startDirVec, endDirVec, endVec ); + QList polygons = cubicPath.toSubpathPolygons(); - if (polygons.isEmpty()) + if( polygons.isEmpty() ) return -1; const QPolygonF polygon = polygons.first(); - QCPVector2D p(pos); - double minDistSqr = (std::numeric_limits::max)(); - for (int i=1; i::max )(); + for( int i = 1; i < polygon.size(); ++i ) { - double distSqr = p.distanceSquaredToLine(polygon.at(i-1), polygon.at(i)); - if (distSqr < minDistSqr) + double distSqr = p.distanceSquaredToLine( polygon.at( i - 1 ), polygon.at( i ) ); + if( distSqr < minDistSqr ) minDistSqr = distSqr; } - return qSqrt(minDistSqr); + return qSqrt( minDistSqr ); } /* inherits documentation from base class */ -void QCPItemCurve::draw(QCPPainter *painter) +void QCPItemCurve::draw( QCPPainter* painter ) { - QCPVector2D startVec(start->pixelPosition()); - QCPVector2D startDirVec(startDir->pixelPosition()); - QCPVector2D endDirVec(endDir->pixelPosition()); - QCPVector2D endVec(end->pixelPosition()); - if ((endVec-startVec).length() > 1e10) // too large curves cause crash + QCPVector2D startVec( start->pixelPosition() ); + QCPVector2D startDirVec( startDir->pixelPosition() ); + QCPVector2D endDirVec( endDir->pixelPosition() ); + QCPVector2D endVec( end->pixelPosition() ); + if( ( endVec - startVec ).length() > 1e10 ) // too large curves cause crash return; - QPainterPath cubicPath(startVec.toPointF()); - cubicPath.cubicTo(startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF()); + QPainterPath cubicPath( startVec.toPointF() ); + cubicPath.cubicTo( startDirVec.toPointF(), endDirVec.toPointF(), endVec.toPointF() ); // paint visible segment, if existent: - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); + QRect clip = clipRect().adjusted( -mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF() ); QRect cubicRect = cubicPath.controlPointRect().toRect(); - if (cubicRect.isEmpty()) // may happen when start and end exactly on same x or y position - cubicRect.adjust(0, 0, 1, 1); - if (clip.intersects(cubicRect)) + if( cubicRect.isEmpty() ) // may happen when start and end exactly on same x or y position + cubicRect.adjust( 0, 0, 1, 1 ); + if( clip.intersects( cubicRect ) ) { - painter->setPen(mainPen()); - painter->drawPath(cubicPath); - painter->setBrush(Qt::SolidPattern); - if (mTail.style() != QCPLineEnding::esNone) - mTail.draw(painter, startVec, M_PI-cubicPath.angleAtPercent(0)/180.0*M_PI); - if (mHead.style() != QCPLineEnding::esNone) - mHead.draw(painter, endVec, -cubicPath.angleAtPercent(1)/180.0*M_PI); + painter->setPen( mainPen() ); + painter->drawPath( cubicPath ); + painter->setBrush( Qt::SolidPattern ); + if( mTail.style() != QCPLineEnding::esNone ) + mTail.draw( painter, startVec, M_PI - cubicPath.angleAtPercent( 0 ) / 180.0 * M_PI ); + if( mHead.style() != QCPLineEnding::esNone ) + mHead.draw( painter, endVec, -cubicPath.angleAtPercent( 1 ) / 180.0 * M_PI ); } } @@ -28638,7 +29196,6 @@ QPen QCPItemCurve::mainPen() const } /* end of 'src/items/item-curve.cpp' */ - /* including file 'src/items/item-rect.cpp', size 6479 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -28660,24 +29217,16 @@ QPen QCPItemCurve::mainPen() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemRect::QCPItemRect(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)) +QCPItemRect::QCPItemRect( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), topLeft( createPosition( QLatin1String( "topLeft" ) ) ), bottomRight( createPosition( QLatin1String( "bottomRight" ) ) ), top( createAnchor( QLatin1String( "top" ), aiTop ) ), topRight( createAnchor( QLatin1String( "topRight" ), aiTopRight ) ), right( createAnchor( QLatin1String( "right" ), aiRight ) ), bottom( createAnchor( QLatin1String( "bottom" ), aiBottom ) ), bottomLeft( createAnchor( QLatin1String( "bottomLeft" ), aiBottomLeft ) ), left( createAnchor( QLatin1String( "left" ), aiLeft ) ) { - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue,2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); + topLeft->setCoords( 0, 1 ); + bottomRight->setCoords( 1, 0 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); + setBrush( Qt::NoBrush ); + setSelectedBrush( Qt::NoBrush ); } QCPItemRect::~QCPItemRect() @@ -28689,7 +29238,7 @@ QCPItemRect::~QCPItemRect() \see setSelectedPen, setBrush */ -void QCPItemRect::setPen(const QPen &pen) +void QCPItemRect::setPen( const QPen& pen ) { mPen = pen; } @@ -28699,7 +29248,7 @@ void QCPItemRect::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemRect::setSelectedPen(const QPen &pen) +void QCPItemRect::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -28710,7 +29259,7 @@ void QCPItemRect::setSelectedPen(const QPen &pen) \see setSelectedBrush, setPen */ -void QCPItemRect::setBrush(const QBrush &brush) +void QCPItemRect::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -28721,55 +29270,61 @@ void QCPItemRect::setBrush(const QBrush &brush) \see setBrush */ -void QCPItemRect::setSelectedBrush(const QBrush &brush) +void QCPItemRect::setSelectedBrush( const QBrush& brush ) { mSelectedBrush = brush; } /* inherits documentation from base class */ -double QCPItemRect::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemRect::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()).normalized(); + + QRectF rect = QRectF( topLeft->pixelPosition(), bottomRight->pixelPosition() ).normalized(); bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); + return rectDistance( rect, pos, filledRect ); } /* inherits documentation from base class */ -void QCPItemRect::draw(QCPPainter *painter) +void QCPItemRect::draw( QCPPainter* painter ) { QPointF p1 = topLeft->pixelPosition(); QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) + if( p1.toPoint() == p2.toPoint() ) return; - QRectF rect = QRectF(p1, p2).normalized(); + QRectF rect = QRectF( p1, p2 ).normalized(); double clipPad = mainPen().widthF(); - QRectF boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) // only draw if bounding rect of rect item is visible in cliprect + QRectF boundingRect = rect.adjusted( -clipPad, -clipPad, clipPad, clipPad ); + if( boundingRect.intersects( clipRect() ) ) // only draw if bounding rect of rect item is visible in cliprect { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(rect); + painter->setPen( mainPen() ); + painter->setBrush( mainBrush() ); + painter->drawRect( rect ); } } /* inherits documentation from base class */ -QPointF QCPItemRect::anchorPixelPosition(int anchorId) const +QPointF QCPItemRect::anchorPixelPosition( int anchorId ) const { - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) + QRectF rect = QRectF( topLeft->pixelPosition(), bottomRight->pixelPosition() ); + switch( anchorId ) { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; + case aiTop: + return ( rect.topLeft() + rect.topRight() ) * 0.5; + case aiTopRight: + return rect.topRight(); + case aiRight: + return ( rect.topRight() + rect.bottomRight() ) * 0.5; + case aiBottom: + return ( rect.bottomLeft() + rect.bottomRight() ) * 0.5; + case aiBottomLeft: + return rect.bottomLeft(); + case aiLeft: + return ( rect.topLeft() + rect.bottomLeft() ) * 0.5; } - + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; return QPointF(); } @@ -28795,7 +29350,6 @@ QBrush QCPItemRect::mainBrush() const } /* end of 'src/items/item-rect.cpp' */ - /* including file 'src/items/item-text.cpp', size 13338 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -28823,30 +29377,17 @@ QBrush QCPItemRect::mainBrush() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemText::QCPItemText(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - topLeft(createAnchor(QLatin1String("topLeft"), aiTopLeft)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRight(createAnchor(QLatin1String("bottomRight"), aiBottomRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mText(QLatin1String("text")), - mPositionAlignment(Qt::AlignCenter), - mTextAlignment(Qt::AlignTop|Qt::AlignHCenter), - mRotation(0) +QCPItemText::QCPItemText( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), position( createPosition( QLatin1String( "position" ) ) ), topLeft( createAnchor( QLatin1String( "topLeft" ), aiTopLeft ) ), top( createAnchor( QLatin1String( "top" ), aiTop ) ), topRight( createAnchor( QLatin1String( "topRight" ), aiTopRight ) ), right( createAnchor( QLatin1String( "right" ), aiRight ) ), bottomRight( createAnchor( QLatin1String( "bottomRight" ), aiBottomRight ) ), bottom( createAnchor( QLatin1String( "bottom" ), aiBottom ) ), bottomLeft( createAnchor( QLatin1String( "bottomLeft" ), aiBottomLeft ) ), left( createAnchor( QLatin1String( "left" ), aiLeft ) ), mText( QLatin1String( "text" ) ), mPositionAlignment( Qt::AlignCenter ), mTextAlignment( Qt::AlignTop | Qt::AlignHCenter ), mRotation( 0 ) { - position->setCoords(0, 0); - - setPen(Qt::NoPen); - setSelectedPen(Qt::NoPen); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setColor(Qt::black); - setSelectedColor(Qt::blue); + position->setCoords( 0, 0 ); + + setPen( Qt::NoPen ); + setSelectedPen( Qt::NoPen ); + setBrush( Qt::NoBrush ); + setSelectedBrush( Qt::NoBrush ); + setColor( Qt::black ); + setSelectedColor( Qt::blue ); } QCPItemText::~QCPItemText() @@ -28856,7 +29397,7 @@ QCPItemText::~QCPItemText() /*! Sets the color of the text. */ -void QCPItemText::setColor(const QColor &color) +void QCPItemText::setColor( const QColor& color ) { mColor = color; } @@ -28864,7 +29405,7 @@ void QCPItemText::setColor(const QColor &color) /*! Sets the color of the text that will be used when the item is selected. */ -void QCPItemText::setSelectedColor(const QColor &color) +void QCPItemText::setSelectedColor( const QColor& color ) { mSelectedColor = color; } @@ -28875,7 +29416,7 @@ void QCPItemText::setSelectedColor(const QColor &color) \see setSelectedPen, setBrush, setPadding */ -void QCPItemText::setPen(const QPen &pen) +void QCPItemText::setPen( const QPen& pen ) { mPen = pen; } @@ -28886,7 +29427,7 @@ void QCPItemText::setPen(const QPen &pen) \see setPen */ -void QCPItemText::setSelectedPen(const QPen &pen) +void QCPItemText::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -28897,7 +29438,7 @@ void QCPItemText::setSelectedPen(const QPen &pen) \see setSelectedBrush, setPen, setPadding */ -void QCPItemText::setBrush(const QBrush &brush) +void QCPItemText::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -28908,7 +29449,7 @@ void QCPItemText::setBrush(const QBrush &brush) \see setBrush */ -void QCPItemText::setSelectedBrush(const QBrush &brush) +void QCPItemText::setSelectedBrush( const QBrush& brush ) { mSelectedBrush = brush; } @@ -28918,7 +29459,7 @@ void QCPItemText::setSelectedBrush(const QBrush &brush) \see setSelectedFont, setColor */ -void QCPItemText::setFont(const QFont &font) +void QCPItemText::setFont( const QFont& font ) { mFont = font; } @@ -28928,7 +29469,7 @@ void QCPItemText::setFont(const QFont &font) \see setFont */ -void QCPItemText::setSelectedFont(const QFont &font) +void QCPItemText::setSelectedFont( const QFont& font ) { mSelectedFont = font; } @@ -28939,7 +29480,7 @@ void QCPItemText::setSelectedFont(const QFont &font) \see setFont, setColor, setTextAlignment */ -void QCPItemText::setText(const QString &text) +void QCPItemText::setText( const QString& text ) { mText = text; } @@ -28956,7 +29497,7 @@ void QCPItemText::setText(const QString &text) If you want to control the alignment of (multi-lined) text within the text rect, use \ref setTextAlignment. */ -void QCPItemText::setPositionAlignment(Qt::Alignment alignment) +void QCPItemText::setPositionAlignment( Qt::Alignment alignment ) { mPositionAlignment = alignment; } @@ -28964,7 +29505,7 @@ void QCPItemText::setPositionAlignment(Qt::Alignment alignment) /*! Controls how (multi-lined) text is aligned inside the text rect (typically Qt::AlignLeft, Qt::AlignCenter or Qt::AlignRight). */ -void QCPItemText::setTextAlignment(Qt::Alignment alignment) +void QCPItemText::setTextAlignment( Qt::Alignment alignment ) { mTextAlignment = alignment; } @@ -28973,7 +29514,7 @@ void QCPItemText::setTextAlignment(Qt::Alignment alignment) Sets the angle in degrees by which the text (and the text rectangle, if visible) will be rotated around \a position. */ -void QCPItemText::setRotation(double degrees) +void QCPItemText::setRotation( double degrees ) { mRotation = degrees; } @@ -28982,95 +29523,103 @@ void QCPItemText::setRotation(double degrees) Sets the distance between the border of the text rectangle and the text. The appearance (and visibility) of the text rectangle can be controlled with \ref setPen and \ref setBrush. */ -void QCPItemText::setPadding(const QMargins &padding) +void QCPItemText::setPadding( const QMargins& padding ) { mPadding = padding; } /* inherits documentation from base class */ -double QCPItemText::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemText::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - + // The rect may be rotated, so we transform the actual clicked pos to the rotated // coordinate system, so we can use the normal rectDistance function for non-rotated rects: - QPointF positionPixels(position->pixelPosition()); + QPointF positionPixels( position->pixelPosition() ); QTransform inputTransform; - inputTransform.translate(positionPixels.x(), positionPixels.y()); - inputTransform.rotate(-mRotation); - inputTransform.translate(-positionPixels.x(), -positionPixels.y()); - QPointF rotatedPos = inputTransform.map(pos); - QFontMetrics fontMetrics(mFont); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(positionPixels, textBoxRect, mPositionAlignment); - textBoxRect.moveTopLeft(textPos.toPoint()); + inputTransform.translate( positionPixels.x(), positionPixels.y() ); + inputTransform.rotate( -mRotation ); + inputTransform.translate( -positionPixels.x(), -positionPixels.y() ); + QPointF rotatedPos = inputTransform.map( pos ); + QFontMetrics fontMetrics( mFont ); + QRect textRect = fontMetrics.boundingRect( 0, 0, 0, 0, Qt::TextDontClip | mTextAlignment, mText ); + QRect textBoxRect = textRect.adjusted( -mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom() ); + QPointF textPos = getTextDrawPoint( positionPixels, textBoxRect, mPositionAlignment ); + textBoxRect.moveTopLeft( textPos.toPoint() ); - return rectDistance(textBoxRect, rotatedPos, true); + return rectDistance( textBoxRect, rotatedPos, true ); } /* inherits documentation from base class */ -void QCPItemText::draw(QCPPainter *painter) +void QCPItemText::draw( QCPPainter* painter ) { - QPointF pos(position->pixelPosition()); + QPointF pos( position->pixelPosition() ); QTransform transform = painter->transform(); - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - painter->setFont(mainFont()); - QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRect textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textRect.moveTopLeft(textPos.toPoint()+QPoint(mPadding.left(), mPadding.top())); - textBoxRect.moveTopLeft(textPos.toPoint()); + transform.translate( pos.x(), pos.y() ); + if( !qFuzzyIsNull( mRotation ) ) + transform.rotate( mRotation ); + painter->setFont( mainFont() ); + QRect textRect = painter->fontMetrics().boundingRect( 0, 0, 0, 0, Qt::TextDontClip | mTextAlignment, mText ); + QRect textBoxRect = textRect.adjusted( -mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom() ); + QPointF textPos = getTextDrawPoint( QPointF( 0, 0 ), textBoxRect, mPositionAlignment ); // 0, 0 because the transform does the translation + textRect.moveTopLeft( textPos.toPoint() + QPoint( mPadding.left(), mPadding.top() ) ); + textBoxRect.moveTopLeft( textPos.toPoint() ); double clipPad = mainPen().widthF(); - QRect boundingRect = textBoxRect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (transform.mapRect(boundingRect).intersects(painter->transform().mapRect(clipRect()))) + QRect boundingRect = textBoxRect.adjusted( -clipPad, -clipPad, clipPad, clipPad ); + if( transform.mapRect( boundingRect ).intersects( painter->transform().mapRect( clipRect() ) ) ) { - painter->setTransform(transform); - if ((mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0) || - (mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0)) + painter->setTransform( transform ); + if( ( mainBrush().style() != Qt::NoBrush && mainBrush().color().alpha() != 0 ) || + ( mainPen().style() != Qt::NoPen && mainPen().color().alpha() != 0 ) ) { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - painter->drawRect(textBoxRect); + painter->setPen( mainPen() ); + painter->setBrush( mainBrush() ); + painter->drawRect( textBoxRect ); } - painter->setBrush(Qt::NoBrush); - painter->setPen(QPen(mainColor())); - painter->drawText(textRect, Qt::TextDontClip|mTextAlignment, mText); + painter->setBrush( Qt::NoBrush ); + painter->setPen( QPen( mainColor() ) ); + painter->drawText( textRect, Qt::TextDontClip | mTextAlignment, mText ); } } /* inherits documentation from base class */ -QPointF QCPItemText::anchorPixelPosition(int anchorId) const +QPointF QCPItemText::anchorPixelPosition( int anchorId ) const { // get actual rect points (pretty much copied from draw function): - QPointF pos(position->pixelPosition()); + QPointF pos( position->pixelPosition() ); QTransform transform; - transform.translate(pos.x(), pos.y()); - if (!qFuzzyIsNull(mRotation)) - transform.rotate(mRotation); - QFontMetrics fontMetrics(mainFont()); - QRect textRect = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip|mTextAlignment, mText); - QRectF textBoxRect = textRect.adjusted(-mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom()); - QPointF textPos = getTextDrawPoint(QPointF(0, 0), textBoxRect, mPositionAlignment); // 0, 0 because the transform does the translation - textBoxRect.moveTopLeft(textPos.toPoint()); - QPolygonF rectPoly = transform.map(QPolygonF(textBoxRect)); - - switch (anchorId) + transform.translate( pos.x(), pos.y() ); + if( !qFuzzyIsNull( mRotation ) ) + transform.rotate( mRotation ); + QFontMetrics fontMetrics( mainFont() ); + QRect textRect = fontMetrics.boundingRect( 0, 0, 0, 0, Qt::TextDontClip | mTextAlignment, mText ); + QRectF textBoxRect = textRect.adjusted( -mPadding.left(), -mPadding.top(), mPadding.right(), mPadding.bottom() ); + QPointF textPos = getTextDrawPoint( QPointF( 0, 0 ), textBoxRect, mPositionAlignment ); // 0, 0 because the transform does the translation + textBoxRect.moveTopLeft( textPos.toPoint() ); + QPolygonF rectPoly = transform.map( QPolygonF( textBoxRect ) ); + + switch( anchorId ) { - case aiTopLeft: return rectPoly.at(0); - case aiTop: return (rectPoly.at(0)+rectPoly.at(1))*0.5; - case aiTopRight: return rectPoly.at(1); - case aiRight: return (rectPoly.at(1)+rectPoly.at(2))*0.5; - case aiBottomRight: return rectPoly.at(2); - case aiBottom: return (rectPoly.at(2)+rectPoly.at(3))*0.5; - case aiBottomLeft: return rectPoly.at(3); - case aiLeft: return (rectPoly.at(3)+rectPoly.at(0))*0.5; + case aiTopLeft: + return rectPoly.at( 0 ); + case aiTop: + return ( rectPoly.at( 0 ) + rectPoly.at( 1 ) ) * 0.5; + case aiTopRight: + return rectPoly.at( 1 ); + case aiRight: + return ( rectPoly.at( 1 ) + rectPoly.at( 2 ) ) * 0.5; + case aiBottomRight: + return rectPoly.at( 2 ); + case aiBottom: + return ( rectPoly.at( 2 ) + rectPoly.at( 3 ) ) * 0.5; + case aiBottomLeft: + return rectPoly.at( 3 ); + case aiLeft: + return ( rectPoly.at( 3 ) + rectPoly.at( 0 ) ) * 0.5; } - + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; return QPointF(); } @@ -29085,19 +29634,19 @@ QPointF QCPItemText::anchorPixelPosition(int anchorId) const will be shifted upward by the height of \a rect, starting from \a pos. So if the text is finally drawn at that point, the lower left corner of the resulting text rect is at \a pos. */ -QPointF QCPItemText::getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const +QPointF QCPItemText::getTextDrawPoint( const QPointF& pos, const QRectF& rect, Qt::Alignment positionAlignment ) const { - if (positionAlignment == 0 || positionAlignment == (Qt::AlignLeft|Qt::AlignTop)) + if( positionAlignment == 0 || positionAlignment == ( Qt::AlignLeft | Qt::AlignTop ) ) return pos; - - QPointF result = pos; // start at top left - if (positionAlignment.testFlag(Qt::AlignHCenter)) - result.rx() -= rect.width()/2.0; - else if (positionAlignment.testFlag(Qt::AlignRight)) + + QPointF result = pos; // start at top left + if( positionAlignment.testFlag( Qt::AlignHCenter ) ) + result.rx() -= rect.width() / 2.0; + else if( positionAlignment.testFlag( Qt::AlignRight ) ) result.rx() -= rect.width(); - if (positionAlignment.testFlag(Qt::AlignVCenter)) - result.ry() -= rect.height()/2.0; - else if (positionAlignment.testFlag(Qt::AlignBottom)) + if( positionAlignment.testFlag( Qt::AlignVCenter ) ) + result.ry() -= rect.height() / 2.0; + else if( positionAlignment.testFlag( Qt::AlignBottom ) ) result.ry() -= rect.height(); return result; } @@ -29143,7 +29692,6 @@ QBrush QCPItemText::mainBrush() const } /* end of 'src/items/item-text.cpp' */ - /* including file 'src/items/item-ellipse.cpp', size 7863 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -29165,27 +29713,16 @@ QBrush QCPItemText::mainBrush() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemEllipse::QCPItemEllipse(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - topLeftRim(createAnchor(QLatin1String("topLeftRim"), aiTopLeftRim)), - top(createAnchor(QLatin1String("top"), aiTop)), - topRightRim(createAnchor(QLatin1String("topRightRim"), aiTopRightRim)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottomRightRim(createAnchor(QLatin1String("bottomRightRim"), aiBottomRightRim)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeftRim(createAnchor(QLatin1String("bottomLeftRim"), aiBottomLeftRim)), - left(createAnchor(QLatin1String("left"), aiLeft)), - center(createAnchor(QLatin1String("center"), aiCenter)) +QCPItemEllipse::QCPItemEllipse( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), topLeft( createPosition( QLatin1String( "topLeft" ) ) ), bottomRight( createPosition( QLatin1String( "bottomRight" ) ) ), topLeftRim( createAnchor( QLatin1String( "topLeftRim" ), aiTopLeftRim ) ), top( createAnchor( QLatin1String( "top" ), aiTop ) ), topRightRim( createAnchor( QLatin1String( "topRightRim" ), aiTopRightRim ) ), right( createAnchor( QLatin1String( "right" ), aiRight ) ), bottomRightRim( createAnchor( QLatin1String( "bottomRightRim" ), aiBottomRightRim ) ), bottom( createAnchor( QLatin1String( "bottom" ), aiBottom ) ), bottomLeftRim( createAnchor( QLatin1String( "bottomLeftRim" ), aiBottomLeftRim ) ), left( createAnchor( QLatin1String( "left" ), aiLeft ) ), center( createAnchor( QLatin1String( "center" ), aiCenter ) ) { - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); + topLeft->setCoords( 0, 1 ); + bottomRight->setCoords( 1, 0 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); + setBrush( Qt::NoBrush ); + setSelectedBrush( Qt::NoBrush ); } QCPItemEllipse::~QCPItemEllipse() @@ -29197,7 +29734,7 @@ QCPItemEllipse::~QCPItemEllipse() \see setSelectedPen, setBrush */ -void QCPItemEllipse::setPen(const QPen &pen) +void QCPItemEllipse::setPen( const QPen& pen ) { mPen = pen; } @@ -29207,7 +29744,7 @@ void QCPItemEllipse::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemEllipse::setSelectedPen(const QPen &pen) +void QCPItemEllipse::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -29218,7 +29755,7 @@ void QCPItemEllipse::setSelectedPen(const QPen &pen) \see setSelectedBrush, setPen */ -void QCPItemEllipse::setBrush(const QBrush &brush) +void QCPItemEllipse::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -29229,83 +29766,93 @@ void QCPItemEllipse::setBrush(const QBrush &brush) \see setBrush */ -void QCPItemEllipse::setSelectedBrush(const QBrush &brush) +void QCPItemEllipse::setSelectedBrush( const QBrush& brush ) { mSelectedBrush = brush; } /* inherits documentation from base class */ -double QCPItemEllipse::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemEllipse::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - + QPointF p1 = topLeft->pixelPosition(); QPointF p2 = bottomRight->pixelPosition(); - QPointF center((p1+p2)/2.0); - double a = qAbs(p1.x()-p2.x())/2.0; - double b = qAbs(p1.y()-p2.y())/2.0; - double x = pos.x()-center.x(); - double y = pos.y()-center.y(); - + QPointF center( ( p1 + p2 ) / 2.0 ); + double a = qAbs( p1.x() - p2.x() ) / 2.0; + double b = qAbs( p1.y() - p2.y() ) / 2.0; + double x = pos.x() - center.x(); + double y = pos.y() - center.y(); + // distance to border: - double c = 1.0/qSqrt(x*x/(a*a)+y*y/(b*b)); - double result = qAbs(c-1)*qSqrt(x*x+y*y); + double c = 1.0 / qSqrt( x * x / ( a * a ) + y * y / ( b * b ) ); + double result = qAbs( c - 1 ) * qSqrt( x * x + y * y ); // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) + if( result > mParentPlot->selectionTolerance() * 0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0 ) { - if (x*x/(a*a) + y*y/(b*b) <= 1) - result = mParentPlot->selectionTolerance()*0.99; + if( x * x / ( a * a ) + y * y / ( b * b ) <= 1 ) + result = mParentPlot->selectionTolerance() * 0.99; } return result; } /* inherits documentation from base class */ -void QCPItemEllipse::draw(QCPPainter *painter) +void QCPItemEllipse::draw( QCPPainter* painter ) { QPointF p1 = topLeft->pixelPosition(); QPointF p2 = bottomRight->pixelPosition(); - if (p1.toPoint() == p2.toPoint()) + if( p1.toPoint() == p2.toPoint() ) return; - QRectF ellipseRect = QRectF(p1, p2).normalized(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (ellipseRect.intersects(clip)) // only draw if bounding rect of ellipse is visible in cliprect + QRectF ellipseRect = QRectF( p1, p2 ).normalized(); + QRect clip = clipRect().adjusted( -mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF() ); + if( ellipseRect.intersects( clip ) ) // only draw if bounding rect of ellipse is visible in cliprect { - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); + painter->setPen( mainPen() ); + painter->setBrush( mainBrush() ); #ifdef __EXCEPTIONS - try // drawEllipse sometimes throws exceptions if ellipse is too big + try // drawEllipse sometimes throws exceptions if ellipse is too big { #endif - painter->drawEllipse(ellipseRect); + painter->drawEllipse( ellipseRect ); #ifdef __EXCEPTIONS - } catch (...) + } + catch( ... ) { qDebug() << Q_FUNC_INFO << "Item too large for memory, setting invisible"; - setVisible(false); + setVisible( false ); } #endif } } /* inherits documentation from base class */ -QPointF QCPItemEllipse::anchorPixelPosition(int anchorId) const +QPointF QCPItemEllipse::anchorPixelPosition( int anchorId ) const { - QRectF rect = QRectF(topLeft->pixelPosition(), bottomRight->pixelPosition()); - switch (anchorId) + QRectF rect = QRectF( topLeft->pixelPosition(), bottomRight->pixelPosition() ); + switch( anchorId ) { - case aiTopLeftRim: return rect.center()+(rect.topLeft()-rect.center())*1/qSqrt(2); - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRightRim: return rect.center()+(rect.topRight()-rect.center())*1/qSqrt(2); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottomRightRim: return rect.center()+(rect.bottomRight()-rect.center())*1/qSqrt(2); - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeftRim: return rect.center()+(rect.bottomLeft()-rect.center())*1/qSqrt(2); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5; - case aiCenter: return (rect.topLeft()+rect.bottomRight())*0.5; + case aiTopLeftRim: + return rect.center() + ( rect.topLeft() - rect.center() ) * 1 / qSqrt( 2 ); + case aiTop: + return ( rect.topLeft() + rect.topRight() ) * 0.5; + case aiTopRightRim: + return rect.center() + ( rect.topRight() - rect.center() ) * 1 / qSqrt( 2 ); + case aiRight: + return ( rect.topRight() + rect.bottomRight() ) * 0.5; + case aiBottomRightRim: + return rect.center() + ( rect.bottomRight() - rect.center() ) * 1 / qSqrt( 2 ); + case aiBottom: + return ( rect.bottomLeft() + rect.bottomRight() ) * 0.5; + case aiBottomLeftRim: + return rect.center() + ( rect.bottomLeft() - rect.center() ) * 1 / qSqrt( 2 ); + case aiLeft: + return ( rect.topLeft() + rect.bottomLeft() ) * 0.5; + case aiCenter: + return ( rect.topLeft() + rect.bottomRight() ) * 0.5; } - + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; return QPointF(); } @@ -29331,7 +29878,6 @@ QBrush QCPItemEllipse::mainBrush() const } /* end of 'src/items/item-ellipse.cpp' */ - /* including file 'src/items/item-pixmap.cpp', size 10615 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -29359,26 +29905,14 @@ QBrush QCPItemEllipse::mainBrush() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemPixmap::QCPItemPixmap(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - topLeft(createPosition(QLatin1String("topLeft"))), - bottomRight(createPosition(QLatin1String("bottomRight"))), - top(createAnchor(QLatin1String("top"), aiTop)), - topRight(createAnchor(QLatin1String("topRight"), aiTopRight)), - right(createAnchor(QLatin1String("right"), aiRight)), - bottom(createAnchor(QLatin1String("bottom"), aiBottom)), - bottomLeft(createAnchor(QLatin1String("bottomLeft"), aiBottomLeft)), - left(createAnchor(QLatin1String("left"), aiLeft)), - mScaled(false), - mScaledPixmapInvalidated(true), - mAspectRatioMode(Qt::KeepAspectRatio), - mTransformationMode(Qt::SmoothTransformation) +QCPItemPixmap::QCPItemPixmap( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), topLeft( createPosition( QLatin1String( "topLeft" ) ) ), bottomRight( createPosition( QLatin1String( "bottomRight" ) ) ), top( createAnchor( QLatin1String( "top" ), aiTop ) ), topRight( createAnchor( QLatin1String( "topRight" ), aiTopRight ) ), right( createAnchor( QLatin1String( "right" ), aiRight ) ), bottom( createAnchor( QLatin1String( "bottom" ), aiBottom ) ), bottomLeft( createAnchor( QLatin1String( "bottomLeft" ), aiBottomLeft ) ), left( createAnchor( QLatin1String( "left" ), aiLeft ) ), mScaled( false ), mScaledPixmapInvalidated( true ), mAspectRatioMode( Qt::KeepAspectRatio ), mTransformationMode( Qt::SmoothTransformation ) { - topLeft->setCoords(0, 1); - bottomRight->setCoords(1, 0); - - setPen(Qt::NoPen); - setSelectedPen(QPen(Qt::blue)); + topLeft->setCoords( 0, 1 ); + bottomRight->setCoords( 1, 0 ); + + setPen( Qt::NoPen ); + setSelectedPen( QPen( Qt::blue ) ); } QCPItemPixmap::~QCPItemPixmap() @@ -29388,11 +29922,11 @@ QCPItemPixmap::~QCPItemPixmap() /*! Sets the pixmap that will be displayed. */ -void QCPItemPixmap::setPixmap(const QPixmap &pixmap) +void QCPItemPixmap::setPixmap( const QPixmap& pixmap ) { mPixmap = pixmap; mScaledPixmapInvalidated = true; - if (mPixmap.isNull()) + if( mPixmap.isNull() ) qDebug() << Q_FUNC_INFO << "pixmap is null"; } @@ -29400,7 +29934,7 @@ void QCPItemPixmap::setPixmap(const QPixmap &pixmap) Sets whether the pixmap will be scaled to fit the rectangle defined by the \a topLeft and \a bottomRight positions. */ -void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode) +void QCPItemPixmap::setScaled( bool scaled, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformationMode ) { mScaled = scaled; mAspectRatioMode = aspectRatioMode; @@ -29413,7 +29947,7 @@ void QCPItemPixmap::setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode, \see setSelectedPen, setBrush */ -void QCPItemPixmap::setPen(const QPen &pen) +void QCPItemPixmap::setPen( const QPen& pen ) { mPen = pen; } @@ -29423,66 +29957,73 @@ void QCPItemPixmap::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemPixmap::setSelectedPen(const QPen &pen) +void QCPItemPixmap::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } /* inherits documentation from base class */ -double QCPItemPixmap::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemPixmap::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - return rectDistance(getFinalRect(), pos, true); + + return rectDistance( getFinalRect(), pos, true ); } /* inherits documentation from base class */ -void QCPItemPixmap::draw(QCPPainter *painter) +void QCPItemPixmap::draw( QCPPainter* painter ) { bool flipHorz = false; bool flipVert = false; - QRect rect = getFinalRect(&flipHorz, &flipVert); + QRect rect = getFinalRect( &flipHorz, &flipVert ); double clipPad = mainPen().style() == Qt::NoPen ? 0 : mainPen().widthF(); - QRect boundingRect = rect.adjusted(-clipPad, -clipPad, clipPad, clipPad); - if (boundingRect.intersects(clipRect())) + QRect boundingRect = rect.adjusted( -clipPad, -clipPad, clipPad, clipPad ); + if( boundingRect.intersects( clipRect() ) ) { - updateScaledPixmap(rect, flipHorz, flipVert); - painter->drawPixmap(rect.topLeft(), mScaled ? mScaledPixmap : mPixmap); + updateScaledPixmap( rect, flipHorz, flipVert ); + painter->drawPixmap( rect.topLeft(), mScaled ? mScaledPixmap : mPixmap ); QPen pen = mainPen(); - if (pen.style() != Qt::NoPen) + if( pen.style() != Qt::NoPen ) { - painter->setPen(pen); - painter->setBrush(Qt::NoBrush); - painter->drawRect(rect); + painter->setPen( pen ); + painter->setBrush( Qt::NoBrush ); + painter->drawRect( rect ); } } } /* inherits documentation from base class */ -QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const +QPointF QCPItemPixmap::anchorPixelPosition( int anchorId ) const { bool flipHorz; bool flipVert; - QRect rect = getFinalRect(&flipHorz, &flipVert); + QRect rect = getFinalRect( &flipHorz, &flipVert ); // we actually want denormal rects (negative width/height) here, so restore // the flipped state: - if (flipHorz) - rect.adjust(rect.width(), 0, -rect.width(), 0); - if (flipVert) - rect.adjust(0, rect.height(), 0, -rect.height()); - - switch (anchorId) + if( flipHorz ) + rect.adjust( rect.width(), 0, -rect.width(), 0 ); + if( flipVert ) + rect.adjust( 0, rect.height(), 0, -rect.height() ); + + switch( anchorId ) { - case aiTop: return (rect.topLeft()+rect.topRight())*0.5; - case aiTopRight: return rect.topRight(); - case aiRight: return (rect.topRight()+rect.bottomRight())*0.5; - case aiBottom: return (rect.bottomLeft()+rect.bottomRight())*0.5; - case aiBottomLeft: return rect.bottomLeft(); - case aiLeft: return (rect.topLeft()+rect.bottomLeft())*0.5;; + case aiTop: + return ( rect.topLeft() + rect.topRight() ) * 0.5; + case aiTopRight: + return rect.topRight(); + case aiRight: + return ( rect.topRight() + rect.bottomRight() ) * 0.5; + case aiBottom: + return ( rect.bottomLeft() + rect.bottomRight() ) * 0.5; + case aiBottomLeft: + return rect.bottomLeft(); + case aiLeft: + return ( rect.topLeft() + rect.bottomLeft() ) * 0.5; + ; } - + qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; return QPointF(); } @@ -29500,30 +30041,31 @@ QPointF QCPItemPixmap::anchorPixelPosition(int anchorId) const If scaling is disabled, sets mScaledPixmap to a null QPixmap. */ -void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flipVert) +void QCPItemPixmap::updateScaledPixmap( QRect finalRect, bool flipHorz, bool flipVert ) { - if (mPixmap.isNull()) + if( mPixmap.isNull() ) return; - - if (mScaled) + + if( mScaled ) { #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED double devicePixelRatio = mPixmap.devicePixelRatio(); #else double devicePixelRatio = 1.0; #endif - if (finalRect.isNull()) - finalRect = getFinalRect(&flipHorz, &flipVert); - if (mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size()/devicePixelRatio) + if( finalRect.isNull() ) + finalRect = getFinalRect( &flipHorz, &flipVert ); + if( mScaledPixmapInvalidated || finalRect.size() != mScaledPixmap.size() / devicePixelRatio ) { - mScaledPixmap = mPixmap.scaled(finalRect.size()*devicePixelRatio, mAspectRatioMode, mTransformationMode); - if (flipHorz || flipVert) - mScaledPixmap = QPixmap::fromImage(mScaledPixmap.toImage().mirrored(flipHorz, flipVert)); + mScaledPixmap = mPixmap.scaled( finalRect.size() * devicePixelRatio, mAspectRatioMode, mTransformationMode ); + if( flipHorz || flipVert ) + mScaledPixmap = QPixmap::fromImage( mScaledPixmap.toImage().mirrored( flipHorz, flipVert ) ); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - mScaledPixmap.setDevicePixelRatio(devicePixelRatio); + mScaledPixmap.setDevicePixelRatio( devicePixelRatio ); #endif } - } else if (!mScaledPixmap.isNull()) + } + else if( !mScaledPixmap.isNull() ) mScaledPixmap = QPixmap(); mScaledPixmapInvalidated = false; } @@ -29542,50 +30084,51 @@ void QCPItemPixmap::updateScaledPixmap(QRect finalRect, bool flipHorz, bool flip If scaling is disabled, returns a rect with size of the original pixmap and the top left corner aligned with the item position \a topLeft. The position \a bottomRight is ignored. */ -QRect QCPItemPixmap::getFinalRect(bool *flippedHorz, bool *flippedVert) const +QRect QCPItemPixmap::getFinalRect( bool* flippedHorz, bool* flippedVert ) const { QRect result; bool flipHorz = false; bool flipVert = false; QPoint p1 = topLeft->pixelPosition().toPoint(); QPoint p2 = bottomRight->pixelPosition().toPoint(); - if (p1 == p2) - return QRect(p1, QSize(0, 0)); - if (mScaled) + if( p1 == p2 ) + return QRect( p1, QSize( 0, 0 ) ); + if( mScaled ) { - QSize newSize = QSize(p2.x()-p1.x(), p2.y()-p1.y()); + QSize newSize = QSize( p2.x() - p1.x(), p2.y() - p1.y() ); QPoint topLeft = p1; - if (newSize.width() < 0) + if( newSize.width() < 0 ) { flipHorz = true; newSize.rwidth() *= -1; - topLeft.setX(p2.x()); + topLeft.setX( p2.x() ); } - if (newSize.height() < 0) + if( newSize.height() < 0 ) { flipVert = true; newSize.rheight() *= -1; - topLeft.setY(p2.y()); + topLeft.setY( p2.y() ); } QSize scaledSize = mPixmap.size(); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED scaledSize /= mPixmap.devicePixelRatio(); - scaledSize.scale(newSize*mPixmap.devicePixelRatio(), mAspectRatioMode); + scaledSize.scale( newSize * mPixmap.devicePixelRatio(), mAspectRatioMode ); #else - scaledSize.scale(newSize, mAspectRatioMode); + scaledSize.scale( newSize, mAspectRatioMode ); #endif - result = QRect(topLeft, scaledSize); - } else + result = QRect( topLeft, scaledSize ); + } + else { #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - result = QRect(p1, mPixmap.size()/mPixmap.devicePixelRatio()); + result = QRect( p1, mPixmap.size() / mPixmap.devicePixelRatio() ); #else - result = QRect(p1, mPixmap.size()); + result = QRect( p1, mPixmap.size() ); #endif } - if (flippedHorz) + if( flippedHorz ) *flippedHorz = flipHorz; - if (flippedVert) + if( flippedVert ) *flippedVert = flipVert; return result; } @@ -29601,7 +30144,6 @@ QPen QCPItemPixmap::mainPen() const } /* end of 'src/items/item-pixmap.cpp' */ - /* including file 'src/items/item-tracer.cpp', size 14624 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -29645,21 +30187,15 @@ QPen QCPItemPixmap::mainPen() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - position(createPosition(QLatin1String("position"))), - mSize(6), - mStyle(tsCrosshair), - mGraph(0), - mGraphKey(0), - mInterpolating(false) +QCPItemTracer::QCPItemTracer( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), position( createPosition( QLatin1String( "position" ) ) ), mSize( 6 ), mStyle( tsCrosshair ), mGraph( 0 ), mGraphKey( 0 ), mInterpolating( false ) { - position->setCoords(0, 0); + position->setCoords( 0, 0 ); - setBrush(Qt::NoBrush); - setSelectedBrush(Qt::NoBrush); - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); + setBrush( Qt::NoBrush ); + setSelectedBrush( Qt::NoBrush ); + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); } QCPItemTracer::~QCPItemTracer() @@ -29671,7 +30207,7 @@ QCPItemTracer::~QCPItemTracer() \see setSelectedPen, setBrush */ -void QCPItemTracer::setPen(const QPen &pen) +void QCPItemTracer::setPen( const QPen& pen ) { mPen = pen; } @@ -29681,7 +30217,7 @@ void QCPItemTracer::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemTracer::setSelectedPen(const QPen &pen) +void QCPItemTracer::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -29691,7 +30227,7 @@ void QCPItemTracer::setSelectedPen(const QPen &pen) \see setSelectedBrush, setPen */ -void QCPItemTracer::setBrush(const QBrush &brush) +void QCPItemTracer::setBrush( const QBrush& brush ) { mBrush = brush; } @@ -29701,7 +30237,7 @@ void QCPItemTracer::setBrush(const QBrush &brush) \see setBrush, setSelected */ -void QCPItemTracer::setSelectedBrush(const QBrush &brush) +void QCPItemTracer::setSelectedBrush( const QBrush& brush ) { mSelectedBrush = brush; } @@ -29710,7 +30246,7 @@ void QCPItemTracer::setSelectedBrush(const QBrush &brush) Sets the size of the tracer in pixels, if the style supports setting a size (e.g. \ref tsSquare does, \ref tsCrosshair does not). */ -void QCPItemTracer::setSize(double size) +void QCPItemTracer::setSize( double size ) { mSize = size; } @@ -29721,7 +30257,7 @@ void QCPItemTracer::setSize(double size) If you only want to use the tracer \a position as an anchor for other items, set \a style to \ref tsNone. */ -void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) +void QCPItemTracer::setStyle( QCPItemTracer::TracerStyle style ) { mStyle = style; } @@ -29736,19 +30272,21 @@ void QCPItemTracer::setStyle(QCPItemTracer::TracerStyle style) \see setGraphKey */ -void QCPItemTracer::setGraph(QCPGraph *graph) +void QCPItemTracer::setGraph( QCPGraph* graph ) { - if (graph) + if( graph ) { - if (graph->parentPlot() == mParentPlot) + if( graph->parentPlot() == mParentPlot ) { - position->setType(QCPItemPosition::ptPlotCoords); - position->setAxes(graph->keyAxis(), graph->valueAxis()); + position->setType( QCPItemPosition::ptPlotCoords ); + position->setAxes( graph->keyAxis(), graph->valueAxis() ); mGraph = graph; updatePosition(); - } else + } + else qDebug() << Q_FUNC_INFO << "graph isn't in same QCustomPlot instance as this item"; - } else + } + else { mGraph = 0; } @@ -29763,7 +30301,7 @@ void QCPItemTracer::setGraph(QCPGraph *graph) \see setGraph, setInterpolating */ -void QCPItemTracer::setGraphKey(double key) +void QCPItemTracer::setGraphKey( double key ) { mGraphKey = key; } @@ -29779,112 +30317,106 @@ void QCPItemTracer::setGraphKey(double key) \see setGraph, setGraphKey */ -void QCPItemTracer::setInterpolating(bool enabled) +void QCPItemTracer::setInterpolating( bool enabled ) { mInterpolating = enabled; } /* inherits documentation from base class */ -double QCPItemTracer::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemTracer::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - QPointF center(position->pixelPosition()); - double w = mSize/2.0; + QPointF center( position->pixelPosition() ); + double w = mSize / 2.0; QRect clip = clipRect(); - switch (mStyle) + switch( mStyle ) { - case tsNone: return -1; - case tsPlus: + case tsNone: + return -1; + case tsPlus: { + if( clipRect().intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) + return qSqrt( qMin( QCPVector2D( pos ).distanceSquaredToLine( center + QPointF( -w, 0 ), center + QPointF( w, 0 ) ), + QCPVector2D( pos ).distanceSquaredToLine( center + QPointF( 0, -w ), center + QPointF( 0, w ) ) ) ); + break; + } + case tsCrosshair: { + return qSqrt( qMin( QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( clip.left(), center.y() ), QCPVector2D( clip.right(), center.y() ) ), + QCPVector2D( pos ).distanceSquaredToLine( QCPVector2D( center.x(), clip.top() ), QCPVector2D( center.x(), clip.bottom() ) ) ) ); + } + case tsCircle: { + if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) { - if (clipRect().intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(center+QPointF(-w, 0), center+QPointF(w, 0)), - QCPVector2D(pos).distanceSquaredToLine(center+QPointF(0, -w), center+QPointF(0, w)))); - break; - } - case tsCrosshair: - { - return qSqrt(qMin(QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(clip.left(), center.y()), QCPVector2D(clip.right(), center.y())), - QCPVector2D(pos).distanceSquaredToLine(QCPVector2D(center.x(), clip.top()), QCPVector2D(center.x(), clip.bottom())))); - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) + // distance to border: + double centerDist = QCPVector2D( center - pos ).length(); + double circleLine = w; + double result = qAbs( centerDist - circleLine ); + // filled ellipse, allow click inside to count as hit: + if( result > mParentPlot->selectionTolerance() * 0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0 ) { - // distance to border: - double centerDist = QCPVector2D(center-pos).length(); - double circleLine = w; - double result = qAbs(centerDist-circleLine); - // filled ellipse, allow click inside to count as hit: - if (result > mParentPlot->selectionTolerance()*0.99 && mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0) - { - if (centerDist <= circleLine) - result = mParentPlot->selectionTolerance()*0.99; - } - return result; + if( centerDist <= circleLine ) + result = mParentPlot->selectionTolerance() * 0.99; } - break; + return result; } - case tsSquare: + break; + } + case tsSquare: { + if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - QRectF rect = QRectF(center-QPointF(w, w), center+QPointF(w, w)); - bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; - return rectDistance(rect, pos, filledRect); - } - break; + QRectF rect = QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ); + bool filledRect = mBrush.style() != Qt::NoBrush && mBrush.color().alpha() != 0; + return rectDistance( rect, pos, filledRect ); } + break; + } } return -1; } /* inherits documentation from base class */ -void QCPItemTracer::draw(QCPPainter *painter) +void QCPItemTracer::draw( QCPPainter* painter ) { updatePosition(); - if (mStyle == tsNone) + if( mStyle == tsNone ) return; - painter->setPen(mainPen()); - painter->setBrush(mainBrush()); - QPointF center(position->pixelPosition()); - double w = mSize/2.0; + painter->setPen( mainPen() ); + painter->setBrush( mainBrush() ); + QPointF center( position->pixelPosition() ); + double w = mSize / 2.0; QRect clip = clipRect(); - switch (mStyle) + switch( mStyle ) { - case tsNone: return; - case tsPlus: + case tsNone: + return; + case tsPlus: { + if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - { - painter->drawLine(QLineF(center+QPointF(-w, 0), center+QPointF(w, 0))); - painter->drawLine(QLineF(center+QPointF(0, -w), center+QPointF(0, w))); - } - break; - } - case tsCrosshair: - { - if (center.y() > clip.top() && center.y() < clip.bottom()) - painter->drawLine(QLineF(clip.left(), center.y(), clip.right(), center.y())); - if (center.x() > clip.left() && center.x() < clip.right()) - painter->drawLine(QLineF(center.x(), clip.top(), center.x(), clip.bottom())); - break; - } - case tsCircle: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawEllipse(center, w, w); - break; - } - case tsSquare: - { - if (clip.intersects(QRectF(center-QPointF(w, w), center+QPointF(w, w)).toRect())) - painter->drawRect(QRectF(center-QPointF(w, w), center+QPointF(w, w))); - break; + painter->drawLine( QLineF( center + QPointF( -w, 0 ), center + QPointF( w, 0 ) ) ); + painter->drawLine( QLineF( center + QPointF( 0, -w ), center + QPointF( 0, w ) ) ); } + break; + } + case tsCrosshair: { + if( center.y() > clip.top() && center.y() < clip.bottom() ) + painter->drawLine( QLineF( clip.left(), center.y(), clip.right(), center.y() ) ); + if( center.x() > clip.left() && center.x() < clip.right() ) + painter->drawLine( QLineF( center.x(), clip.top(), center.x(), clip.bottom() ) ); + break; + } + case tsCircle: { + if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) + painter->drawEllipse( center, w, w ); + break; + } + case tsSquare: { + if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) + painter->drawRect( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ) ); + break; + } } } @@ -29902,50 +30434,55 @@ void QCPItemTracer::draw(QCPPainter *painter) */ void QCPItemTracer::updatePosition() { - if (mGraph) + if( mGraph ) { - if (mParentPlot->hasPlottable(mGraph)) + if( mParentPlot->hasPlottable( mGraph ) ) { - if (mGraph->data()->size() > 1) + if( mGraph->data()->size() > 1 ) { QCPGraphDataContainer::const_iterator first = mGraph->data()->constBegin(); - QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd()-1; - if (mGraphKey <= first->key) - position->setCoords(first->key, first->value); - else if (mGraphKey >= last->key) - position->setCoords(last->key, last->value); + QCPGraphDataContainer::const_iterator last = mGraph->data()->constEnd() - 1; + if( mGraphKey <= first->key ) + position->setCoords( first->key, first->value ); + else if( mGraphKey >= last->key ) + position->setCoords( last->key, last->value ); else { - QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin(mGraphKey); - if (it != mGraph->data()->constEnd()) // mGraphKey is not exactly on last iterator, but somewhere between iterators + QCPGraphDataContainer::const_iterator it = mGraph->data()->findBegin( mGraphKey ); + if( it != mGraph->data()->constEnd() ) // mGraphKey is not exactly on last iterator, but somewhere between iterators { QCPGraphDataContainer::const_iterator prevIt = it; - ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before - if (mInterpolating) + ++it; // won't advance to constEnd because we handled that case (mGraphKey >= last->key) before + if( mInterpolating ) { // interpolate between iterators around mGraphKey: double slope = 0; - if (!qFuzzyCompare((double)it->key, (double)prevIt->key)) - slope = (it->value-prevIt->value)/(it->key-prevIt->key); - position->setCoords(mGraphKey, (mGraphKey-prevIt->key)*slope+prevIt->value); - } else + if( !qFuzzyCompare( (double)it->key, (double)prevIt->key ) ) + slope = ( it->value - prevIt->value ) / ( it->key - prevIt->key ); + position->setCoords( mGraphKey, ( mGraphKey - prevIt->key ) * slope + prevIt->value ); + } + else { // find iterator with key closest to mGraphKey: - if (mGraphKey < (prevIt->key+it->key)*0.5) - position->setCoords(prevIt->key, prevIt->value); + if( mGraphKey < ( prevIt->key + it->key ) * 0.5 ) + position->setCoords( prevIt->key, prevIt->value ); else - position->setCoords(it->key, it->value); + position->setCoords( it->key, it->value ); } - } else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) - position->setCoords(it->key, it->value); + } + else // mGraphKey is exactly on last iterator (should actually be caught when comparing first/last keys, but this is a failsafe for fp uncertainty) + position->setCoords( it->key, it->value ); } - } else if (mGraph->data()->size() == 1) + } + else if( mGraph->data()->size() == 1 ) { QCPGraphDataContainer::const_iterator it = mGraph->data()->constBegin(); - position->setCoords(it->key, it->value); - } else + position->setCoords( it->key, it->value ); + } + else qDebug() << Q_FUNC_INFO << "graph has no data"; - } else + } + else qDebug() << Q_FUNC_INFO << "graph not contained in QCustomPlot instance (anymore)"; } } @@ -29971,7 +30508,6 @@ QBrush QCPItemTracer::mainBrush() const } /* end of 'src/items/item-tracer.cpp' */ - /* including file 'src/items/item-bracket.cpp', size 10687 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -30005,19 +30541,14 @@ QBrush QCPItemTracer::mainBrush() const The created item is automatically registered with \a parentPlot. This QCustomPlot instance takes ownership of the item, so do not delete it manually but use QCustomPlot::removeItem() instead. */ -QCPItemBracket::QCPItemBracket(QCustomPlot *parentPlot) : - QCPAbstractItem(parentPlot), - left(createPosition(QLatin1String("left"))), - right(createPosition(QLatin1String("right"))), - center(createAnchor(QLatin1String("center"), aiCenter)), - mLength(8), - mStyle(bsCalligraphic) +QCPItemBracket::QCPItemBracket( QCustomPlot* parentPlot ) + : QCPAbstractItem( parentPlot ), left( createPosition( QLatin1String( "left" ) ) ), right( createPosition( QLatin1String( "right" ) ) ), center( createAnchor( QLatin1String( "center" ), aiCenter ) ), mLength( 8 ), mStyle( bsCalligraphic ) { - left->setCoords(0, 0); - right->setCoords(1, 1); - - setPen(QPen(Qt::black)); - setSelectedPen(QPen(Qt::blue, 2)); + left->setCoords( 0, 0 ); + right->setCoords( 1, 1 ); + + setPen( QPen( Qt::black ) ); + setSelectedPen( QPen( Qt::blue, 2 ) ); } QCPItemBracket::~QCPItemBracket() @@ -30033,7 +30564,7 @@ QCPItemBracket::~QCPItemBracket() \see setSelectedPen */ -void QCPItemBracket::setPen(const QPen &pen) +void QCPItemBracket::setPen( const QPen& pen ) { mPen = pen; } @@ -30043,7 +30574,7 @@ void QCPItemBracket::setPen(const QPen &pen) \see setPen, setSelected */ -void QCPItemBracket::setSelectedPen(const QPen &pen) +void QCPItemBracket::setSelectedPen( const QPen& pen ) { mSelectedPen = pen; } @@ -30056,7 +30587,7 @@ void QCPItemBracket::setSelectedPen(const QPen &pen)
Demonstrating the effect of different values for \ref setLength, for styles \ref bsCalligraphic and \ref bsSquare. Anchors and positions are displayed for reference.
*/ -void QCPItemBracket::setLength(double length) +void QCPItemBracket::setLength( double length ) { mLength = length; } @@ -30066,135 +30597,129 @@ void QCPItemBracket::setLength(double length) \see setPen */ -void QCPItemBracket::setStyle(QCPItemBracket::BracketStyle style) +void QCPItemBracket::setStyle( QCPItemBracket::BracketStyle style ) { mStyle = style; } /* inherits documentation from base class */ -double QCPItemBracket::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPItemBracket::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - Q_UNUSED(details) - if (onlySelectable && !mSelectable) + Q_UNUSED( details ) + if( onlySelectable && !mSelectable ) return -1; - - QCPVector2D p(pos); - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) + + QCPVector2D p( pos ); + QCPVector2D leftVec( left->pixelPosition() ); + QCPVector2D rightVec( right->pixelPosition() ); + if( leftVec.toPoint() == rightVec.toPoint() ) return -1; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (mStyle) + + QCPVector2D widthVec = ( rightVec - leftVec ) * 0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized() * mLength; + QCPVector2D centerVec = ( rightVec + leftVec ) * 0.5 - lengthVec; + + switch( mStyle ) { - case QCPItemBracket::bsSquare: - case QCPItemBracket::bsRound: - { - double a = p.distanceSquaredToLine(centerVec-widthVec, centerVec+widthVec); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec, centerVec-widthVec); - double c = p.distanceSquaredToLine(centerVec+widthVec+lengthVec, centerVec+widthVec); - return qSqrt(qMin(qMin(a, b), c)); - } - case QCPItemBracket::bsCurly: - case QCPItemBracket::bsCalligraphic: - { - double a = p.distanceSquaredToLine(centerVec-widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double b = p.distanceSquaredToLine(centerVec-widthVec+lengthVec*0.7, centerVec-widthVec*0.75+lengthVec*0.15); - double c = p.distanceSquaredToLine(centerVec+widthVec*0.75+lengthVec*0.15, centerVec+lengthVec*0.3); - double d = p.distanceSquaredToLine(centerVec+widthVec+lengthVec*0.7, centerVec+widthVec*0.75+lengthVec*0.15); - return qSqrt(qMin(qMin(a, b), qMin(c, d))); - } + case QCPItemBracket::bsSquare: + case QCPItemBracket::bsRound: { + double a = p.distanceSquaredToLine( centerVec - widthVec, centerVec + widthVec ); + double b = p.distanceSquaredToLine( centerVec - widthVec + lengthVec, centerVec - widthVec ); + double c = p.distanceSquaredToLine( centerVec + widthVec + lengthVec, centerVec + widthVec ); + return qSqrt( qMin( qMin( a, b ), c ) ); + } + case QCPItemBracket::bsCurly: + case QCPItemBracket::bsCalligraphic: { + double a = p.distanceSquaredToLine( centerVec - widthVec * 0.75 + lengthVec * 0.15, centerVec + lengthVec * 0.3 ); + double b = p.distanceSquaredToLine( centerVec - widthVec + lengthVec * 0.7, centerVec - widthVec * 0.75 + lengthVec * 0.15 ); + double c = p.distanceSquaredToLine( centerVec + widthVec * 0.75 + lengthVec * 0.15, centerVec + lengthVec * 0.3 ); + double d = p.distanceSquaredToLine( centerVec + widthVec + lengthVec * 0.7, centerVec + widthVec * 0.75 + lengthVec * 0.15 ); + return qSqrt( qMin( qMin( a, b ), qMin( c, d ) ) ); + } } return -1; } /* inherits documentation from base class */ -void QCPItemBracket::draw(QCPPainter *painter) +void QCPItemBracket::draw( QCPPainter* painter ) { - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) + QCPVector2D leftVec( left->pixelPosition() ); + QCPVector2D rightVec( right->pixelPosition() ); + if( leftVec.toPoint() == rightVec.toPoint() ) return; - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; + + QCPVector2D widthVec = ( rightVec - leftVec ) * 0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized() * mLength; + QCPVector2D centerVec = ( rightVec + leftVec ) * 0.5 - lengthVec; QPolygon boundingPoly; boundingPoly << leftVec.toPoint() << rightVec.toPoint() - << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); - QRect clip = clipRect().adjusted(-mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF()); - if (clip.intersects(boundingPoly.boundingRect())) + << ( rightVec - lengthVec ).toPoint() << ( leftVec - lengthVec ).toPoint(); + QRect clip = clipRect().adjusted( -mainPen().widthF(), -mainPen().widthF(), mainPen().widthF(), mainPen().widthF() ); + if( clip.intersects( boundingPoly.boundingRect() ) ) { - painter->setPen(mainPen()); - switch (mStyle) + painter->setPen( mainPen() ); + switch( mStyle ) { - case bsSquare: - { - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec-widthVec).toPointF()); - painter->drawLine((centerVec+widthVec).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - painter->drawLine((centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - break; - } - case bsRound: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec).toPointF(), (centerVec+widthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-widthVec).toPointF(), (centerVec-widthVec).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCurly: - { - painter->setBrush(Qt::NoBrush); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - painter->drawPath(path); - break; - } - case bsCalligraphic: - { - painter->setPen(Qt::NoPen); - painter->setBrush(QBrush(mainPen().color())); - QPainterPath path; - path.moveTo((centerVec+widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec+widthVec-lengthVec*0.8).toPointF(), (centerVec+0.4*widthVec+0.8*lengthVec).toPointF(), centerVec.toPointF()); - path.cubicTo((centerVec-0.4*widthVec+0.8*lengthVec).toPointF(), (centerVec-widthVec-lengthVec*0.8).toPointF(), (centerVec-widthVec+lengthVec).toPointF()); - - path.cubicTo((centerVec-widthVec-lengthVec*0.5).toPointF(), (centerVec-0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+lengthVec*0.2).toPointF()); - path.cubicTo((centerVec+0.2*widthVec+1.2*lengthVec).toPointF(), (centerVec+widthVec-lengthVec*0.5).toPointF(), (centerVec+widthVec+lengthVec).toPointF()); - - painter->drawPath(path); - break; - } + case bsSquare: { + painter->drawLine( ( centerVec + widthVec ).toPointF(), ( centerVec - widthVec ).toPointF() ); + painter->drawLine( ( centerVec + widthVec ).toPointF(), ( centerVec + widthVec + lengthVec ).toPointF() ); + painter->drawLine( ( centerVec - widthVec ).toPointF(), ( centerVec - widthVec + lengthVec ).toPointF() ); + break; + } + case bsRound: { + painter->setBrush( Qt::NoBrush ); + QPainterPath path; + path.moveTo( ( centerVec + widthVec + lengthVec ).toPointF() ); + path.cubicTo( ( centerVec + widthVec ).toPointF(), ( centerVec + widthVec ).toPointF(), centerVec.toPointF() ); + path.cubicTo( ( centerVec - widthVec ).toPointF(), ( centerVec - widthVec ).toPointF(), ( centerVec - widthVec + lengthVec ).toPointF() ); + painter->drawPath( path ); + break; + } + case bsCurly: { + painter->setBrush( Qt::NoBrush ); + QPainterPath path; + path.moveTo( ( centerVec + widthVec + lengthVec ).toPointF() ); + path.cubicTo( ( centerVec + widthVec - lengthVec * 0.8 ).toPointF(), ( centerVec + 0.4 * widthVec + lengthVec ).toPointF(), centerVec.toPointF() ); + path.cubicTo( ( centerVec - 0.4 * widthVec + lengthVec ).toPointF(), ( centerVec - widthVec - lengthVec * 0.8 ).toPointF(), ( centerVec - widthVec + lengthVec ).toPointF() ); + painter->drawPath( path ); + break; + } + case bsCalligraphic: { + painter->setPen( Qt::NoPen ); + painter->setBrush( QBrush( mainPen().color() ) ); + QPainterPath path; + path.moveTo( ( centerVec + widthVec + lengthVec ).toPointF() ); + + path.cubicTo( ( centerVec + widthVec - lengthVec * 0.8 ).toPointF(), ( centerVec + 0.4 * widthVec + 0.8 * lengthVec ).toPointF(), centerVec.toPointF() ); + path.cubicTo( ( centerVec - 0.4 * widthVec + 0.8 * lengthVec ).toPointF(), ( centerVec - widthVec - lengthVec * 0.8 ).toPointF(), ( centerVec - widthVec + lengthVec ).toPointF() ); + + path.cubicTo( ( centerVec - widthVec - lengthVec * 0.5 ).toPointF(), ( centerVec - 0.2 * widthVec + 1.2 * lengthVec ).toPointF(), ( centerVec + lengthVec * 0.2 ).toPointF() ); + path.cubicTo( ( centerVec + 0.2 * widthVec + 1.2 * lengthVec ).toPointF(), ( centerVec + widthVec - lengthVec * 0.5 ).toPointF(), ( centerVec + widthVec + lengthVec ).toPointF() ); + + painter->drawPath( path ); + break; + } } } } /* inherits documentation from base class */ -QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const +QPointF QCPItemBracket::anchorPixelPosition( int anchorId ) const { - QCPVector2D leftVec(left->pixelPosition()); - QCPVector2D rightVec(right->pixelPosition()); - if (leftVec.toPoint() == rightVec.toPoint()) + QCPVector2D leftVec( left->pixelPosition() ); + QCPVector2D rightVec( right->pixelPosition() ); + if( leftVec.toPoint() == rightVec.toPoint() ) return leftVec.toPointF(); - - QCPVector2D widthVec = (rightVec-leftVec)*0.5; - QCPVector2D lengthVec = widthVec.perpendicular().normalized()*mLength; - QCPVector2D centerVec = (rightVec+leftVec)*0.5-lengthVec; - - switch (anchorId) + + QCPVector2D widthVec = ( rightVec - leftVec ) * 0.5; + QCPVector2D lengthVec = widthVec.perpendicular().normalized() * mLength; + QCPVector2D centerVec = ( rightVec + leftVec ) * 0.5 - lengthVec; + + switch( anchorId ) { - case aiCenter: - return centerVec.toPointF(); + case aiCenter: + return centerVec.toPointF(); } qDebug() << Q_FUNC_INFO << "invalid anchorId" << anchorId; return QPointF(); @@ -30207,8 +30732,6 @@ QPointF QCPItemBracket::anchorPixelPosition(int anchorId) const */ QPen QCPItemBracket::mainPen() const { - return mSelected ? mSelectedPen : mPen; + return mSelected ? mSelectedPen : mPen; } /* end of 'src/items/item-bracket.cpp' */ - - diff --git a/app/external/qcustomplot/qcustomplot.h b/app/external/qcustomplot/qcustomplot.h index 3b046e5..9ff6400 100644 --- a/app/external/qcustomplot/qcustomplot.h +++ b/app/external/qcustomplot/qcustomplot.h @@ -30,65 +30,67 @@ // some Qt version/configuration dependent macros to include or exclude certain code paths: #ifdef QCUSTOMPLOT_USE_OPENGL -# if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# define QCP_OPENGL_PBUFFER -# else -# define QCP_OPENGL_FBO -# endif -# if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) -# define QCP_OPENGL_OFFSCREENSURFACE -# endif +#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) +#define QCP_OPENGL_PBUFFER +#else +#define QCP_OPENGL_FBO +#endif +#if QT_VERSION >= QT_VERSION_CHECK( 5, 3, 0 ) +#define QCP_OPENGL_OFFSCREENSURFACE +#endif #endif -#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) -# define QCP_DEVICEPIXELRATIO_SUPPORTED -# if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) -# define QCP_DEVICEPIXELRATIO_FLOAT -# endif +#if QT_VERSION >= QT_VERSION_CHECK( 5, 4, 0 ) +#define QCP_DEVICEPIXELRATIO_SUPPORTED +#if QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 ) +#define QCP_DEVICEPIXELRATIO_FLOAT +#endif #endif +#include + +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #ifdef QCP_OPENGL_FBO -# include -# include -# ifdef QCP_OPENGL_OFFSCREENSURFACE -# include -# else -# include -# endif +#include +#include +#ifdef QCP_OPENGL_OFFSCREENSURFACE +#include +#else +#include +#endif #endif #ifdef QCP_OPENGL_PBUFFER -# include +#include #endif -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) -# include -# include -# include -# include +#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) +#include + +#include +#include +#include #else -# include -# include -# include +#include +#include +#include #endif class QCPPainter; @@ -119,19 +121,19 @@ class QCPBars; #define QCUSTOMPLOT_VERSION 0x020001 // decl definitions for shared library compilation/usage: -#if defined(QT_STATIC_BUILD) -# define QCP_LIB_DECL -#elif defined(QCUSTOMPLOT_COMPILE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_EXPORT -#elif defined(QCUSTOMPLOT_USE_LIBRARY) -# define QCP_LIB_DECL Q_DECL_IMPORT +#if defined( QT_STATIC_BUILD ) +#define QCP_LIB_DECL +#elif defined( QCUSTOMPLOT_COMPILE_LIBRARY ) +#define QCP_LIB_DECL Q_DECL_EXPORT +#elif defined( QCUSTOMPLOT_USE_LIBRARY ) +#define QCP_LIB_DECL Q_DECL_IMPORT #else -# define QCP_LIB_DECL +#define QCP_LIB_DECL #endif // define empty macro for Q_DECL_OVERRIDE if it doesn't exist (Qt < 5) #ifndef Q_DECL_OVERRIDE -# define Q_DECL_OVERRIDE +#define Q_DECL_OVERRIDE #endif /*! @@ -141,23 +143,25 @@ class QCPBars; It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. */ #ifndef Q_MOC_RUN -namespace QCP { +namespace QCP +{ #else -class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace +class QCP +{ // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace Q_GADGET - Q_ENUMS(ExportPen) - Q_ENUMS(ResolutionUnit) - Q_ENUMS(SignDomain) - Q_ENUMS(MarginSide) - Q_FLAGS(MarginSides) - Q_ENUMS(AntialiasedElement) - Q_FLAGS(AntialiasedElements) - Q_ENUMS(PlottingHint) - Q_FLAGS(PlottingHints) - Q_ENUMS(Interaction) - Q_FLAGS(Interactions) - Q_ENUMS(SelectionRectMode) - Q_ENUMS(SelectionType) + Q_ENUMS( ExportPen ) + Q_ENUMS( ResolutionUnit ) + Q_ENUMS( SignDomain ) + Q_ENUMS( MarginSide ) + Q_FLAGS( MarginSides ) + Q_ENUMS( AntialiasedElement ) + Q_FLAGS( AntialiasedElements ) + Q_ENUMS( PlottingHint ) + Q_FLAGS( PlottingHints ) + Q_ENUMS( Interaction ) + Q_FLAGS( Interactions ) + Q_ENUMS( SelectionRectMode ) + Q_ENUMS( SelectionType ) public: #endif @@ -167,19 +171,26 @@ public: \see QCustomPlot::savePng, QCustomPlot::saveJpg, QCustomPlot::saveBmp, QCustomPlot::saveRastered */ -enum ResolutionUnit { ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) - ,ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) - ,ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) - }; +enum ResolutionUnit +{ + ruDotsPerMeter ///< Resolution is given in dots per meter (dpm) + , + ruDotsPerCentimeter ///< Resolution is given in dots per centimeter (dpcm) + , + ruDotsPerInch ///< Resolution is given in dots per inch (DPI/PPI) +}; /*! Defines how cosmetic pens (pens with numerical width 0) are handled during export. \see QCustomPlot::savePdf */ -enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting - ,epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) - }; +enum ExportPen +{ + epNoCosmetic ///< Cosmetic pens are converted to pens with pixel width 1 when exporting + , + epAllowCosmetic ///< Cosmetic pens are exported normally (e.g. in PDF exports, cosmetic pens always appear as 1 pixel on screen, independent of viewer zoom level) +}; /*! Represents negative and positive sign domain, e.g. for passing to \ref @@ -188,24 +199,35 @@ enum ExportPen { epNoCosmetic ///< Cosmetic pens are converted to pens with This is primarily needed when working with logarithmic axis scales, since only one of the sign domains can be visible at a time. */ -enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero - ,sdBoth ///< Both sign domains, including zero, i.e. all numbers - ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero - }; +enum SignDomain +{ + sdNegative ///< The negative sign domain, i.e. numbers smaller than zero + , + sdBoth ///< Both sign domains, including zero, i.e. all numbers + , + sdPositive ///< The positive sign domain, i.e. numbers greater than zero +}; /*! Defines the sides of a rectangular entity to which margins can be applied. \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins */ -enum MarginSide { msLeft = 0x01 ///< 0x01 left margin - ,msRight = 0x02 ///< 0x02 right margin - ,msTop = 0x04 ///< 0x04 top margin - ,msBottom = 0x08 ///< 0x08 bottom margin - ,msAll = 0xFF ///< 0xFF all margins - ,msNone = 0x00 ///< 0x00 no margin - }; -Q_DECLARE_FLAGS(MarginSides, MarginSide) +enum MarginSide +{ + msLeft = 0x01 ///< 0x01 left margin + , + msRight = 0x02 ///< 0x02 right margin + , + msTop = 0x04 ///< 0x04 top margin + , + msBottom = 0x08 ///< 0x08 bottom margin + , + msAll = 0xFF ///< 0xFF all margins + , + msNone = 0x00 ///< 0x00 no margin +}; +Q_DECLARE_FLAGS( MarginSides, MarginSide ) /*! Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is @@ -216,35 +238,54 @@ Q_DECLARE_FLAGS(MarginSides, MarginSide) \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements */ -enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks - ,aeGrid = 0x0002 ///< 0x0002 Grid lines - ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines - ,aeLegend = 0x0008 ///< 0x0008 Legend box - ,aeLegendItems = 0x0010 ///< 0x0010 Legend items - ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables - ,aeItems = 0x0040 ///< 0x0040 Main lines of items - ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) - ,aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) - ,aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen - ,aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories - ,aeAll = 0xFFFF ///< 0xFFFF All elements - ,aeNone = 0x0000 ///< 0x0000 No elements - }; -Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement) +enum AntialiasedElement +{ + aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks + , + aeGrid = 0x0002 ///< 0x0002 Grid lines + , + aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines + , + aeLegend = 0x0008 ///< 0x0008 Legend box + , + aeLegendItems = 0x0010 ///< 0x0010 Legend items + , + aePlottables = 0x0020 ///< 0x0020 Main lines of plottables + , + aeItems = 0x0040 ///< 0x0040 Main lines of items + , + aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap) + , + aeFills = 0x0100 ///< 0x0100 Borders of fills (e.g. under or between graphs) + , + aeZeroLine = 0x0200 ///< 0x0200 Zero-lines, see \ref QCPGrid::setZeroLinePen + , + aeOther = 0x8000 ///< 0x8000 Other elements that don't fit into any of the existing categories + , + aeAll = 0xFFFF ///< 0xFFFF All elements + , + aeNone = 0x0000 ///< 0x0000 No elements +}; +Q_DECLARE_FLAGS( AntialiasedElements, AntialiasedElement ) /*! Defines plotting hints that control various aspects of the quality and speed of plotting. \see QCustomPlot::setPlottingHints */ -enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set - ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment - ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. - ,phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. - ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). - ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. - }; -Q_DECLARE_FLAGS(PlottingHints, PlottingHint) +enum PlottingHint +{ + phNone = 0x000 ///< 0x000 No hints are set + , + phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality especially of the line segment + ///< joins, thus is most effective for pen sizes larger than 1. It is only used for solid line pens. + , + phImmediateRefresh = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpRefreshHint. + ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse). + , + phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance. +}; +Q_DECLARE_FLAGS( PlottingHints, PlottingHint ) /*! Defines the mouse interactions possible with QCustomPlot. @@ -253,27 +294,41 @@ Q_DECLARE_FLAGS(PlottingHints, PlottingHint) \see QCustomPlot::setInteractions */ -enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) - ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) - ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking - ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) - ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) - ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) - ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) - ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) - }; -Q_DECLARE_FLAGS(Interactions, Interaction) +enum Interaction +{ + iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes) + , + iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes) + , + iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking + , + iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) + , + iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts) + , + iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts) + , + iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem) + , + iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, other layout elements,...) +}; +Q_DECLARE_FLAGS( Interactions, Interaction ) /*! Defines the behaviour of the selection rect. \see QCustomPlot::setSelectionRectMode, QCustomPlot::selectionRect, QCPSelectionRect */ -enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging - ,srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. - ,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) - ,srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. - }; +enum SelectionRectMode +{ + srmNone ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging + , + srmZoom ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly. + , + srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See \ref dataselection "data selection mechanism" for details.) + , + srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction. +}; /*! Defines the different ways a plottable can be selected. These images show the effect of the @@ -293,12 +348,18 @@ enum SelectionRectMode { srmNone ///< The selection rect is disabled, and all \see QCPAbstractPlottable::setSelectable, QCPDataSelection::enforceType */ -enum SelectionType { stNone ///< The plottable is not selectable - ,stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. - ,stSingleData ///< One individual data point can be selected at a time - ,stDataRange ///< Multiple contiguous data points (a data range) can be selected - ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected - }; +enum SelectionType +{ + stNone ///< The plottable is not selectable + , + stWhole ///< Selection behaves like \ref stMultipleDataRanges, but if there are any data points selected, the entire plottable is drawn as selected. + , + stSingleData ///< One individual data point can be selected at a time + , + stDataRange ///< Multiple contiguous data points (a data range) can be selected + , + stMultipleDataRanges ///< Any combination of data points/ranges can be selected +}; /*! \internal @@ -306,9 +367,9 @@ enum SelectionType { stNone ///< The plottable is not selectable is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the compiler flag \c QCUSTOMPLOT_CHECK_DATA is set. */ -inline bool isInvalidData(double value) +inline bool isInvalidData( double value ) { - return qIsNaN(value) || qIsInf(value); + return qIsNaN( value ) || qIsInf( value ); } /*! \internal @@ -316,9 +377,9 @@ inline bool isInvalidData(double value) Checks two arguments instead of one. */ -inline bool isInvalidData(double value1, double value2) +inline bool isInvalidData( double value1, double value2 ) { - return isInvalidData(value1) || isInvalidData(value2); + return isInvalidData( value1 ) || isInvalidData( value2 ); } /*! \internal @@ -327,16 +388,27 @@ inline bool isInvalidData(double value1, double value2) \see getMarginValue */ -inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) +inline void setMarginValue( QMargins& margins, QCP::MarginSide side, int value ) { - switch (side) + switch( side ) { - case QCP::msLeft: margins.setLeft(value); break; - case QCP::msRight: margins.setRight(value); break; - case QCP::msTop: margins.setTop(value); break; - case QCP::msBottom: margins.setBottom(value); break; - case QCP::msAll: margins = QMargins(value, value, value, value); break; - default: break; + case QCP::msLeft: + margins.setLeft( value ); + break; + case QCP::msRight: + margins.setRight( value ); + break; + case QCP::msTop: + margins.setTop( value ); + break; + case QCP::msBottom: + margins.setBottom( value ); + break; + case QCP::msAll: + margins = QMargins( value, value, value, value ); + break; + default: + break; } } @@ -347,40 +419,43 @@ inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value) \see setMarginValue */ -inline int getMarginValue(const QMargins &margins, QCP::MarginSide side) +inline int getMarginValue( const QMargins& margins, QCP::MarginSide side ) { - switch (side) + switch( side ) { - case QCP::msLeft: return margins.left(); - case QCP::msRight: return margins.right(); - case QCP::msTop: return margins.top(); - case QCP::msBottom: return margins.bottom(); - default: break; + case QCP::msLeft: + return margins.left(); + case QCP::msRight: + return margins.right(); + case QCP::msTop: + return margins.top(); + case QCP::msBottom: + return margins.bottom(); + default: + break; } return 0; } +extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace -extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace - -} // end of namespace QCP -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions) -Q_DECLARE_METATYPE(QCP::ExportPen) -Q_DECLARE_METATYPE(QCP::ResolutionUnit) -Q_DECLARE_METATYPE(QCP::SignDomain) -Q_DECLARE_METATYPE(QCP::MarginSide) -Q_DECLARE_METATYPE(QCP::AntialiasedElement) -Q_DECLARE_METATYPE(QCP::PlottingHint) -Q_DECLARE_METATYPE(QCP::Interaction) -Q_DECLARE_METATYPE(QCP::SelectionRectMode) -Q_DECLARE_METATYPE(QCP::SelectionType) +} // end of namespace QCP +Q_DECLARE_OPERATORS_FOR_FLAGS( QCP::AntialiasedElements ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCP::PlottingHints ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCP::MarginSides ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCP::Interactions ) +Q_DECLARE_METATYPE( QCP::ExportPen ) +Q_DECLARE_METATYPE( QCP::ResolutionUnit ) +Q_DECLARE_METATYPE( QCP::SignDomain ) +Q_DECLARE_METATYPE( QCP::MarginSide ) +Q_DECLARE_METATYPE( QCP::AntialiasedElement ) +Q_DECLARE_METATYPE( QCP::PlottingHint ) +Q_DECLARE_METATYPE( QCP::Interaction ) +Q_DECLARE_METATYPE( QCP::SelectionRectMode ) +Q_DECLARE_METATYPE( QCP::SelectionType ) /* end of 'src/global.h' */ - /* including file 'src/vector2d.h', size 4928 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -388,73 +463,90 @@ class QCP_LIB_DECL QCPVector2D { public: QCPVector2D(); - QCPVector2D(double x, double y); - QCPVector2D(const QPoint &point); - QCPVector2D(const QPointF &point); - + QCPVector2D( double x, double y ); + QCPVector2D( const QPoint& point ); + QCPVector2D( const QPointF& point ); + // getters: double x() const { return mX; } double y() const { return mY; } - double &rx() { return mX; } - double &ry() { return mY; } - + double& rx() { return mX; } + double& ry() { return mY; } + // setters: - void setX(double x) { mX = x; } - void setY(double y) { mY = y; } - + void setX( double x ) { mX = x; } + void setY( double y ) { mY = y; } + // non-virtual methods: - double length() const { return qSqrt(mX*mX+mY*mY); } - double lengthSquared() const { return mX*mX+mY*mY; } - QPoint toPoint() const { return QPoint(mX, mY); } - QPointF toPointF() const { return QPointF(mX, mY); } - - bool isNull() const { return qIsNull(mX) && qIsNull(mY); } + double length() const { return qSqrt( mX * mX + mY * mY ); } + double lengthSquared() const { return mX * mX + mY * mY; } + QPoint toPoint() const { return QPoint( mX, mY ); } + QPointF toPointF() const { return QPointF( mX, mY ); } + + bool isNull() const { return qIsNull( mX ) && qIsNull( mY ); } void normalize(); QCPVector2D normalized() const; - QCPVector2D perpendicular() const { return QCPVector2D(-mY, mX); } - double dot(const QCPVector2D &vec) const { return mX*vec.mX+mY*vec.mY; } - double distanceSquaredToLine(const QCPVector2D &start, const QCPVector2D &end) const; - double distanceSquaredToLine(const QLineF &line) const; - double distanceToStraightLine(const QCPVector2D &base, const QCPVector2D &direction) const; - - QCPVector2D &operator*=(double factor); - QCPVector2D &operator/=(double divisor); - QCPVector2D &operator+=(const QCPVector2D &vector); - QCPVector2D &operator-=(const QCPVector2D &vector); - + QCPVector2D perpendicular() const { return QCPVector2D( -mY, mX ); } + double dot( const QCPVector2D& vec ) const { return mX * vec.mX + mY * vec.mY; } + double distanceSquaredToLine( const QCPVector2D& start, const QCPVector2D& end ) const; + double distanceSquaredToLine( const QLineF& line ) const; + double distanceToStraightLine( const QCPVector2D& base, const QCPVector2D& direction ) const; + + QCPVector2D& operator*=( double factor ); + QCPVector2D& operator/=( double divisor ); + QCPVector2D& operator+=( const QCPVector2D& vector ); + QCPVector2D& operator-=( const QCPVector2D& vector ); + private: // property members: double mX, mY; - - friend inline const QCPVector2D operator*(double factor, const QCPVector2D &vec); - friend inline const QCPVector2D operator*(const QCPVector2D &vec, double factor); - friend inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor); - friend inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2); - friend inline const QCPVector2D operator-(const QCPVector2D &vec); -}; -Q_DECLARE_TYPEINFO(QCPVector2D, Q_MOVABLE_TYPE); -inline const QCPVector2D operator*(double factor, const QCPVector2D &vec) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator*(const QCPVector2D &vec, double factor) { return QCPVector2D(vec.mX*factor, vec.mY*factor); } -inline const QCPVector2D operator/(const QCPVector2D &vec, double divisor) { return QCPVector2D(vec.mX/divisor, vec.mY/divisor); } -inline const QCPVector2D operator+(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX+vec2.mX, vec1.mY+vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec1, const QCPVector2D &vec2) { return QCPVector2D(vec1.mX-vec2.mX, vec1.mY-vec2.mY); } -inline const QCPVector2D operator-(const QCPVector2D &vec) { return QCPVector2D(-vec.mX, -vec.mY); } + friend inline const QCPVector2D operator*( double factor, const QCPVector2D& vec ); + friend inline const QCPVector2D operator*( const QCPVector2D& vec, double factor ); + friend inline const QCPVector2D operator/( const QCPVector2D& vec, double divisor ); + friend inline const QCPVector2D operator+( const QCPVector2D& vec1, const QCPVector2D& vec2 ); + friend inline const QCPVector2D operator-( const QCPVector2D& vec1, const QCPVector2D& vec2 ); + friend inline const QCPVector2D operator-( const QCPVector2D& vec ); +}; +Q_DECLARE_TYPEINFO( QCPVector2D, Q_MOVABLE_TYPE ); + +inline const QCPVector2D operator*( double factor, const QCPVector2D& vec ) +{ + return QCPVector2D( vec.mX * factor, vec.mY * factor ); +} +inline const QCPVector2D operator*( const QCPVector2D& vec, double factor ) +{ + return QCPVector2D( vec.mX * factor, vec.mY * factor ); +} +inline const QCPVector2D operator/( const QCPVector2D& vec, double divisor ) +{ + return QCPVector2D( vec.mX / divisor, vec.mY / divisor ); +} +inline const QCPVector2D operator+( const QCPVector2D& vec1, const QCPVector2D& vec2 ) +{ + return QCPVector2D( vec1.mX + vec2.mX, vec1.mY + vec2.mY ); +} +inline const QCPVector2D operator-( const QCPVector2D& vec1, const QCPVector2D& vec2 ) +{ + return QCPVector2D( vec1.mX - vec2.mX, vec1.mY - vec2.mY ); +} +inline const QCPVector2D operator-( const QCPVector2D& vec ) +{ + return QCPVector2D( -vec.mX, -vec.mY ); +} /*! \relates QCPVector2D Prints \a vec in a human readable format to the qDebug output. */ -inline QDebug operator<< (QDebug d, const QCPVector2D &vec) +inline QDebug operator<<( QDebug d, const QCPVector2D& vec ) { - d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; - return d.space(); + d.nospace() << "QCPVector2D(" << vec.x() << ", " << vec.y() << ")"; + return d.space(); } /* end of 'src/vector2d.h' */ - /* including file 'src/painter.h', size 4035 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -466,162 +558,162 @@ public: Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds, depending on whether they are wanted on the respective output device. */ - enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices - ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. - ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels - ,pmNonCosmetic = 0x04 ///< 0x04 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.) - }; - Q_ENUMS(PainterMode) - Q_FLAGS(PainterModes) - Q_DECLARE_FLAGS(PainterModes, PainterMode) - + enum PainterMode + { + pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices + , + pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes. + , + pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels + , + pmNonCosmetic = 0x04 ///< 0x04 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.) + }; + Q_ENUMS( PainterMode ) + Q_FLAGS( PainterModes ) + Q_DECLARE_FLAGS( PainterModes, PainterMode ) + QCPPainter(); - explicit QCPPainter(QPaintDevice *device); - + explicit QCPPainter( QPaintDevice* device ); + // getters: - bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); } + bool antialiasing() const { return testRenderHint( QPainter::Antialiasing ); } PainterModes modes() const { return mModes; } // setters: - void setAntialiasing(bool enabled); - void setMode(PainterMode mode, bool enabled=true); - void setModes(PainterModes modes); + void setAntialiasing( bool enabled ); + void setMode( PainterMode mode, bool enabled = true ); + void setModes( PainterModes modes ); // methods hiding non-virtual base class functions (QPainter bug workarounds): - bool begin(QPaintDevice *device); - void setPen(const QPen &pen); - void setPen(const QColor &color); - void setPen(Qt::PenStyle penStyle); - void drawLine(const QLineF &line); - void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));} + bool begin( QPaintDevice* device ); + void setPen( const QPen& pen ); + void setPen( const QColor& color ); + void setPen( Qt::PenStyle penStyle ); + void drawLine( const QLineF& line ); + void drawLine( const QPointF& p1, const QPointF& p2 ) { drawLine( QLineF( p1, p2 ) ); } void save(); void restore(); - + // non-virtual methods: void makeNonCosmetic(); - + protected: // property members: PainterModes mModes; bool mIsAntialiasing; - + // non-property members: QStack mAntialiasingStack; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes) -Q_DECLARE_METATYPE(QCPPainter::PainterMode) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCPPainter::PainterModes ) +Q_DECLARE_METATYPE( QCPPainter::PainterMode ) /* end of 'src/painter.h' */ - /* including file 'src/paintbuffer.h', size 4958 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ class QCP_LIB_DECL QCPAbstractPaintBuffer { public: - explicit QCPAbstractPaintBuffer(const QSize &size, double devicePixelRatio); + explicit QCPAbstractPaintBuffer( const QSize& size, double devicePixelRatio ); virtual ~QCPAbstractPaintBuffer(); - + // getters: QSize size() const { return mSize; } bool invalidated() const { return mInvalidated; } double devicePixelRatio() const { return mDevicePixelRatio; } - + // setters: - void setSize(const QSize &size); - void setInvalidated(bool invalidated=true); - void setDevicePixelRatio(double ratio); - + void setSize( const QSize& size ); + void setInvalidated( bool invalidated = true ); + void setDevicePixelRatio( double ratio ); + // introduced virtual methods: - virtual QCPPainter *startPainting() = 0; + virtual QCPPainter* startPainting() = 0; virtual void donePainting() {} - virtual void draw(QCPPainter *painter) const = 0; - virtual void clear(const QColor &color) = 0; - + virtual void draw( QCPPainter* painter ) const = 0; + virtual void clear( const QColor& color ) = 0; + protected: // property members: QSize mSize; double mDevicePixelRatio; - + // non-property members: bool mInvalidated; - + // introduced virtual methods: virtual void reallocateBuffer() = 0; }; - class QCP_LIB_DECL QCPPaintBufferPixmap : public QCPAbstractPaintBuffer { public: - explicit QCPPaintBufferPixmap(const QSize &size, double devicePixelRatio); + explicit QCPPaintBufferPixmap( const QSize& size, double devicePixelRatio ); virtual ~QCPPaintBufferPixmap(); - + // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - + virtual QCPPainter* startPainting() Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) const Q_DECL_OVERRIDE; + void clear( const QColor& color ) Q_DECL_OVERRIDE; + protected: // non-property members: QPixmap mBuffer; - + // reimplemented virtual methods: virtual void reallocateBuffer() Q_DECL_OVERRIDE; }; - #ifdef QCP_OPENGL_PBUFFER class QCP_LIB_DECL QCPPaintBufferGlPbuffer : public QCPAbstractPaintBuffer { public: - explicit QCPPaintBufferGlPbuffer(const QSize &size, double devicePixelRatio, int multisamples); + explicit QCPPaintBufferGlPbuffer( const QSize& size, double devicePixelRatio, int multisamples ); virtual ~QCPPaintBufferGlPbuffer(); - + // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - + virtual QCPPainter* startPainting() Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) const Q_DECL_OVERRIDE; + void clear( const QColor& color ) Q_DECL_OVERRIDE; + protected: // non-property members: - QGLPixelBuffer *mGlPBuffer; + QGLPixelBuffer* mGlPBuffer; int mMultisamples; - + // reimplemented virtual methods: virtual void reallocateBuffer() Q_DECL_OVERRIDE; }; -#endif // QCP_OPENGL_PBUFFER - +#endif // QCP_OPENGL_PBUFFER #ifdef QCP_OPENGL_FBO class QCP_LIB_DECL QCPPaintBufferGlFbo : public QCPAbstractPaintBuffer { public: - explicit QCPPaintBufferGlFbo(const QSize &size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice); + explicit QCPPaintBufferGlFbo( const QSize& size, double devicePixelRatio, QWeakPointer glContext, QWeakPointer glPaintDevice ); virtual ~QCPPaintBufferGlFbo(); - + // reimplemented virtual methods: - virtual QCPPainter *startPainting() Q_DECL_OVERRIDE; + virtual QCPPainter* startPainting() Q_DECL_OVERRIDE; virtual void donePainting() Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) const Q_DECL_OVERRIDE; - void clear(const QColor &color) Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) const Q_DECL_OVERRIDE; + void clear( const QColor& color ) Q_DECL_OVERRIDE; + protected: // non-property members: QWeakPointer mGlContext; QWeakPointer mGlPaintDevice; - QOpenGLFramebufferObject *mGlFrameBuffer; - + QOpenGLFramebufferObject* mGlFrameBuffer; + // reimplemented virtual methods: virtual void reallocateBuffer() Q_DECL_OVERRIDE; }; -#endif // QCP_OPENGL_FBO +#endif // QCP_OPENGL_FBO /* end of 'src/paintbuffer.h' */ - /* including file 'src/layer.h', size 6885 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -629,15 +721,14 @@ class QCP_LIB_DECL QCPLayer : public QObject { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QString name READ name) - Q_PROPERTY(int index READ index) - Q_PROPERTY(QList children READ children) - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(LayerMode mode READ mode WRITE setMode) + Q_PROPERTY( QCustomPlot* parentPlot READ parentPlot ) + Q_PROPERTY( QString name READ name ) + Q_PROPERTY( int index READ index ) + Q_PROPERTY( QList children READ children ) + Q_PROPERTY( bool visible READ visible WRITE setVisible ) + Q_PROPERTY( LayerMode mode READ mode WRITE setMode ) /// \endcond public: - /*! Defines the different rendering modes of a layer. Depending on the mode, certain layers can be replotted individually, without the need to replot (possibly complex) layerables on other @@ -645,124 +736,127 @@ public: \see setMode */ - enum LayerMode { lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. - ,lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). - }; - Q_ENUMS(LayerMode) - - QCPLayer(QCustomPlot* parentPlot, const QString &layerName); + enum LayerMode + { + lmLogical ///< Layer is used only for rendering order, and shares paint buffer with all other adjacent logical layers. + , + lmBuffered ///< Layer has its own paint buffer and may be replotted individually (see \ref replot). + }; + Q_ENUMS( LayerMode ) + + QCPLayer( QCustomPlot* parentPlot, const QString& layerName ); virtual ~QCPLayer(); - + // getters: - QCustomPlot *parentPlot() const { return mParentPlot; } + QCustomPlot* parentPlot() const { return mParentPlot; } QString name() const { return mName; } int index() const { return mIndex; } QList children() const { return mChildren; } bool visible() const { return mVisible; } LayerMode mode() const { return mMode; } - + // setters: - void setVisible(bool visible); - void setMode(LayerMode mode); - + void setVisible( bool visible ); + void setMode( LayerMode mode ); + // non-virtual methods: void replot(); - + protected: // property members: - QCustomPlot *mParentPlot; + QCustomPlot* mParentPlot; QString mName; int mIndex; QList mChildren; bool mVisible; LayerMode mMode; - + // non-property members: QWeakPointer mPaintBuffer; - + // non-virtual methods: - void draw(QCPPainter *painter); + void draw( QCPPainter* painter ); void drawToPaintBuffer(); - void addChild(QCPLayerable *layerable, bool prepend); - void removeChild(QCPLayerable *layerable); - + void addChild( QCPLayerable* layerable, bool prepend ); + void removeChild( QCPLayerable* layerable ); + private: - Q_DISABLE_COPY(QCPLayer) - + Q_DISABLE_COPY( QCPLayer ) + friend class QCustomPlot; friend class QCPLayerable; }; -Q_DECLARE_METATYPE(QCPLayer::LayerMode) +Q_DECLARE_METATYPE( QCPLayer::LayerMode ) class QCP_LIB_DECL QCPLayerable : public QObject { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool visible READ visible WRITE setVisible) - Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot) - Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable) - Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged) - Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased) + Q_PROPERTY( bool visible READ visible WRITE setVisible ) + Q_PROPERTY( QCustomPlot* parentPlot READ parentPlot ) + Q_PROPERTY( QCPLayerable* parentLayerable READ parentLayerable ) + Q_PROPERTY( QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged ) + Q_PROPERTY( bool antialiased READ antialiased WRITE setAntialiased ) /// \endcond public: - QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=0); + QCPLayerable( QCustomPlot* plot, QString targetLayer = QString(), QCPLayerable* parentLayerable = 0 ); virtual ~QCPLayerable(); - + // getters: bool visible() const { return mVisible; } - QCustomPlot *parentPlot() const { return mParentPlot; } - QCPLayerable *parentLayerable() const { return mParentLayerable.data(); } - QCPLayer *layer() const { return mLayer; } + QCustomPlot* parentPlot() const { return mParentPlot; } + QCPLayerable* parentLayerable() const { return mParentLayerable.data(); } + QCPLayer* layer() const { return mLayer; } bool antialiased() const { return mAntialiased; } - + // setters: - void setVisible(bool on); - Q_SLOT bool setLayer(QCPLayer *layer); - bool setLayer(const QString &layerName); - void setAntialiased(bool enabled); - + void setVisible( bool on ); + Q_SLOT bool setLayer( QCPLayer* layer ); + bool setLayer( const QString& layerName ); + void setAntialiased( bool enabled ); + // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const; // non-property methods: bool realVisibility() const; - + signals: - void layerChanged(QCPLayer *newLayer); - + void layerChanged( QCPLayer* newLayer ); + protected: // property members: bool mVisible; - QCustomPlot *mParentPlot; + QCustomPlot* mParentPlot; QPointer mParentLayerable; - QCPLayer *mLayer; + QCPLayer* mLayer; bool mAntialiased; - + // introduced virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot); + virtual void parentPlotInitialized( QCustomPlot* parentPlot ); virtual QCP::Interaction selectionCategory() const; virtual QRect clipRect() const; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0; - virtual void draw(QCPPainter *painter) = 0; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const = 0; + virtual void draw( QCPPainter* painter ) = 0; // selection events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged); - virtual void deselectEvent(bool *selectionStateChanged); + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ); + virtual void deselectEvent( bool* selectionStateChanged ); // low-level mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details); - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos); - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details); - virtual void wheelEvent(QWheelEvent *event); - + virtual void mousePressEvent( QMouseEvent* event, const QVariant& details ); + virtual void mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ); + virtual void mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ); + virtual void mouseDoubleClickEvent( QMouseEvent* event, const QVariant& details ); + virtual void wheelEvent( QWheelEvent* event ); + // non-property methods: - void initializeParentPlot(QCustomPlot *parentPlot); - void setParentLayerable(QCPLayerable* parentLayerable); - bool moveToLayer(QCPLayer *layer, bool prepend); - void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const; - + void initializeParentPlot( QCustomPlot* parentPlot ); + void setParentLayerable( QCPLayerable* parentLayerable ); + bool moveToLayer( QCPLayer* layer, bool prepend ); + void applyAntialiasingHint( QCPPainter* painter, bool localAntialiased, QCP::AntialiasedElement overrideElement ) const; + private: - Q_DISABLE_COPY(QCPLayerable) - + Q_DISABLE_COPY( QCPLayerable ) + friend class QCustomPlot; friend class QCPLayer; friend class QCPAxisRect; @@ -770,7 +864,6 @@ private: /* end of 'src/layer.h' */ - /* including file 'src/axis/range.h', size 5280 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -778,60 +871,83 @@ class QCP_LIB_DECL QCPRange { public: double lower, upper; - + QCPRange(); - QCPRange(double lower, double upper); - - bool operator==(const QCPRange& other) const { return lower == other.lower && upper == other.upper; } - bool operator!=(const QCPRange& other) const { return !(*this == other); } - - QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; } - QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; } - QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; } - QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; } - friend inline const QCPRange operator+(const QCPRange&, double); - friend inline const QCPRange operator+(double, const QCPRange&); - friend inline const QCPRange operator-(const QCPRange& range, double value); - friend inline const QCPRange operator*(const QCPRange& range, double value); - friend inline const QCPRange operator*(double value, const QCPRange& range); - friend inline const QCPRange operator/(const QCPRange& range, double value); - - double size() const { return upper-lower; } - double center() const { return (upper+lower)*0.5; } - void normalize() { if (lower > upper) qSwap(lower, upper); } - void expand(const QCPRange &otherRange); - void expand(double includeCoord); - QCPRange expanded(const QCPRange &otherRange) const; - QCPRange expanded(double includeCoord) const; - QCPRange bounded(double lowerBound, double upperBound) const; + QCPRange( double lower, double upper ); + + bool operator==( const QCPRange& other ) const { return lower == other.lower && upper == other.upper; } + bool operator!=( const QCPRange& other ) const { return !( *this == other ); } + + QCPRange& operator+=( const double& value ) + { + lower += value; + upper += value; + return *this; + } + QCPRange& operator-=( const double& value ) + { + lower -= value; + upper -= value; + return *this; + } + QCPRange& operator*=( const double& value ) + { + lower *= value; + upper *= value; + return *this; + } + QCPRange& operator/=( const double& value ) + { + lower /= value; + upper /= value; + return *this; + } + friend inline const QCPRange operator+( const QCPRange&, double ); + friend inline const QCPRange operator+( double, const QCPRange& ); + friend inline const QCPRange operator-( const QCPRange& range, double value ); + friend inline const QCPRange operator*( const QCPRange& range, double value ); + friend inline const QCPRange operator*( double value, const QCPRange& range ); + friend inline const QCPRange operator/( const QCPRange& range, double value ); + + double size() const { return upper - lower; } + double center() const { return ( upper + lower ) * 0.5; } + void normalize() + { + if( lower > upper ) + qSwap( lower, upper ); + } + void expand( const QCPRange& otherRange ); + void expand( double includeCoord ); + QCPRange expanded( const QCPRange& otherRange ) const; + QCPRange expanded( double includeCoord ) const; + QCPRange bounded( double lowerBound, double upperBound ) const; QCPRange sanitizedForLogScale() const; QCPRange sanitizedForLinScale() const; - bool contains(double value) const { return value >= lower && value <= upper; } - - static bool validRange(double lower, double upper); - static bool validRange(const QCPRange &range); + bool contains( double value ) const { return value >= lower && value <= upper; } + + static bool validRange( double lower, double upper ); + static bool validRange( const QCPRange& range ); static const double minRange; static const double maxRange; - }; -Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO( QCPRange, Q_MOVABLE_TYPE ); /*! \relates QCPRange Prints \a range in a human readable format to the qDebug output. */ -inline QDebug operator<< (QDebug d, const QCPRange &range) +inline QDebug operator<<( QDebug d, const QCPRange& range ) { - d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; - return d.space(); + d.nospace() << "QCPRange(" << range.lower << ", " << range.upper << ")"; + return d.space(); } /*! Adds \a value to both boundaries of the range. */ -inline const QCPRange operator+(const QCPRange& range, double value) +inline const QCPRange operator+( const QCPRange& range, double value ) { - QCPRange result(range); + QCPRange result( range ); result += value; return result; } @@ -839,9 +955,9 @@ inline const QCPRange operator+(const QCPRange& range, double value) /*! Adds \a value to both boundaries of the range. */ -inline const QCPRange operator+(double value, const QCPRange& range) +inline const QCPRange operator+( double value, const QCPRange& range ) { - QCPRange result(range); + QCPRange result( range ); result += value; return result; } @@ -849,9 +965,9 @@ inline const QCPRange operator+(double value, const QCPRange& range) /*! Subtracts \a value from both boundaries of the range. */ -inline const QCPRange operator-(const QCPRange& range, double value) +inline const QCPRange operator-( const QCPRange& range, double value ) { - QCPRange result(range); + QCPRange result( range ); result -= value; return result; } @@ -859,9 +975,9 @@ inline const QCPRange operator-(const QCPRange& range, double value) /*! Multiplies both boundaries of the range by \a value. */ -inline const QCPRange operator*(const QCPRange& range, double value) +inline const QCPRange operator*( const QCPRange& range, double value ) { - QCPRange result(range); + QCPRange result( range ); result *= value; return result; } @@ -869,9 +985,9 @@ inline const QCPRange operator*(const QCPRange& range, double value) /*! Multiplies both boundaries of the range by \a value. */ -inline const QCPRange operator*(double value, const QCPRange& range) +inline const QCPRange operator*( double value, const QCPRange& range ) { - QCPRange result(range); + QCPRange result( range ); result *= value; return result; } @@ -879,16 +995,15 @@ inline const QCPRange operator*(double value, const QCPRange& range) /*! Divides both boundaries of the range by \a value. */ -inline const QCPRange operator/(const QCPRange& range, double value) +inline const QCPRange operator/( const QCPRange& range, double value ) { - QCPRange result(range); + QCPRange result( range ); result /= value; return result; } /* end of 'src/axis/range.h' */ - /* including file 'src/selection.h', size 8569 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -896,94 +1011,91 @@ class QCP_LIB_DECL QCPDataRange { public: QCPDataRange(); - QCPDataRange(int begin, int end); - - bool operator==(const QCPDataRange& other) const { return mBegin == other.mBegin && mEnd == other.mEnd; } - bool operator!=(const QCPDataRange& other) const { return !(*this == other); } - + QCPDataRange( int begin, int end ); + + bool operator==( const QCPDataRange& other ) const { return mBegin == other.mBegin && mEnd == other.mEnd; } + bool operator!=( const QCPDataRange& other ) const { return !( *this == other ); } + // getters: int begin() const { return mBegin; } int end() const { return mEnd; } - int size() const { return mEnd-mBegin; } + int size() const { return mEnd - mBegin; } int length() const { return size(); } - + // setters: - void setBegin(int begin) { mBegin = begin; } - void setEnd(int end) { mEnd = end; } - + void setBegin( int begin ) { mBegin = begin; } + void setEnd( int end ) { mEnd = end; } + // non-property methods: - bool isValid() const { return (mEnd >= mBegin) && (mBegin >= 0); } + bool isValid() const { return ( mEnd >= mBegin ) && ( mBegin >= 0 ); } bool isEmpty() const { return length() == 0; } - QCPDataRange bounded(const QCPDataRange &other) const; - QCPDataRange expanded(const QCPDataRange &other) const; - QCPDataRange intersection(const QCPDataRange &other) const; - QCPDataRange adjusted(int changeBegin, int changeEnd) const { return QCPDataRange(mBegin+changeBegin, mEnd+changeEnd); } - bool intersects(const QCPDataRange &other) const; - bool contains(const QCPDataRange &other) const; - + QCPDataRange bounded( const QCPDataRange& other ) const; + QCPDataRange expanded( const QCPDataRange& other ) const; + QCPDataRange intersection( const QCPDataRange& other ) const; + QCPDataRange adjusted( int changeBegin, int changeEnd ) const { return QCPDataRange( mBegin + changeBegin, mEnd + changeEnd ); } + bool intersects( const QCPDataRange& other ) const; + bool contains( const QCPDataRange& other ) const; + private: // property members: int mBegin, mEnd; - }; -Q_DECLARE_TYPEINFO(QCPDataRange, Q_MOVABLE_TYPE); - +Q_DECLARE_TYPEINFO( QCPDataRange, Q_MOVABLE_TYPE ); class QCP_LIB_DECL QCPDataSelection { public: explicit QCPDataSelection(); - explicit QCPDataSelection(const QCPDataRange &range); - - bool operator==(const QCPDataSelection& other) const; - bool operator!=(const QCPDataSelection& other) const { return !(*this == other); } - QCPDataSelection &operator+=(const QCPDataSelection& other); - QCPDataSelection &operator+=(const QCPDataRange& other); - QCPDataSelection &operator-=(const QCPDataSelection& other); - QCPDataSelection &operator-=(const QCPDataRange& other); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b); - friend inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b); - friend inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b); - + explicit QCPDataSelection( const QCPDataRange& range ); + + bool operator==( const QCPDataSelection& other ) const; + bool operator!=( const QCPDataSelection& other ) const { return !( *this == other ); } + QCPDataSelection& operator+=( const QCPDataSelection& other ); + QCPDataSelection& operator+=( const QCPDataRange& other ); + QCPDataSelection& operator-=( const QCPDataSelection& other ); + QCPDataSelection& operator-=( const QCPDataRange& other ); + friend inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDataSelection& b ); + friend inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataSelection& b ); + friend inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDataRange& b ); + friend inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataRange& b ); + friend inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDataSelection& b ); + friend inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataSelection& b ); + friend inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDataRange& b ); + friend inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataRange& b ); + // getters: int dataRangeCount() const { return mDataRanges.size(); } int dataPointCount() const; - QCPDataRange dataRange(int index=0) const; + QCPDataRange dataRange( int index = 0 ) const; QList dataRanges() const { return mDataRanges; } QCPDataRange span() const; - + // non-property methods: - void addDataRange(const QCPDataRange &dataRange, bool simplify=true); + void addDataRange( const QCPDataRange& dataRange, bool simplify = true ); void clear(); bool isEmpty() const { return mDataRanges.isEmpty(); } void simplify(); - void enforceType(QCP::SelectionType type); - bool contains(const QCPDataSelection &other) const; - QCPDataSelection intersection(const QCPDataRange &other) const; - QCPDataSelection intersection(const QCPDataSelection &other) const; - QCPDataSelection inverse(const QCPDataRange &outerRange) const; - + void enforceType( QCP::SelectionType type ); + bool contains( const QCPDataSelection& other ) const; + QCPDataSelection intersection( const QCPDataRange& other ) const; + QCPDataSelection intersection( const QCPDataSelection& other ) const; + QCPDataSelection inverse( const QCPDataRange& outerRange ) const; + private: // property members: QList mDataRanges; - - inline static bool lessThanDataRangeBegin(const QCPDataRange &a, const QCPDataRange &b) { return a.begin() < b.begin(); } + + inline static bool lessThanDataRangeBegin( const QCPDataRange& a, const QCPDataRange& b ) { return a.begin() < b.begin(); } }; -Q_DECLARE_METATYPE(QCPDataSelection) - +Q_DECLARE_METATYPE( QCPDataSelection ) /*! Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). */ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataSelection& b) +inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDataSelection& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result += b; return result; } @@ -992,9 +1104,9 @@ inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPData Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). */ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSelection& b) +inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataSelection& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result += b; return result; } @@ -1003,9 +1115,9 @@ inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataSele Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). */ -inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPDataRange& b) +inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDataRange& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result += b; return result; } @@ -1014,9 +1126,9 @@ inline const QCPDataSelection operator+(const QCPDataSelection& a, const QCPData Return a \ref QCPDataSelection with the data points in \a a joined with the data points in \a b. The resulting data selection is already simplified (see \ref QCPDataSelection::simplify). */ -inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRange& b) +inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataRange& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result += b; return result; } @@ -1024,9 +1136,9 @@ inline const QCPDataSelection operator+(const QCPDataRange& a, const QCPDataRang /*! Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. */ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataSelection& b) +inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDataSelection& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result -= b; return result; } @@ -1034,9 +1146,9 @@ inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPData /*! Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. */ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSelection& b) +inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataSelection& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result -= b; return result; } @@ -1044,9 +1156,9 @@ inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataSele /*! Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. */ -inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPDataRange& b) +inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDataRange& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result -= b; return result; } @@ -1054,9 +1166,9 @@ inline const QCPDataSelection operator-(const QCPDataSelection& a, const QCPData /*! Return a \ref QCPDataSelection with the data points which are in \a a but not in \a b. */ -inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRange& b) +inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataRange& b ) { - QCPDataSelection result(a); + QCPDataSelection result( a ); result -= b; return result; } @@ -1065,7 +1177,7 @@ inline const QCPDataSelection operator-(const QCPDataRange& a, const QCPDataRang Prints \a dataRange in a human readable format to the qDebug output. */ -inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) +inline QDebug operator<<( QDebug d, const QCPDataRange& dataRange ) { d.nospace() << "QCPDataRange(" << dataRange.begin() << ", " << dataRange.end() << ")"; return d; @@ -1075,24 +1187,21 @@ inline QDebug operator<< (QDebug d, const QCPDataRange &dataRange) Prints \a selection in a human readable format to the qDebug output. */ -inline QDebug operator<< (QDebug d, const QCPDataSelection &selection) +inline QDebug operator<<( QDebug d, const QCPDataSelection& selection ) { - d.nospace() << "QCPDataSelection("; - for (int i=0; i elements(QCP::MarginSide side) const { return mChildren.value(side); } + QList elements( QCP::MarginSide side ) const { return mChildren.value( side ); } bool isEmpty() const; void clear(); - + protected: // non-property members: - QCustomPlot *mParentPlot; + QCustomPlot* mParentPlot; QHash > mChildren; - + // introduced virtual methods: - virtual int commonMargin(QCP::MarginSide side) const; - + virtual int commonMargin( QCP::MarginSide side ) const; + // non-virtual methods: - void addChild(QCP::MarginSide side, QCPLayoutElement *element); - void removeChild(QCP::MarginSide side, QCPLayoutElement *element); - + void addChild( QCP::MarginSide side, QCPLayoutElement* element ); + void removeChild( QCP::MarginSide side, QCPLayoutElement* element ); + private: - Q_DISABLE_COPY(QCPMarginGroup) - + Q_DISABLE_COPY( QCPMarginGroup ) + friend class QCPLayoutElement; }; - class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLayout* layout READ layout) - Q_PROPERTY(QRect rect READ rect) - Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect) - Q_PROPERTY(QMargins margins READ margins WRITE setMargins) - Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins) - Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize) - Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize) - Q_PROPERTY(SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect) + Q_PROPERTY( QCPLayout* layout READ layout ) + Q_PROPERTY( QRect rect READ rect ) + Q_PROPERTY( QRect outerRect READ outerRect WRITE setOuterRect ) + Q_PROPERTY( QMargins margins READ margins WRITE setMargins ) + Q_PROPERTY( QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins ) + Q_PROPERTY( QSize minimumSize READ minimumSize WRITE setMinimumSize ) + Q_PROPERTY( QSize maximumSize READ maximumSize WRITE setMaximumSize ) + Q_PROPERTY( SizeConstraintRect sizeConstraintRect READ sizeConstraintRect WRITE setSizeConstraintRect ) /// \endcond public: /*! Defines the phases of the update process, that happens just before a replot. At each phase, \ref update is called with the according UpdatePhase value. */ - enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout - ,upMargins ///< Phase in which the margins are calculated and set - ,upLayout ///< Final phase in which the layout system places the rects of the elements - }; - Q_ENUMS(UpdatePhase) - + enum UpdatePhase + { + upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout + , + upMargins ///< Phase in which the margins are calculated and set + , + upLayout ///< Final phase in which the layout system places the rects of the elements + }; + Q_ENUMS( UpdatePhase ) + /*! Defines to which rect of a layout element the size constraints that can be set via \ref setMinimumSize and \ref setMaximumSize apply. The outer rect (\ref outerRect) includes the @@ -1213,16 +1324,19 @@ public: \see setSizeConstraintRect */ - enum SizeConstraintRect { scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect - , scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins - }; - Q_ENUMS(SizeConstraintRect) + enum SizeConstraintRect + { + scrInnerRect ///< Minimum/Maximum size constraints apply to inner rect + , + scrOuterRect ///< Minimum/Maximum size constraints apply to outer rect, thus include layout element margins + }; + Q_ENUMS( SizeConstraintRect ) - explicit QCPLayoutElement(QCustomPlot *parentPlot=0); + explicit QCPLayoutElement( QCustomPlot* parentPlot = 0 ); virtual ~QCPLayoutElement(); - + // getters: - QCPLayout *layout() const { return mParentLayout; } + QCPLayout* layout() const { return mParentLayout; } QRect rect() const { return mRect; } QRect outerRect() const { return mOuterRect; } QMargins margins() const { return mMargins; } @@ -1231,114 +1345,111 @@ public: QSize minimumSize() const { return mMinimumSize; } QSize maximumSize() const { return mMaximumSize; } SizeConstraintRect sizeConstraintRect() const { return mSizeConstraintRect; } - QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); } + QCPMarginGroup* marginGroup( QCP::MarginSide side ) const { return mMarginGroups.value( side, (QCPMarginGroup*)0 ); } QHash marginGroups() const { return mMarginGroups; } - + // setters: - void setOuterRect(const QRect &rect); - void setMargins(const QMargins &margins); - void setMinimumMargins(const QMargins &margins); - void setAutoMargins(QCP::MarginSides sides); - void setMinimumSize(const QSize &size); - void setMinimumSize(int width, int height); - void setMaximumSize(const QSize &size); - void setMaximumSize(int width, int height); - void setSizeConstraintRect(SizeConstraintRect constraintRect); - void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group); - + void setOuterRect( const QRect& rect ); + void setMargins( const QMargins& margins ); + void setMinimumMargins( const QMargins& margins ); + void setAutoMargins( QCP::MarginSides sides ); + void setMinimumSize( const QSize& size ); + void setMinimumSize( int width, int height ); + void setMaximumSize( const QSize& size ); + void setMaximumSize( int width, int height ); + void setSizeConstraintRect( SizeConstraintRect constraintRect ); + void setMarginGroup( QCP::MarginSides sides, QCPMarginGroup* group ); + // introduced virtual methods: - virtual void update(UpdatePhase phase); + virtual void update( UpdatePhase phase ); virtual QSize minimumOuterSizeHint() const; virtual QSize maximumOuterSizeHint() const; - virtual QList elements(bool recursive) const; - + virtual QList elements( bool recursive ) const; + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + protected: // property members: - QCPLayout *mParentLayout; + QCPLayout* mParentLayout; QSize mMinimumSize, mMaximumSize; SizeConstraintRect mSizeConstraintRect; QRect mRect, mOuterRect; QMargins mMargins, mMinimumMargins; QCP::MarginSides mAutoMargins; QHash mMarginGroups; - + // introduced virtual methods: - virtual int calculateAutoMargin(QCP::MarginSide side); + virtual int calculateAutoMargin( QCP::MarginSide side ); virtual void layoutChanged(); - + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE { Q_UNUSED(painter) } - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE { Q_UNUSED( painter ) } + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE { Q_UNUSED( painter ) } + virtual void parentPlotInitialized( QCustomPlot* parentPlot ) Q_DECL_OVERRIDE; private: - Q_DISABLE_COPY(QCPLayoutElement) - + Q_DISABLE_COPY( QCPLayoutElement ) + friend class QCustomPlot; friend class QCPLayout; friend class QCPMarginGroup; }; -Q_DECLARE_METATYPE(QCPLayoutElement::UpdatePhase) - +Q_DECLARE_METATYPE( QCPLayoutElement::UpdatePhase ) class QCP_LIB_DECL QCPLayout : public QCPLayoutElement { Q_OBJECT public: explicit QCPLayout(); - + // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; - + virtual void update( UpdatePhase phase ) Q_DECL_OVERRIDE; + virtual QList elements( bool recursive ) const Q_DECL_OVERRIDE; + // introduced virtual methods: virtual int elementCount() const = 0; - virtual QCPLayoutElement* elementAt(int index) const = 0; - virtual QCPLayoutElement* takeAt(int index) = 0; - virtual bool take(QCPLayoutElement* element) = 0; + virtual QCPLayoutElement* elementAt( int index ) const = 0; + virtual QCPLayoutElement* takeAt( int index ) = 0; + virtual bool take( QCPLayoutElement* element ) = 0; virtual void simplify(); - + // non-virtual methods: - bool removeAt(int index); - bool remove(QCPLayoutElement* element); + bool removeAt( int index ); + bool remove( QCPLayoutElement* element ); void clear(); - + protected: // introduced virtual methods: virtual void updateLayout(); - + // non-virtual methods: void sizeConstraintsChanged() const; - void adoptElement(QCPLayoutElement *el); - void releaseElement(QCPLayoutElement *el); - QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const; - static QSize getFinalMinimumOuterSize(const QCPLayoutElement *el); - static QSize getFinalMaximumOuterSize(const QCPLayoutElement *el); - + void adoptElement( QCPLayoutElement* el ); + void releaseElement( QCPLayoutElement* el ); + QVector getSectionSizes( QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize ) const; + static QSize getFinalMinimumOuterSize( const QCPLayoutElement* el ); + static QSize getFinalMaximumOuterSize( const QCPLayoutElement* el ); + private: - Q_DISABLE_COPY(QCPLayout) + Q_DISABLE_COPY( QCPLayout ) friend class QCPLayoutElement; }; - class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(int rowCount READ rowCount) - Q_PROPERTY(int columnCount READ columnCount) - Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors) - Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors) - Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing) - Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing) - Q_PROPERTY(FillOrder fillOrder READ fillOrder WRITE setFillOrder) - Q_PROPERTY(int wrap READ wrap WRITE setWrap) + Q_PROPERTY( int rowCount READ rowCount ) + Q_PROPERTY( int columnCount READ columnCount ) + Q_PROPERTY( QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors ) + Q_PROPERTY( QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors ) + Q_PROPERTY( int columnSpacing READ columnSpacing WRITE setColumnSpacing ) + Q_PROPERTY( int rowSpacing READ rowSpacing WRITE setRowSpacing ) + Q_PROPERTY( FillOrder fillOrder READ fillOrder WRITE setFillOrder ) + Q_PROPERTY( int wrap READ wrap WRITE setWrap ) /// \endcond public: - /*! Defines in which direction the grid is filled when using \ref addElement(QCPLayoutElement*). The column/row at which wrapping into the next row/column occurs can be specified with \ref @@ -1346,14 +1457,17 @@ public: \see setFillOrder */ - enum FillOrder { foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. - ,foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. - }; - Q_ENUMS(FillOrder) - + enum FillOrder + { + foRowsFirst ///< Rows are filled first, and a new element is wrapped to the next column if the row count would exceed \ref setWrap. + , + foColumnsFirst ///< Columns are filled first, and a new element is wrapped to the next row if the column count would exceed \ref setWrap. + }; + Q_ENUMS( FillOrder ) + explicit QCPLayoutGrid(); virtual ~QCPLayoutGrid(); - + // getters: int rowCount() const { return mElements.size(); } int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } @@ -1363,39 +1477,39 @@ public: int rowSpacing() const { return mRowSpacing; } int wrap() const { return mWrap; } FillOrder fillOrder() const { return mFillOrder; } - + // setters: - void setColumnStretchFactor(int column, double factor); - void setColumnStretchFactors(const QList &factors); - void setRowStretchFactor(int row, double factor); - void setRowStretchFactors(const QList &factors); - void setColumnSpacing(int pixels); - void setRowSpacing(int pixels); - void setWrap(int count); - void setFillOrder(FillOrder order, bool rearrange=true); - + void setColumnStretchFactor( int column, double factor ); + void setColumnStretchFactors( const QList& factors ); + void setRowStretchFactor( int row, double factor ); + void setRowStretchFactors( const QList& factors ); + void setColumnSpacing( int pixels ); + void setRowSpacing( int pixels ); + void setWrap( int count ); + void setFillOrder( FillOrder order, bool rearrange = true ); + // reimplemented virtual methods: virtual void updateLayout() Q_DECL_OVERRIDE; - virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount()*columnCount(); } - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + virtual int elementCount() const Q_DECL_OVERRIDE { return rowCount() * columnCount(); } + virtual QCPLayoutElement* elementAt( int index ) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt( int index ) Q_DECL_OVERRIDE; + virtual bool take( QCPLayoutElement* element ) Q_DECL_OVERRIDE; + virtual QList elements( bool recursive ) const Q_DECL_OVERRIDE; virtual void simplify() Q_DECL_OVERRIDE; virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; - + // non-virtual methods: - QCPLayoutElement *element(int row, int column) const; - bool addElement(int row, int column, QCPLayoutElement *element); - bool addElement(QCPLayoutElement *element); - bool hasElement(int row, int column); - void expandTo(int newRowCount, int newColumnCount); - void insertRow(int newIndex); - void insertColumn(int newIndex); - int rowColToIndex(int row, int column) const; - void indexToRowCol(int index, int &row, int &column) const; - + QCPLayoutElement* element( int row, int column ) const; + bool addElement( int row, int column, QCPLayoutElement* element ); + bool addElement( QCPLayoutElement* element ); + bool hasElement( int row, int column ); + void expandTo( int newRowCount, int newColumnCount ); + void insertRow( int newIndex ); + void insertColumn( int newIndex ); + int rowColToIndex( int row, int column ) const; + void indexToRowCol( int index, int& row, int& column ) const; + protected: // property members: QList > mElements; @@ -1404,16 +1518,15 @@ protected: int mColumnSpacing, mRowSpacing; int mWrap; FillOrder mFillOrder; - - // non-virtual methods: - void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; - void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; - -private: - Q_DISABLE_COPY(QCPLayoutGrid) -}; -Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) + // non-virtual methods: + void getMinimumRowColSizes( QVector* minColWidths, QVector* minRowHeights ) const; + void getMaximumRowColSizes( QVector* maxColWidths, QVector* maxRowHeights ) const; + +private: + Q_DISABLE_COPY( QCPLayoutGrid ) +}; +Q_DECLARE_METATYPE( QCPLayoutGrid::FillOrder ) class QCP_LIB_DECL QCPLayoutInset : public QCPLayout { @@ -1422,52 +1535,54 @@ public: /*! Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset. */ - enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect - ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment - }; - Q_ENUMS(InsetPlacement) - + enum InsetPlacement + { + ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect + , + ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment + }; + Q_ENUMS( InsetPlacement ) + explicit QCPLayoutInset(); virtual ~QCPLayoutInset(); - + // getters: - InsetPlacement insetPlacement(int index) const; - Qt::Alignment insetAlignment(int index) const; - QRectF insetRect(int index) const; - + InsetPlacement insetPlacement( int index ) const; + Qt::Alignment insetAlignment( int index ) const; + QRectF insetRect( int index ) const; + // setters: - void setInsetPlacement(int index, InsetPlacement placement); - void setInsetAlignment(int index, Qt::Alignment alignment); - void setInsetRect(int index, const QRectF &rect); - + void setInsetPlacement( int index, InsetPlacement placement ); + void setInsetAlignment( int index, Qt::Alignment alignment ); + void setInsetRect( int index, const QRectF& rect ); + // reimplemented virtual methods: virtual void updateLayout() Q_DECL_OVERRIDE; virtual int elementCount() const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* elementAt(int index) const Q_DECL_OVERRIDE; - virtual QCPLayoutElement* takeAt(int index) Q_DECL_OVERRIDE; - virtual bool take(QCPLayoutElement* element) Q_DECL_OVERRIDE; + virtual QCPLayoutElement* elementAt( int index ) const Q_DECL_OVERRIDE; + virtual QCPLayoutElement* takeAt( int index ) Q_DECL_OVERRIDE; + virtual bool take( QCPLayoutElement* element ) Q_DECL_OVERRIDE; virtual void simplify() Q_DECL_OVERRIDE {} - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + // non-virtual methods: - void addElement(QCPLayoutElement *element, Qt::Alignment alignment); - void addElement(QCPLayoutElement *element, const QRectF &rect); - + void addElement( QCPLayoutElement* element, Qt::Alignment alignment ); + void addElement( QCPLayoutElement* element, const QRectF& rect ); + protected: // property members: QList mElements; QList mInsetPlacement; QList mInsetAlignment; QList mInsetRect; - + private: - Q_DISABLE_COPY(QCPLayoutInset) + Q_DISABLE_COPY( QCPLayoutInset ) }; -Q_DECLARE_METATYPE(QCPLayoutInset::InsetPlacement) +Q_DECLARE_METATYPE( QCPLayoutInset::InsetPlacement ) /* end of 'src/layout.h' */ - /* including file 'src/lineending.h', size 4426 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1486,52 +1601,62 @@ public: \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding */ - enum EndingStyle { esNone ///< No ending decoration - ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) - ,esSpikeArrow ///< A filled arrow head with an indented back - ,esLineArrow ///< A non-filled arrow head with open back - ,esDisc ///< A filled circle - ,esSquare ///< A filled square - ,esDiamond ///< A filled diamond (45 degrees rotated square) - ,esBar ///< A bar perpendicular to the line - ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) - ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) - }; - Q_ENUMS(EndingStyle) - + enum EndingStyle + { + esNone ///< No ending decoration + , + esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle) + , + esSpikeArrow ///< A filled arrow head with an indented back + , + esLineArrow ///< A non-filled arrow head with open back + , + esDisc ///< A filled circle + , + esSquare ///< A filled square + , + esDiamond ///< A filled diamond (45 degrees rotated square) + , + esBar ///< A bar perpendicular to the line + , + esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted) + , + esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength) + }; + Q_ENUMS( EndingStyle ) + QCPLineEnding(); - QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false); - + QCPLineEnding( EndingStyle style, double width = 8, double length = 10, bool inverted = false ); + // getters: EndingStyle style() const { return mStyle; } double width() const { return mWidth; } double length() const { return mLength; } bool inverted() const { return mInverted; } - + // setters: - void setStyle(EndingStyle style); - void setWidth(double width); - void setLength(double length); - void setInverted(bool inverted); - + void setStyle( EndingStyle style ); + void setWidth( double width ); + void setLength( double length ); + void setInverted( bool inverted ); + // non-property methods: double boundingDistance() const; double realLength() const; - void draw(QCPPainter *painter, const QCPVector2D &pos, const QCPVector2D &dir) const; - void draw(QCPPainter *painter, const QCPVector2D &pos, double angle) const; - + void draw( QCPPainter* painter, const QCPVector2D& pos, const QCPVector2D& dir ) const; + void draw( QCPPainter* painter, const QCPVector2D& pos, double angle ) const; + protected: // property members: EndingStyle mStyle; double mWidth, mLength; bool mInverted; }; -Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE); -Q_DECLARE_METATYPE(QCPLineEnding::EndingStyle) +Q_DECLARE_TYPEINFO( QCPLineEnding, Q_MOVABLE_TYPE ); +Q_DECLARE_METATYPE( QCPLineEnding::EndingStyle ) /* end of 'src/lineending.h' */ - /* including file 'src/axis/axisticker.h', size 4224 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1546,57 +1671,56 @@ public: */ enum TickStepStrategy { - tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) - ,tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count + tssReadability ///< A nicely readable tick step is prioritized over matching the requested number of ticks (see \ref setTickCount) + , + tssMeetTickCount ///< Less readable tick steps are allowed which in turn facilitates getting closer to the requested tick count }; - Q_ENUMS(TickStepStrategy) - + Q_ENUMS( TickStepStrategy ) + QCPAxisTicker(); virtual ~QCPAxisTicker(); - + // getters: TickStepStrategy tickStepStrategy() const { return mTickStepStrategy; } int tickCount() const { return mTickCount; } double tickOrigin() const { return mTickOrigin; } - + // setters: - void setTickStepStrategy(TickStepStrategy strategy); - void setTickCount(int count); - void setTickOrigin(double origin); - + void setTickStepStrategy( TickStepStrategy strategy ); + void setTickCount( int count ); + void setTickOrigin( double origin ); + // introduced virtual methods: - virtual void generate(const QCPRange &range, const QLocale &locale, QChar formatChar, int precision, QVector &ticks, QVector *subTicks, QVector *tickLabels); - + virtual void generate( const QCPRange& range, const QLocale& locale, QChar formatChar, int precision, QVector& ticks, QVector* subTicks, QVector* tickLabels ); + protected: // property members: TickStepStrategy mTickStepStrategy; int mTickCount; double mTickOrigin; - + // introduced virtual methods: - virtual double getTickStep(const QCPRange &range); - virtual int getSubTickCount(double tickStep); - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision); - virtual QVector createTickVector(double tickStep, const QCPRange &range); - virtual QVector createSubTickVector(int subTickCount, const QVector &ticks); - virtual QVector createLabelVector(const QVector &ticks, const QLocale &locale, QChar formatChar, int precision); - + virtual double getTickStep( const QCPRange& range ); + virtual int getSubTickCount( double tickStep ); + virtual QString getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ); + virtual QVector createTickVector( double tickStep, const QCPRange& range ); + virtual QVector createSubTickVector( int subTickCount, const QVector& ticks ); + virtual QVector createLabelVector( const QVector& ticks, const QLocale& locale, QChar formatChar, int precision ); + // non-virtual methods: - void trimTicks(const QCPRange &range, QVector &ticks, bool keepOneOutlier) const; - double pickClosest(double target, const QVector &candidates) const; - double getMantissa(double input, double *magnitude=0) const; - double cleanMantissa(double input) const; - + void trimTicks( const QCPRange& range, QVector& ticks, bool keepOneOutlier ) const; + double pickClosest( double target, const QVector& candidates ) const; + double getMantissa( double input, double* magnitude = 0 ) const; + double cleanMantissa( double input ) const; + private: - Q_DISABLE_COPY(QCPAxisTicker) - + Q_DISABLE_COPY( QCPAxisTicker ) }; -Q_DECLARE_METATYPE(QCPAxisTicker::TickStepStrategy) -Q_DECLARE_METATYPE(QSharedPointer) +Q_DECLARE_METATYPE( QCPAxisTicker::TickStepStrategy ) +Q_DECLARE_METATYPE( QSharedPointer ) /* end of 'src/axis/axisticker.h' */ - /* including file 'src/axis/axistickerdatetime.h', size 3289 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1604,40 +1728,44 @@ class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker { public: QCPAxisTickerDateTime(); - + // getters: QString dateTimeFormat() const { return mDateTimeFormat; } Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } - + // setters: - void setDateTimeFormat(const QString &format); - void setDateTimeSpec(Qt::TimeSpec spec); - void setTickOrigin(double origin); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) - void setTickOrigin(const QDateTime &origin); - + void setDateTimeFormat( const QString& format ); + void setDateTimeSpec( Qt::TimeSpec spec ); + void setTickOrigin( double origin ); // hides base class method but calls baseclass implementation ("using" throws off IDEs and doxygen) + void setTickOrigin( const QDateTime& origin ); + // static methods: - static QDateTime keyToDateTime(double key); - static double dateTimeToKey(const QDateTime dateTime); - static double dateTimeToKey(const QDate date); - + static QDateTime keyToDateTime( double key ); + static double dateTimeToKey( const QDateTime dateTime ); + static double dateTimeToKey( const QDate date ); + protected: // property members: QString mDateTimeFormat; Qt::TimeSpec mDateTimeSpec; - + // non-property members: - enum DateStrategy {dsNone, dsUniformTimeInDay, dsUniformDayInMonth} mDateStrategy; - + enum DateStrategy + { + dsNone, + dsUniformTimeInDay, + dsUniformDayInMonth + } mDateStrategy; + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; + virtual int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; + virtual QString getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) Q_DECL_OVERRIDE; + virtual QVector createTickVector( double tickStep, const QCPRange& range ) Q_DECL_OVERRIDE; }; /* end of 'src/axis/axistickerdatetime.h' */ - /* including file 'src/axis/axistickertime.h', size 3542 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1650,46 +1778,51 @@ public: \see setFieldWidth, setTimeFormat */ - enum TimeUnit { tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) - ,tuSeconds ///< Seconds (%%s in \ref setTimeFormat) - ,tuMinutes ///< Minutes (%%m in \ref setTimeFormat) - ,tuHours ///< Hours (%%h in \ref setTimeFormat) - ,tuDays ///< Days (%%d in \ref setTimeFormat) - }; - Q_ENUMS(TimeUnit) - + enum TimeUnit + { + tuMilliseconds ///< Milliseconds, one thousandth of a second (%%z in \ref setTimeFormat) + , + tuSeconds ///< Seconds (%%s in \ref setTimeFormat) + , + tuMinutes ///< Minutes (%%m in \ref setTimeFormat) + , + tuHours ///< Hours (%%h in \ref setTimeFormat) + , + tuDays ///< Days (%%d in \ref setTimeFormat) + }; + Q_ENUMS( TimeUnit ) + QCPAxisTickerTime(); // getters: QString timeFormat() const { return mTimeFormat; } - int fieldWidth(TimeUnit unit) const { return mFieldWidth.value(unit); } - + int fieldWidth( TimeUnit unit ) const { return mFieldWidth.value( unit ); } + // setters: - void setTimeFormat(const QString &format); - void setFieldWidth(TimeUnit unit, int width); - + void setTimeFormat( const QString& format ); + void setFieldWidth( TimeUnit unit, int width ); + protected: // property members: QString mTimeFormat; QHash mFieldWidth; - + // non-property members: TimeUnit mSmallestUnit, mBiggestUnit; QHash mFormatPattern; - + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; + virtual int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; + virtual QString getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) Q_DECL_OVERRIDE; + // non-virtual methods: - void replaceUnit(QString &text, TimeUnit unit, int value) const; + void replaceUnit( QString& text, TimeUnit unit, int value ) const; }; -Q_DECLARE_METATYPE(QCPAxisTickerTime::TimeUnit) +Q_DECLARE_METATYPE( QCPAxisTickerTime::TimeUnit ) /* end of 'src/axis/axistickertime.h' */ - /* including file 'src/axis/axistickerfixed.h', size 3308 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1703,35 +1836,38 @@ public: \see setScaleStrategy */ - enum ScaleStrategy { ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. - ,ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. - ,ssPowers ///< An integer power of the specified tick step is allowed. - }; - Q_ENUMS(ScaleStrategy) - + enum ScaleStrategy + { + ssNone ///< Modifications are not allowed, the specified tick step is absolutely fixed. This might cause a high tick density and overlapping labels if the axis range is zoomed out. + , + ssMultiples ///< An integer multiple of the specified tick step is allowed. The used factor follows the base class properties of \ref setTickStepStrategy and \ref setTickCount. + , + ssPowers ///< An integer power of the specified tick step is allowed. + }; + Q_ENUMS( ScaleStrategy ) + QCPAxisTickerFixed(); - + // getters: double tickStep() const { return mTickStep; } ScaleStrategy scaleStrategy() const { return mScaleStrategy; } - + // setters: - void setTickStep(double step); - void setScaleStrategy(ScaleStrategy strategy); - + void setTickStep( double step ); + void setScaleStrategy( ScaleStrategy strategy ); + protected: // property members: double mTickStep; ScaleStrategy mScaleStrategy; - + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; }; -Q_DECLARE_METATYPE(QCPAxisTickerFixed::ScaleStrategy) +Q_DECLARE_METATYPE( QCPAxisTickerFixed::ScaleStrategy ) /* end of 'src/axis/axistickerfixed.h' */ - /* including file 'src/axis/axistickertext.h', size 3090 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1739,37 +1875,36 @@ class QCP_LIB_DECL QCPAxisTickerText : public QCPAxisTicker { public: QCPAxisTickerText(); - + // getters: - QMap &ticks() { return mTicks; } + QMap& ticks() { return mTicks; } int subTickCount() const { return mSubTickCount; } - + // setters: - void setTicks(const QMap &ticks); - void setTicks(const QVector &positions, const QVector &labels); - void setSubTickCount(int subTicks); - + void setTicks( const QMap& ticks ); + void setTicks( const QVector& positions, const QVector& labels ); + void setSubTickCount( int subTicks ); + // non-virtual methods: void clear(); - void addTick(double position, const QString &label); - void addTicks(const QMap &ticks); - void addTicks(const QVector &positions, const QVector &labels); - + void addTick( double position, const QString& label ); + void addTicks( const QMap& ticks ); + void addTicks( const QVector& positions, const QVector& labels ); + protected: // property members: QMap mTicks; int mSubTickCount; - + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; + virtual int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; + virtual QString getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) Q_DECL_OVERRIDE; + virtual QVector createTickVector( double tickStep, const QCPRange& range ) Q_DECL_OVERRIDE; }; /* end of 'src/axis/axistickertext.h' */ - /* including file 'src/axis/axistickerpi.h', size 3911 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1782,53 +1917,56 @@ public: \see setFractionStyle */ - enum FractionStyle { fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". - ,fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" - ,fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. - }; - Q_ENUMS(FractionStyle) - + enum FractionStyle + { + fsFloatingPoint ///< Fractions are displayed as regular decimal floating point numbers, e.g. "0.25" or "0.125". + , + fsAsciiFractions ///< Fractions are written as rationals using ASCII characters only, e.g. "1/4" or "1/8" + , + fsUnicodeFractions ///< Fractions are written using sub- and superscript UTF-8 digits and the fraction symbol. + }; + Q_ENUMS( FractionStyle ) + QCPAxisTickerPi(); - + // getters: QString piSymbol() const { return mPiSymbol; } double piValue() const { return mPiValue; } bool periodicity() const { return mPeriodicity; } FractionStyle fractionStyle() const { return mFractionStyle; } - + // setters: - void setPiSymbol(QString symbol); - void setPiValue(double pi); - void setPeriodicity(int multiplesOfPi); - void setFractionStyle(FractionStyle style); - + void setPiSymbol( QString symbol ); + void setPiValue( double pi ); + void setPeriodicity( int multiplesOfPi ); + void setFractionStyle( FractionStyle style ); + protected: // property members: QString mPiSymbol; double mPiValue; int mPeriodicity; FractionStyle mFractionStyle; - + // non-property members: - double mPiTickStep; // size of one tick step in units of mPiValue - + double mPiTickStep; // size of one tick step in units of mPiValue + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QString getTickLabel(double tick, const QLocale &locale, QChar formatChar, int precision) Q_DECL_OVERRIDE; - + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; + virtual int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; + virtual QString getTickLabel( double tick, const QLocale& locale, QChar formatChar, int precision ) Q_DECL_OVERRIDE; + // non-virtual methods: - void simplifyFraction(int &numerator, int &denominator) const; - QString fractionToString(int numerator, int denominator) const; - QString unicodeFraction(int numerator, int denominator) const; - QString unicodeSuperscript(int number) const; - QString unicodeSubscript(int number) const; + void simplifyFraction( int& numerator, int& denominator ) const; + QString fractionToString( int numerator, int denominator ) const; + QString unicodeFraction( int numerator, int denominator ) const; + QString unicodeSuperscript( int number ) const; + QString unicodeSubscript( int number ) const; }; -Q_DECLARE_METATYPE(QCPAxisTickerPi::FractionStyle) +Q_DECLARE_METATYPE( QCPAxisTickerPi::FractionStyle ) /* end of 'src/axis/axistickerpi.h' */ - /* including file 'src/axis/axistickerlog.h', size 2663 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -1836,49 +1974,48 @@ class QCP_LIB_DECL QCPAxisTickerLog : public QCPAxisTicker { public: QCPAxisTickerLog(); - + // getters: double logBase() const { return mLogBase; } int subTickCount() const { return mSubTickCount; } - + // setters: - void setLogBase(double base); - void setSubTickCount(int subTicks); - + void setLogBase( double base ); + void setSubTickCount( int subTicks ); + protected: // property members: double mLogBase; int mSubTickCount; - + // non-property members: double mLogBaseLnInv; - + // reimplemented virtual methods: - virtual double getTickStep(const QCPRange &range) Q_DECL_OVERRIDE; - virtual int getSubTickCount(double tickStep) Q_DECL_OVERRIDE; - virtual QVector createTickVector(double tickStep, const QCPRange &range) Q_DECL_OVERRIDE; + virtual double getTickStep( const QCPRange& range ) Q_DECL_OVERRIDE; + virtual int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; + virtual QVector createTickVector( double tickStep, const QCPRange& range ) Q_DECL_OVERRIDE; }; /* end of 'src/axis/axistickerlog.h' */ - /* including file 'src/axis/axis.h', size 20698 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ -class QCP_LIB_DECL QCPGrid :public QCPLayerable +class QCP_LIB_DECL QCPGrid : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible) - Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid) - Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen) - Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen) + Q_PROPERTY( bool subGridVisible READ subGridVisible WRITE setSubGridVisible ) + Q_PROPERTY( bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid ) + Q_PROPERTY( bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine ) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen subGridPen READ subGridPen WRITE setSubGridPen ) + Q_PROPERTY( QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen ) /// \endcond public: - explicit QCPGrid(QCPAxis *parentAxis); - + explicit QCPGrid( QCPAxis* parentAxis ); + // getters: bool subGridVisible() const { return mSubGridVisible; } bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } @@ -1886,133 +2023,148 @@ public: QPen pen() const { return mPen; } QPen subGridPen() const { return mSubGridPen; } QPen zeroLinePen() const { return mZeroLinePen; } - + // setters: - void setSubGridVisible(bool visible); - void setAntialiasedSubGrid(bool enabled); - void setAntialiasedZeroLine(bool enabled); - void setPen(const QPen &pen); - void setSubGridPen(const QPen &pen); - void setZeroLinePen(const QPen &pen); - + void setSubGridVisible( bool visible ); + void setAntialiasedSubGrid( bool enabled ); + void setAntialiasedZeroLine( bool enabled ); + void setPen( const QPen& pen ); + void setSubGridPen( const QPen& pen ); + void setZeroLinePen( const QPen& pen ); + protected: // property members: bool mSubGridVisible; bool mAntialiasedSubGrid, mAntialiasedZeroLine; QPen mPen, mSubGridPen, mZeroLinePen; - + // non-property members: - QCPAxis *mParentAxis; - + QCPAxis* mParentAxis; + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + // non-virtual methods: - void drawGridLines(QCPPainter *painter) const; - void drawSubGridLines(QCPPainter *painter) const; - + void drawGridLines( QCPPainter* painter ) const; + void drawSubGridLines( QCPPainter* painter ) const; + friend class QCPAxis; }; - class QCP_LIB_DECL QCPAxis : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(AxisType axisType READ axisType) - Q_PROPERTY(QCPAxisRect* axisRect READ axisRect) - Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged) - Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged) - Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed) - Q_PROPERTY(QSharedPointer ticker READ ticker WRITE setTicker) - Q_PROPERTY(bool ticks READ ticks WRITE setTicks) - Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels) - Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding) - Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont) - Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor) - Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation) - Q_PROPERTY(LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide) - Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat) - Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision) - Q_PROPERTY(QVector tickVector READ tickVector) - Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels) - Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn) - Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut) - Q_PROPERTY(bool subTicks READ subTicks WRITE setSubTicks) - Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn) - Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut) - Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen) - Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen) - Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen) - Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) - Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding) - Q_PROPERTY(int padding READ padding WRITE setPadding) - Q_PROPERTY(int offset READ offset WRITE setOffset) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged) - Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont) - Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont) - Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor) - Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor) - Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen) - Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen) - Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen) - Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding) - Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding) - Q_PROPERTY(QCPGrid* grid READ grid) + Q_PROPERTY( AxisType axisType READ axisType ) + Q_PROPERTY( QCPAxisRect* axisRect READ axisRect ) + Q_PROPERTY( ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged ) + Q_PROPERTY( QCPRange range READ range WRITE setRange NOTIFY rangeChanged ) + Q_PROPERTY( bool rangeReversed READ rangeReversed WRITE setRangeReversed ) + Q_PROPERTY( QSharedPointer ticker READ ticker WRITE setTicker ) + Q_PROPERTY( bool ticks READ ticks WRITE setTicks ) + Q_PROPERTY( bool tickLabels READ tickLabels WRITE setTickLabels ) + Q_PROPERTY( int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding ) + Q_PROPERTY( QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont ) + Q_PROPERTY( QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor ) + Q_PROPERTY( double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation ) + Q_PROPERTY( LabelSide tickLabelSide READ tickLabelSide WRITE setTickLabelSide ) + Q_PROPERTY( QString numberFormat READ numberFormat WRITE setNumberFormat ) + Q_PROPERTY( int numberPrecision READ numberPrecision WRITE setNumberPrecision ) + Q_PROPERTY( QVector tickVector READ tickVector ) + Q_PROPERTY( QVector tickVectorLabels READ tickVectorLabels ) + Q_PROPERTY( int tickLengthIn READ tickLengthIn WRITE setTickLengthIn ) + Q_PROPERTY( int tickLengthOut READ tickLengthOut WRITE setTickLengthOut ) + Q_PROPERTY( bool subTicks READ subTicks WRITE setSubTicks ) + Q_PROPERTY( int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn ) + Q_PROPERTY( int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut ) + Q_PROPERTY( QPen basePen READ basePen WRITE setBasePen ) + Q_PROPERTY( QPen tickPen READ tickPen WRITE setTickPen ) + Q_PROPERTY( QPen subTickPen READ subTickPen WRITE setSubTickPen ) + Q_PROPERTY( QFont labelFont READ labelFont WRITE setLabelFont ) + Q_PROPERTY( QColor labelColor READ labelColor WRITE setLabelColor ) + Q_PROPERTY( QString label READ label WRITE setLabel ) + Q_PROPERTY( int labelPadding READ labelPadding WRITE setLabelPadding ) + Q_PROPERTY( int padding READ padding WRITE setPadding ) + Q_PROPERTY( int offset READ offset WRITE setOffset ) + Q_PROPERTY( SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged ) + Q_PROPERTY( SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged ) + Q_PROPERTY( QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont ) + Q_PROPERTY( QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont ) + Q_PROPERTY( QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor ) + Q_PROPERTY( QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor ) + Q_PROPERTY( QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen ) + Q_PROPERTY( QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen ) + Q_PROPERTY( QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen ) + Q_PROPERTY( QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding ) + Q_PROPERTY( QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding ) + Q_PROPERTY( QCPGrid* grid READ grid ) /// \endcond public: /*! Defines at which side of the axis rect the axis will appear. This also affects how the tick marks are drawn, on which side the labels are placed etc. */ - enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect - ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect - ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect - ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect - }; - Q_ENUMS(AxisType) - Q_FLAGS(AxisTypes) - Q_DECLARE_FLAGS(AxisTypes, AxisType) + enum AxisType + { + atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect + , + atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect + , + atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect + , + atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect + }; + Q_ENUMS( AxisType ) + Q_FLAGS( AxisTypes ) + Q_DECLARE_FLAGS( AxisTypes, AxisType ) /*! Defines on which side of the axis the tick labels (numbers) shall appear. \see setTickLabelSide */ - enum LabelSide { lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect - ,lsOutside ///< Tick labels will be displayed outside the axis rect - }; - Q_ENUMS(LabelSide) + enum LabelSide + { + lsInside ///< Tick labels will be displayed inside the axis rect and clipped to the inner axis rect + , + lsOutside ///< Tick labels will be displayed outside the axis rect + }; + Q_ENUMS( LabelSide ) /*! Defines the scale of an axis. \see setScaleType */ - enum ScaleType { stLinear ///< Linear scaling - ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). - }; - Q_ENUMS(ScaleType) + enum ScaleType + { + stLinear ///< Linear scaling + , + stLogarithmic ///< Logarithmic scaling with correspondingly transformed axis coordinates (possibly also \ref setTicker to a \ref QCPAxisTickerLog instance). + }; + Q_ENUMS( ScaleType ) /*! Defines the selectable parts of an axis. \see setSelectableParts, setSelectedParts */ - enum SelectablePart { spNone = 0 ///< None of the selectable parts - ,spAxis = 0x001 ///< The axis backbone and tick marks - ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) - ,spAxisLabel = 0x004 ///< The axis label - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - - explicit QCPAxis(QCPAxisRect *parent, AxisType type); + enum SelectablePart + { + spNone = 0 ///< None of the selectable parts + , + spAxis = 0x001 ///< The axis backbone and tick marks + , + spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually) + , + spAxisLabel = 0x004 ///< The axis label + }; + Q_ENUMS( SelectablePart ) + Q_FLAGS( SelectableParts ) + Q_DECLARE_FLAGS( SelectableParts, SelectablePart ) + + explicit QCPAxis( QCPAxisRect* parent, AxisType type ); virtual ~QCPAxis(); - + // getters: AxisType axisType() const { return mAxisType; } - QCPAxisRect *axisRect() const { return mAxisRect; } + QCPAxisRect* axisRect() const { return mAxisRect; } ScaleType scaleType() const { return mScaleType; } const QCPRange range() const { return mRange; } bool rangeReversed() const { return mRangeReversed; } @@ -2053,88 +2205,88 @@ public: QPen selectedSubTickPen() const { return mSelectedSubTickPen; } QCPLineEnding lowerEnding() const; QCPLineEnding upperEnding() const; - QCPGrid *grid() const { return mGrid; } - + QCPGrid* grid() const { return mGrid; } + // setters: - Q_SLOT void setScaleType(QCPAxis::ScaleType type); - Q_SLOT void setRange(const QCPRange &range); - void setRange(double lower, double upper); - void setRange(double position, double size, Qt::AlignmentFlag alignment); - void setRangeLower(double lower); - void setRangeUpper(double upper); - void setRangeReversed(bool reversed); - void setTicker(QSharedPointer ticker); - void setTicks(bool show); - void setTickLabels(bool show); - void setTickLabelPadding(int padding); - void setTickLabelFont(const QFont &font); - void setTickLabelColor(const QColor &color); - void setTickLabelRotation(double degrees); - void setTickLabelSide(LabelSide side); - void setNumberFormat(const QString &formatCode); - void setNumberPrecision(int precision); - void setTickLength(int inside, int outside=0); - void setTickLengthIn(int inside); - void setTickLengthOut(int outside); - void setSubTicks(bool show); - void setSubTickLength(int inside, int outside=0); - void setSubTickLengthIn(int inside); - void setSubTickLengthOut(int outside); - void setBasePen(const QPen &pen); - void setTickPen(const QPen &pen); - void setSubTickPen(const QPen &pen); - void setLabelFont(const QFont &font); - void setLabelColor(const QColor &color); - void setLabel(const QString &str); - void setLabelPadding(int padding); - void setPadding(int padding); - void setOffset(int offset); - void setSelectedTickLabelFont(const QFont &font); - void setSelectedLabelFont(const QFont &font); - void setSelectedTickLabelColor(const QColor &color); - void setSelectedLabelColor(const QColor &color); - void setSelectedBasePen(const QPen &pen); - void setSelectedTickPen(const QPen &pen); - void setSelectedSubTickPen(const QPen &pen); - Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts); - void setLowerEnding(const QCPLineEnding &ending); - void setUpperEnding(const QCPLineEnding &ending); - + Q_SLOT void setScaleType( QCPAxis::ScaleType type ); + Q_SLOT void setRange( const QCPRange& range ); + void setRange( double lower, double upper ); + void setRange( double position, double size, Qt::AlignmentFlag alignment ); + void setRangeLower( double lower ); + void setRangeUpper( double upper ); + void setRangeReversed( bool reversed ); + void setTicker( QSharedPointer ticker ); + void setTicks( bool show ); + void setTickLabels( bool show ); + void setTickLabelPadding( int padding ); + void setTickLabelFont( const QFont& font ); + void setTickLabelColor( const QColor& color ); + void setTickLabelRotation( double degrees ); + void setTickLabelSide( LabelSide side ); + void setNumberFormat( const QString& formatCode ); + void setNumberPrecision( int precision ); + void setTickLength( int inside, int outside = 0 ); + void setTickLengthIn( int inside ); + void setTickLengthOut( int outside ); + void setSubTicks( bool show ); + void setSubTickLength( int inside, int outside = 0 ); + void setSubTickLengthIn( int inside ); + void setSubTickLengthOut( int outside ); + void setBasePen( const QPen& pen ); + void setTickPen( const QPen& pen ); + void setSubTickPen( const QPen& pen ); + void setLabelFont( const QFont& font ); + void setLabelColor( const QColor& color ); + void setLabel( const QString& str ); + void setLabelPadding( int padding ); + void setPadding( int padding ); + void setOffset( int offset ); + void setSelectedTickLabelFont( const QFont& font ); + void setSelectedLabelFont( const QFont& font ); + void setSelectedTickLabelColor( const QColor& color ); + void setSelectedLabelColor( const QColor& color ); + void setSelectedBasePen( const QPen& pen ); + void setSelectedTickPen( const QPen& pen ); + void setSelectedSubTickPen( const QPen& pen ); + Q_SLOT void setSelectableParts( const QCPAxis::SelectableParts& selectableParts ); + Q_SLOT void setSelectedParts( const QCPAxis::SelectableParts& selectedParts ); + void setLowerEnding( const QCPLineEnding& ending ); + void setUpperEnding( const QCPLineEnding& ending ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + // non-property methods: Qt::Orientation orientation() const { return mOrientation; } - int pixelOrientation() const { return rangeReversed() != (orientation()==Qt::Vertical) ? -1 : 1; } - void moveRange(double diff); - void scaleRange(double factor); - void scaleRange(double factor, double center); - void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0); - void rescale(bool onlyVisiblePlottables=false); - double pixelToCoord(double value) const; - double coordToPixel(double value) const; - SelectablePart getPartAt(const QPointF &pos) const; + int pixelOrientation() const { return rangeReversed() != ( orientation() == Qt::Vertical ) ? -1 : 1; } + void moveRange( double diff ); + void scaleRange( double factor ); + void scaleRange( double factor, double center ); + void setScaleRatio( const QCPAxis* otherAxis, double ratio = 1.0 ); + void rescale( bool onlyVisiblePlottables = false ); + double pixelToCoord( double value ) const; + double coordToPixel( double value ) const; + SelectablePart getPartAt( const QPointF& pos ) const; QList plottables() const; QList graphs() const; QList items() const; - - static AxisType marginSideToAxisType(QCP::MarginSide side); - static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; } - static AxisType opposite(AxisType type); - + + static AxisType marginSideToAxisType( QCP::MarginSide side ); + static Qt::Orientation orientation( AxisType type ) { return type == atBottom || type == atTop ? Qt::Horizontal : Qt::Vertical; } + static AxisType opposite( AxisType type ); + signals: - void rangeChanged(const QCPRange &newRange); - void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); - void scaleTypeChanged(QCPAxis::ScaleType scaleType); - void selectionChanged(const QCPAxis::SelectableParts &parts); - void selectableChanged(const QCPAxis::SelectableParts &parts); + void rangeChanged( const QCPRange& newRange ); + void rangeChanged( const QCPRange& newRange, const QCPRange& oldRange ); + void scaleTypeChanged( QCPAxis::ScaleType scaleType ); + void selectionChanged( const QCPAxis::SelectableParts& parts ); + void selectableChanged( const QCPAxis::SelectableParts& parts ); protected: // property members: // axis base: AxisType mAxisType; - QCPAxisRect *mAxisRect; + QCPAxisRect* mAxisRect; //int mOffset; // in QCPAxisPainter int mPadding; Qt::Orientation mOrientation; @@ -2166,10 +2318,10 @@ protected: QCPRange mRange; bool mRangeReversed; ScaleType mScaleType; - + // non-property members: - QCPGrid *mGrid; - QCPAxisPainterPrivate *mAxisPainter; + QCPGrid* mGrid; + QCPAxisPainterPrivate* mAxisPainter; QSharedPointer mTicker; QVector mTickVector; QVector mTickVectorLabels; @@ -2179,23 +2331,23 @@ protected: bool mDragging; QCPRange mDragStartRange; QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; - + // introduced virtual methods: virtual int calculateMargin(); - + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; // mouse events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - + virtual void mousePressEvent( QMouseEvent* event, const QVariant& details ) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void wheelEvent( QWheelEvent* event ) Q_DECL_OVERRIDE; + // non-virtual methods: void setupTickVectors(); QPen getBasePen() const; @@ -2205,62 +2357,61 @@ protected: QFont getLabelFont() const; QColor getTickLabelColor() const; QColor getLabelColor() const; - + private: - Q_DISABLE_COPY(QCPAxis) - + Q_DISABLE_COPY( QCPAxis ) + friend class QCustomPlot; friend class QCPGrid; friend class QCPAxisRect; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts) -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes) -Q_DECLARE_METATYPE(QCPAxis::AxisType) -Q_DECLARE_METATYPE(QCPAxis::LabelSide) -Q_DECLARE_METATYPE(QCPAxis::ScaleType) -Q_DECLARE_METATYPE(QCPAxis::SelectablePart) - +Q_DECLARE_OPERATORS_FOR_FLAGS( QCPAxis::SelectableParts ) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCPAxis::AxisTypes ) +Q_DECLARE_METATYPE( QCPAxis::AxisType ) +Q_DECLARE_METATYPE( QCPAxis::LabelSide ) +Q_DECLARE_METATYPE( QCPAxis::ScaleType ) +Q_DECLARE_METATYPE( QCPAxis::SelectablePart ) class QCPAxisPainterPrivate { public: - explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot); + explicit QCPAxisPainterPrivate( QCustomPlot* parentPlot ); virtual ~QCPAxisPainterPrivate(); - - virtual void draw(QCPPainter *painter); + + virtual void draw( QCPPainter* painter ); virtual int size() const; void clearCache(); - + QRect axisSelectionBox() const { return mAxisSelectionBox; } QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; } QRect labelSelectionBox() const { return mLabelSelectionBox; } - + // public property members: QCPAxis::AxisType type; QPen basePen; - QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters - int labelPadding; // directly accessed by QCPAxis setters/getters + QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters + int labelPadding; // directly accessed by QCPAxis setters/getters QFont labelFont; QColor labelColor; QString label; - int tickLabelPadding; // directly accessed by QCPAxis setters/getters - double tickLabelRotation; // directly accessed by QCPAxis setters/getters - QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters + int tickLabelPadding; // directly accessed by QCPAxis setters/getters + double tickLabelRotation; // directly accessed by QCPAxis setters/getters + QCPAxis::LabelSide tickLabelSide; // directly accessed by QCPAxis setters/getters bool substituteExponent; - bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters - int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters + bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters + int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters QPen tickPen, subTickPen; QFont tickLabelFont; QColor tickLabelColor; QRect axisRect, viewportRect; - double offset; // directly accessed by QCPAxis setters/getters + double offset; // directly accessed by QCPAxis setters/getters bool abbreviateDecimalPowers; bool reversedEndings; - + QVector subTickPositions; QVector tickPositions; QVector tickLabels; - + protected: struct CachedLabel { @@ -2273,23 +2424,22 @@ protected: QRect baseBounds, expBounds, suffixBounds, totalBounds, rotatedTotalBounds; QFont baseFont, expFont; }; - QCustomPlot *mParentPlot; - QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters + QCustomPlot* mParentPlot; + QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters QCache mLabelCache; QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox; - + virtual QByteArray generateLabelParameterHash() const; - - virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize); - virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const; - virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const; - virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const; - virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; + + virtual void placeTickLabel( QCPPainter* painter, double position, int distanceToAxis, const QString& text, QSize* tickLabelsSize ); + virtual void drawTickLabel( QCPPainter* painter, double x, double y, const TickLabelData& labelData ) const; + virtual TickLabelData getTickLabelData( const QFont& font, const QString& text ) const; + virtual QPointF getTickLabelDrawOffset( const TickLabelData& labelData ) const; + virtual void getMaxTickLabelSize( const QFont& font, const QString& text, QSize* tickLabelsSize ) const; }; /* end of 'src/axis/axis.h' */ - /* including file 'src/scatterstyle.h', size 7275 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -2305,16 +2455,23 @@ public: Specific scatter properties can be transferred between \ref QCPScatterStyle instances via \ref setFromOther. */ - enum ScatterProperty { spNone = 0x00 ///< 0x00 None - ,spPen = 0x01 ///< 0x01 The pen property, see \ref setPen - ,spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush - ,spSize = 0x04 ///< 0x04 The size property, see \ref setSize - ,spShape = 0x08 ///< 0x08 The shape property, see \ref setShape - ,spAll = 0xFF ///< 0xFF All properties - }; - Q_ENUMS(ScatterProperty) - Q_FLAGS(ScatterProperties) - Q_DECLARE_FLAGS(ScatterProperties, ScatterProperty) + enum ScatterProperty + { + spNone = 0x00 ///< 0x00 None + , + spPen = 0x01 ///< 0x01 The pen property, see \ref setPen + , + spBrush = 0x02 ///< 0x02 The brush property, see \ref setBrush + , + spSize = 0x04 ///< 0x04 The size property, see \ref setSize + , + spShape = 0x08 ///< 0x08 The shape property, see \ref setShape + , + spAll = 0xFF ///< 0xFF All properties + }; + Q_ENUMS( ScatterProperty ) + Q_FLAGS( ScatterProperties ) + Q_DECLARE_FLAGS( ScatterProperties, ScatterProperty ) /*! Defines the shape used for scatter points. @@ -2323,35 +2480,54 @@ public: \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are drawn with the pen and brush specified with \ref setPen and \ref setBrush. */ - enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) - ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) - ,ssCross ///< \enumimage{ssCross.png} a cross - ,ssPlus ///< \enumimage{ssPlus.png} a plus - ,ssCircle ///< \enumimage{ssCircle.png} a circle - ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) - ,ssSquare ///< \enumimage{ssSquare.png} a square - ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond - ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus - ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline - ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner - ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside - ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside - ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside - ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside - ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines - ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates - ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) - }; - Q_ENUMS(ScatterShape) + enum ScatterShape + { + ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines) + , + ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius) + , + ssCross ///< \enumimage{ssCross.png} a cross + , + ssPlus ///< \enumimage{ssPlus.png} a plus + , + ssCircle ///< \enumimage{ssCircle.png} a circle + , + ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle) + , + ssSquare ///< \enumimage{ssSquare.png} a square + , + ssDiamond ///< \enumimage{ssDiamond.png} a diamond + , + ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus + , + ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline + , + ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner + , + ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside + , + ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside + , + ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside + , + ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside + , + ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines + , + ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates + , + ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath) + }; + Q_ENUMS( ScatterShape ) QCPScatterStyle(); - QCPScatterStyle(ScatterShape shape, double size=6); - QCPScatterStyle(ScatterShape shape, const QColor &color, double size); - QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size); - QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size); - QCPScatterStyle(const QPixmap &pixmap); - QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6); - + QCPScatterStyle( ScatterShape shape, double size = 6 ); + QCPScatterStyle( ScatterShape shape, const QColor& color, double size ); + QCPScatterStyle( ScatterShape shape, const QColor& color, const QColor& fill, double size ); + QCPScatterStyle( ScatterShape shape, const QPen& pen, const QBrush& brush, double size ); + QCPScatterStyle( const QPixmap& pixmap ); + QCPScatterStyle( const QPainterPath& customPath, const QPen& pen, const QBrush& brush = Qt::NoBrush, double size = 6 ); + // getters: double size() const { return mSize; } ScatterShape shape() const { return mShape; } @@ -2361,21 +2537,21 @@ public: QPainterPath customPath() const { return mCustomPath; } // setters: - void setFromOther(const QCPScatterStyle &other, ScatterProperties properties); - void setSize(double size); - void setShape(ScatterShape shape); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setPixmap(const QPixmap &pixmap); - void setCustomPath(const QPainterPath &customPath); + void setFromOther( const QCPScatterStyle& other, ScatterProperties properties ); + void setSize( double size ); + void setShape( ScatterShape shape ); + void setPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setPixmap( const QPixmap& pixmap ); + void setCustomPath( const QPainterPath& customPath ); // non-property methods: bool isNone() const { return mShape == ssNone; } bool isPenDefined() const { return mPenDefined; } void undefinePen(); - void applyTo(QCPPainter *painter, const QPen &defaultPen) const; - void drawShape(QCPPainter *painter, const QPointF &pos) const; - void drawShape(QCPPainter *painter, double x, double y) const; + void applyTo( QCPPainter* painter, const QPen& defaultPen ) const; + void drawShape( QCPPainter* painter, const QPointF& pos ) const; + void drawShape( QCPPainter* painter, double x, double y ) const; protected: // property members: @@ -2385,18 +2561,17 @@ protected: QBrush mBrush; QPixmap mPixmap; QPainterPath mCustomPath; - + // non-property members: bool mPenDefined; }; -Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE); -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPScatterStyle::ScatterProperties) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterProperty) -Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) +Q_DECLARE_TYPEINFO( QCPScatterStyle, Q_MOVABLE_TYPE ); +Q_DECLARE_OPERATORS_FOR_FLAGS( QCPScatterStyle::ScatterProperties ) +Q_DECLARE_METATYPE( QCPScatterStyle::ScatterProperty ) +Q_DECLARE_METATYPE( QCPScatterStyle::ScatterShape ) /* end of 'src/scatterstyle.h' */ - /* including file 'src/datacontainer.h', size 4596 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -2406,62 +2581,65 @@ Q_DECLARE_METATYPE(QCPScatterStyle::ScatterShape) \see QCPDataContainer::sort */ template -inline bool qcpLessThanSortKey(const DataType &a, const DataType &b) { return a.sortKey() < b.sortKey(); } +inline bool qcpLessThanSortKey( const DataType& a, const DataType& b ) +{ + return a.sortKey() < b.sortKey(); +} template -class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) +class QCPDataContainer // no QCP_LIB_DECL, template class ends up in header (cpp included below) { public: typedef typename QVector::const_iterator const_iterator; typedef typename QVector::iterator iterator; - + QCPDataContainer(); - + // getters: - int size() const { return mData.size()-mPreallocSize; } + int size() const { return mData.size() - mPreallocSize; } bool isEmpty() const { return size() == 0; } bool autoSqueeze() const { return mAutoSqueeze; } - + // setters: - void setAutoSqueeze(bool enabled); - + void setAutoSqueeze( bool enabled ); + // non-virtual methods: - void set(const QCPDataContainer &data); - void set(const QVector &data, bool alreadySorted=false); - void add(const QCPDataContainer &data); - void add(const QVector &data, bool alreadySorted=false); - void add(const DataType &data); - void removeBefore(double sortKey); - void removeAfter(double sortKey); - void remove(double sortKeyFrom, double sortKeyTo); - void remove(double sortKey); + void set( const QCPDataContainer& data ); + void set( const QVector& data, bool alreadySorted = false ); + void add( const QCPDataContainer& data ); + void add( const QVector& data, bool alreadySorted = false ); + void add( const DataType& data ); + void removeBefore( double sortKey ); + void removeAfter( double sortKey ); + void remove( double sortKeyFrom, double sortKeyTo ); + void remove( double sortKey ); void clear(); void sort(); - void squeeze(bool preAllocation=true, bool postAllocation=true); - - const_iterator constBegin() const { return mData.constBegin()+mPreallocSize; } + void squeeze( bool preAllocation = true, bool postAllocation = true ); + + const_iterator constBegin() const { return mData.constBegin() + mPreallocSize; } const_iterator constEnd() const { return mData.constEnd(); } - iterator begin() { return mData.begin()+mPreallocSize; } + iterator begin() { return mData.begin() + mPreallocSize; } iterator end() { return mData.end(); } - const_iterator findBegin(double sortKey, bool expandedRange=true) const; - const_iterator findEnd(double sortKey, bool expandedRange=true) const; - const_iterator at(int index) const { return constBegin()+qBound(0, index, size()); } - QCPRange keyRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth); - QCPRange valueRange(bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()); - QCPDataRange dataRange() const { return QCPDataRange(0, size()); } - void limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const; - + const_iterator findBegin( double sortKey, bool expandedRange = true ) const; + const_iterator findEnd( double sortKey, bool expandedRange = true ) const; + const_iterator at( int index ) const { return constBegin() + qBound( 0, index, size() ); } + QCPRange keyRange( bool& foundRange, QCP::SignDomain signDomain = QCP::sdBoth ); + QCPRange valueRange( bool& foundRange, QCP::SignDomain signDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ); + QCPDataRange dataRange() const { return QCPDataRange( 0, size() ); } + void limitIteratorsToDataRange( const_iterator& begin, const_iterator& end, const QCPDataRange& dataRange ) const; + protected: // property members: bool mAutoSqueeze; - + // non-property memebers: QVector mData; int mPreallocSize; int mPreallocIteration; - + // non-virtual methods: - void preallocateGrow(int minimumPreallocSize); + void preallocateGrow( int minimumPreallocSize ); void performAutoSqueeze(); }; @@ -2604,10 +2782,8 @@ protected: data */ template -QCPDataContainer::QCPDataContainer() : - mAutoSqueeze(true), - mPreallocSize(0), - mPreallocIteration(0) +QCPDataContainer::QCPDataContainer() + : mAutoSqueeze( true ), mPreallocSize( 0 ), mPreallocIteration( 0 ) { } @@ -2620,12 +2796,12 @@ QCPDataContainer::QCPDataContainer() : \ref squeeze. */ template -void QCPDataContainer::setAutoSqueeze(bool enabled) +void QCPDataContainer::setAutoSqueeze( bool enabled ) { - if (mAutoSqueeze != enabled) + if( mAutoSqueeze != enabled ) { mAutoSqueeze = enabled; - if (mAutoSqueeze) + if( mAutoSqueeze ) performAutoSqueeze(); } } @@ -2637,10 +2813,10 @@ void QCPDataContainer::setAutoSqueeze(bool enabled) \see add, remove */ template -void QCPDataContainer::set(const QCPDataContainer &data) +void QCPDataContainer::set( const QCPDataContainer& data ) { clear(); - add(data); + add( data ); } /*! \overload @@ -2653,12 +2829,12 @@ void QCPDataContainer::set(const QCPDataContainer &data) \see add, remove */ template -void QCPDataContainer::set(const QVector &data, bool alreadySorted) +void QCPDataContainer::set( const QVector& data, bool alreadySorted ) { mData = data; mPreallocSize = 0; mPreallocIteration = 0; - if (!alreadySorted) + if( !alreadySorted ) sort(); } @@ -2669,26 +2845,27 @@ void QCPDataContainer::set(const QVector &data, bool already \see set, remove */ template -void QCPDataContainer::add(const QCPDataContainer &data) +void QCPDataContainer::add( const QCPDataContainer& data ) { - if (data.isEmpty()) + if( data.isEmpty() ) return; - + const int n = data.size(); const int oldSize = size(); - - if (oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones + + if( oldSize > 0 && !qcpLessThanSortKey( *constBegin(), *( data.constEnd() - 1 ) ) ) // prepend if new data keys are all smaller than or equal to existing ones { - if (mPreallocSize < n) - preallocateGrow(n); + if( mPreallocSize < n ) + preallocateGrow( n ); mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and merge if necessary + std::copy( data.constBegin(), data.constEnd(), begin() ); + } + else // don't need to prepend, so append and merge if necessary { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + mData.resize( mData.size() + n ); + std::copy( data.constBegin(), data.constEnd(), end() - n ); + if( oldSize > 0 && !qcpLessThanSortKey( *( constEnd() - n - 1 ), *( constEnd() - n ) ) ) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge( begin(), end() - n, end(), qcpLessThanSortKey ); } } @@ -2701,33 +2878,34 @@ void QCPDataContainer::add(const QCPDataContainer &data) \see set, remove */ template -void QCPDataContainer::add(const QVector &data, bool alreadySorted) +void QCPDataContainer::add( const QVector& data, bool alreadySorted ) { - if (data.isEmpty()) + if( data.isEmpty() ) return; - if (isEmpty()) + if( isEmpty() ) { - set(data, alreadySorted); + set( data, alreadySorted ); return; } - + const int n = data.size(); const int oldSize = size(); - - if (alreadySorted && oldSize > 0 && !qcpLessThanSortKey(*constBegin(), *(data.constEnd()-1))) // prepend if new data is sorted and keys are all smaller than or equal to existing ones + + if( alreadySorted && oldSize > 0 && !qcpLessThanSortKey( *constBegin(), *( data.constEnd() - 1 ) ) ) // prepend if new data is sorted and keys are all smaller than or equal to existing ones { - if (mPreallocSize < n) - preallocateGrow(n); + if( mPreallocSize < n ) + preallocateGrow( n ); mPreallocSize -= n; - std::copy(data.constBegin(), data.constEnd(), begin()); - } else // don't need to prepend, so append and then sort and merge if necessary + std::copy( data.constBegin(), data.constEnd(), begin() ); + } + else // don't need to prepend, so append and then sort and merge if necessary { - mData.resize(mData.size()+n); - std::copy(data.constBegin(), data.constEnd(), end()-n); - if (!alreadySorted) // sort appended subrange if it wasn't already sorted - std::sort(end()-n, end(), qcpLessThanSortKey); - if (oldSize > 0 && !qcpLessThanSortKey(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions - std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey); + mData.resize( mData.size() + n ); + std::copy( data.constBegin(), data.constEnd(), end() - n ); + if( !alreadySorted ) // sort appended subrange if it wasn't already sorted + std::sort( end() - n, end(), qcpLessThanSortKey ); + if( oldSize > 0 && !qcpLessThanSortKey( *( constEnd() - n - 1 ), *( constEnd() - n ) ) ) // if appended range keys aren't all greater than existing ones, merge the two partitions + std::inplace_merge( begin(), end() - n, end(), qcpLessThanSortKey ); } } @@ -2738,21 +2916,23 @@ void QCPDataContainer::add(const QVector &data, bool already \see remove */ template -void QCPDataContainer::add(const DataType &data) +void QCPDataContainer::add( const DataType& data ) { - if (isEmpty() || !qcpLessThanSortKey(data, *(constEnd()-1))) // quickly handle appends if new data key is greater or equal to existing ones + if( isEmpty() || !qcpLessThanSortKey( data, *( constEnd() - 1 ) ) ) // quickly handle appends if new data key is greater or equal to existing ones { - mData.append(data); - } else if (qcpLessThanSortKey(data, *constBegin())) // quickly handle prepends using preallocated space + mData.append( data ); + } + else if( qcpLessThanSortKey( data, *constBegin() ) ) // quickly handle prepends using preallocated space { - if (mPreallocSize < 1) - preallocateGrow(1); + if( mPreallocSize < 1 ) + preallocateGrow( 1 ); --mPreallocSize; *begin() = data; - } else // handle inserts, maintaining sorted keys + } + else // handle inserts, maintaining sorted keys { - QCPDataContainer::iterator insertionPoint = std::lower_bound(begin(), end(), data, qcpLessThanSortKey); - mData.insert(insertionPoint, data); + QCPDataContainer::iterator insertionPoint = std::lower_bound( begin(), end(), data, qcpLessThanSortKey ); + mData.insert( insertionPoint, data ); } } @@ -2762,12 +2942,12 @@ void QCPDataContainer::add(const DataType &data) \see removeAfter, remove, clear */ template -void QCPDataContainer::removeBefore(double sortKey) +void QCPDataContainer::removeBefore( double sortKey ) { QCPDataContainer::iterator it = begin(); - QCPDataContainer::iterator itEnd = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - mPreallocSize += itEnd-it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) - if (mAutoSqueeze) + QCPDataContainer::iterator itEnd = std::lower_bound( begin(), end(), DataType::fromSortKey( sortKey ), qcpLessThanSortKey ); + mPreallocSize += itEnd - it; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + if( mAutoSqueeze ) performAutoSqueeze(); } @@ -2777,12 +2957,12 @@ void QCPDataContainer::removeBefore(double sortKey) \see removeBefore, remove, clear */ template -void QCPDataContainer::removeAfter(double sortKey) +void QCPDataContainer::removeAfter( double sortKey ) { - QCPDataContainer::iterator it = std::upper_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); + QCPDataContainer::iterator it = std::upper_bound( begin(), end(), DataType::fromSortKey( sortKey ), qcpLessThanSortKey ); QCPDataContainer::iterator itEnd = end(); - mData.erase(it, itEnd); // typically adds it to the postallocated block - if (mAutoSqueeze) + mData.erase( it, itEnd ); // typically adds it to the postallocated block + if( mAutoSqueeze ) performAutoSqueeze(); } @@ -2794,15 +2974,15 @@ void QCPDataContainer::removeAfter(double sortKey) \see removeBefore, removeAfter, clear */ template -void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) +void QCPDataContainer::remove( double sortKeyFrom, double sortKeyTo ) { - if (sortKeyFrom >= sortKeyTo || isEmpty()) + if( sortKeyFrom >= sortKeyTo || isEmpty() ) return; - - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKeyFrom), qcpLessThanSortKey); - QCPDataContainer::iterator itEnd = std::upper_bound(it, end(), DataType::fromSortKey(sortKeyTo), qcpLessThanSortKey); - mData.erase(it, itEnd); - if (mAutoSqueeze) + + QCPDataContainer::iterator it = std::lower_bound( begin(), end(), DataType::fromSortKey( sortKeyFrom ), qcpLessThanSortKey ); + QCPDataContainer::iterator itEnd = std::upper_bound( it, end(), DataType::fromSortKey( sortKeyTo ), qcpLessThanSortKey ); + mData.erase( it, itEnd ); + if( mAutoSqueeze ) performAutoSqueeze(); } @@ -2816,17 +2996,17 @@ void QCPDataContainer::remove(double sortKeyFrom, double sortKeyTo) \see removeBefore, removeAfter, clear */ template -void QCPDataContainer::remove(double sortKey) +void QCPDataContainer::remove( double sortKey ) { - QCPDataContainer::iterator it = std::lower_bound(begin(), end(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (it != end() && it->sortKey() == sortKey) + QCPDataContainer::iterator it = std::lower_bound( begin(), end(), DataType::fromSortKey( sortKey ), qcpLessThanSortKey ); + if( it != end() && it->sortKey() == sortKey ) { - if (it == begin()) - ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) + if( it == begin() ) + ++mPreallocSize; // don't actually delete, just add it to the preallocated block (if it gets too large, squeeze will take care of it) else - mData.erase(it); + mData.erase( it ); } - if (mAutoSqueeze) + if( mAutoSqueeze ) performAutoSqueeze(); } @@ -2857,7 +3037,7 @@ void QCPDataContainer::clear() template void QCPDataContainer::sort() { - std::sort(begin(), end(), qcpLessThanSortKey); + std::sort( begin(), end(), qcpLessThanSortKey ); } /*! @@ -2871,19 +3051,19 @@ void QCPDataContainer::sort() should be freed, respectively. */ template -void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation) +void QCPDataContainer::squeeze( bool preAllocation, bool postAllocation ) { - if (preAllocation) + if( preAllocation ) { - if (mPreallocSize > 0) + if( mPreallocSize > 0 ) { - std::copy(begin(), end(), mData.begin()); - mData.resize(size()); + std::copy( begin(), end(), mData.begin() ); + mData.resize( size() ); mPreallocSize = 0; } mPreallocIteration = 0; } - if (postAllocation) + if( postAllocation ) mData.squeeze(); } @@ -2903,13 +3083,13 @@ void QCPDataContainer::squeeze(bool preAllocation, bool postAllocation \see findEnd, QCPPlottableInterface1D::findBegin */ template -typename QCPDataContainer::const_iterator QCPDataContainer::findBegin(double sortKey, bool expandedRange) const +typename QCPDataContainer::const_iterator QCPDataContainer::findBegin( double sortKey, bool expandedRange ) const { - if (isEmpty()) + if( isEmpty() ) return constEnd(); - - QCPDataContainer::const_iterator it = std::lower_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constBegin()) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty + + QCPDataContainer::const_iterator it = std::lower_bound( constBegin(), constEnd(), DataType::fromSortKey( sortKey ), qcpLessThanSortKey ); + if( expandedRange && it != constBegin() ) // also covers it == constEnd case, and we know --constEnd is valid because mData isn't empty --it; return it; } @@ -2930,13 +3110,13 @@ typename QCPDataContainer::const_iterator QCPDataContainer:: \see findBegin, QCPPlottableInterface1D::findEnd */ template -typename QCPDataContainer::const_iterator QCPDataContainer::findEnd(double sortKey, bool expandedRange) const +typename QCPDataContainer::const_iterator QCPDataContainer::findEnd( double sortKey, bool expandedRange ) const { - if (isEmpty()) + if( isEmpty() ) return constEnd(); - - QCPDataContainer::const_iterator it = std::upper_bound(constBegin(), constEnd(), DataType::fromSortKey(sortKey), qcpLessThanSortKey); - if (expandedRange && it != constEnd()) + + QCPDataContainer::const_iterator it = std::upper_bound( constBegin(), constEnd(), DataType::fromSortKey( sortKey ), qcpLessThanSortKey ); + if( expandedRange && it != constEnd() ) ++it; return it; } @@ -2957,9 +3137,9 @@ typename QCPDataContainer::const_iterator QCPDataContainer:: \see valueRange */ template -QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain signDomain) +QCPRange QCPDataContainer::keyRange( bool& foundRange, QCP::SignDomain signDomain ) { - if (isEmpty()) + if( isEmpty() ) { foundRange = false; return QCPRange(); @@ -2968,16 +3148,16 @@ QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain bool haveLower = false; bool haveUpper = false; double current; - + QCPDataContainer::const_iterator it = constBegin(); QCPDataContainer::const_iterator itEnd = constEnd(); - if (signDomain == QCP::sdBoth) // range may be anywhere + if( signDomain == QCP::sdBoth ) // range may be anywhere { - if (DataType::sortKeyIsMainKey()) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value + if( DataType::sortKeyIsMainKey() ) // if DataType is sorted by main key (e.g. QCPGraph, but not QCPCurve), use faster algorithm by finding just first and last key with non-NaN value { - while (it != itEnd) // find first non-nan going up from left + while( it != itEnd ) // find first non-nan going up from left { - if (!qIsNaN(it->mainValue())) + if( !qIsNaN( it->mainValue() ) ) { range.lower = it->mainKey(); haveLower = true; @@ -2986,29 +3166,30 @@ QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain ++it; } it = itEnd; - while (it != constBegin()) // find first non-nan going down from right + while( it != constBegin() ) // find first non-nan going down from right { --it; - if (!qIsNaN(it->mainValue())) + if( !qIsNaN( it->mainValue() ) ) { range.upper = it->mainKey(); haveUpper = true; break; } } - } else // DataType is not sorted by main key, go through all data points and accordingly expand range + } + else // DataType is not sorted by main key, go through all data points and accordingly expand range { - while (it != itEnd) + while( it != itEnd ) { - if (!qIsNaN(it->mainValue())) + if( !qIsNaN( it->mainValue() ) ) { current = it->mainKey(); - if (current < range.lower || !haveLower) + if( current < range.lower || !haveLower ) { range.lower = current; haveLower = true; } - if (current > range.upper || !haveUpper) + if( current > range.upper || !haveUpper ) { range.upper = current; haveUpper = true; @@ -3017,39 +3198,20 @@ QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain ++it; } } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain + } + else if( signDomain == QCP::sdNegative ) // range may only be in the negative sign domain { - while (it != itEnd) + while( it != itEnd ) { - if (!qIsNaN(it->mainValue())) + if( !qIsNaN( it->mainValue() ) ) { current = it->mainKey(); - if ((current < range.lower || !haveLower) && current < 0) + if( ( current < range.lower || !haveLower ) && current < 0 ) { range.lower = current; haveLower = true; } - if ((current > range.upper || !haveUpper) && current < 0) - { - range.upper = current; - haveUpper = true; - } - } - ++it; - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - while (it != itEnd) - { - if (!qIsNaN(it->mainValue())) - { - current = it->mainKey(); - if ((current < range.lower || !haveLower) && current > 0) - { - range.lower = current; - haveLower = true; - } - if ((current > range.upper || !haveUpper) && current > 0) + if( ( current > range.upper || !haveUpper ) && current < 0 ) { range.upper = current; haveUpper = true; @@ -3058,7 +3220,28 @@ QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain ++it; } } - + else if( signDomain == QCP::sdPositive ) // range may only be in the positive sign domain + { + while( it != itEnd ) + { + if( !qIsNaN( it->mainValue() ) ) + { + current = it->mainKey(); + if( ( current < range.lower || !haveLower ) && current > 0 ) + { + range.lower = current; + haveLower = true; + } + if( ( current > range.upper || !haveUpper ) && current > 0 ) + { + range.upper = current; + haveUpper = true; + } + } + ++it; + } + } + foundRange = haveLower && haveUpper; return range; } @@ -3080,9 +3263,9 @@ QCPRange QCPDataContainer::keyRange(bool &foundRange, QCP::SignDomain \see keyRange */ template -QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomain signDomain, const QCPRange &inKeyRange) +QCPRange QCPDataContainer::valueRange( bool& foundRange, QCP::SignDomain signDomain, const QCPRange& inKeyRange ) { - if (isEmpty()) + if( isEmpty() ) { foundRange = false; return QCPRange(); @@ -3094,67 +3277,69 @@ QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomai QCPRange current; QCPDataContainer::const_iterator itBegin = constBegin(); QCPDataContainer::const_iterator itEnd = constEnd(); - if (DataType::sortKeyIsMainKey() && restrictKeyRange) + if( DataType::sortKeyIsMainKey() && restrictKeyRange ) { - itBegin = findBegin(inKeyRange.lower); - itEnd = findEnd(inKeyRange.upper); + itBegin = findBegin( inKeyRange.lower ); + itEnd = findEnd( inKeyRange.upper ); } - if (signDomain == QCP::sdBoth) // range may be anywhere + if( signDomain == QCP::sdBoth ) // range may be anywhere { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) + for( QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it ) { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) + if( restrictKeyRange && ( it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper ) ) continue; current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && !qIsNaN(current.lower)) + if( ( current.lower < range.lower || !haveLower ) && !qIsNaN( current.lower ) ) { range.lower = current.lower; haveLower = true; } - if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdNegative) // range may only be in the negative sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower < 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper)) - { - range.upper = current.upper; - haveUpper = true; - } - } - } else if (signDomain == QCP::sdPositive) // range may only be in the positive sign domain - { - for (QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it) - { - if (restrictKeyRange && (it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper)) - continue; - current = it->valueRange(); - if ((current.lower < range.lower || !haveLower) && current.lower > 0 && !qIsNaN(current.lower)) - { - range.lower = current.lower; - haveLower = true; - } - if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper)) + if( ( current.upper > range.upper || !haveUpper ) && !qIsNaN( current.upper ) ) { range.upper = current.upper; haveUpper = true; } } } - + else if( signDomain == QCP::sdNegative ) // range may only be in the negative sign domain + { + for( QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it ) + { + if( restrictKeyRange && ( it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper ) ) + continue; + current = it->valueRange(); + if( ( current.lower < range.lower || !haveLower ) && current.lower < 0 && !qIsNaN( current.lower ) ) + { + range.lower = current.lower; + haveLower = true; + } + if( ( current.upper > range.upper || !haveUpper ) && current.upper < 0 && !qIsNaN( current.upper ) ) + { + range.upper = current.upper; + haveUpper = true; + } + } + } + else if( signDomain == QCP::sdPositive ) // range may only be in the positive sign domain + { + for( QCPDataContainer::const_iterator it = itBegin; it != itEnd; ++it ) + { + if( restrictKeyRange && ( it->mainKey() < inKeyRange.lower || it->mainKey() > inKeyRange.upper ) ) + continue; + current = it->valueRange(); + if( ( current.lower < range.lower || !haveLower ) && current.lower > 0 && !qIsNaN( current.lower ) ) + { + range.lower = current.lower; + haveLower = true; + } + if( ( current.upper > range.upper || !haveUpper ) && current.upper > 0 && !qIsNaN( current.upper ) ) + { + range.upper = current.upper; + haveUpper = true; + } + } + } + foundRange = haveLower && haveUpper; return range; } @@ -3168,12 +3353,12 @@ QCPRange QCPDataContainer::valueRange(bool &foundRange, QCP::SignDomai valid range. */ template -void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const +void QCPDataContainer::limitIteratorsToDataRange( const_iterator& begin, const_iterator& end, const QCPDataRange& dataRange ) const { - QCPDataRange iteratorRange(begin-constBegin(), end-constBegin()); - iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); - begin = constBegin()+iteratorRange.begin(); - end = constBegin()+iteratorRange.end(); + QCPDataRange iteratorRange( begin - constBegin(), end - constBegin() ); + iteratorRange = iteratorRange.bounded( dataRange.bounded( this->dataRange() ) ); + begin = constBegin() + iteratorRange.begin(); + end = constBegin() + iteratorRange.end(); } /*! \internal @@ -3186,18 +3371,18 @@ void QCPDataContainer::limitIteratorsToDataRange(const_iterator &begin method does nothing. */ template -void QCPDataContainer::preallocateGrow(int minimumPreallocSize) +void QCPDataContainer::preallocateGrow( int minimumPreallocSize ) { - if (minimumPreallocSize <= mPreallocSize) + if( minimumPreallocSize <= mPreallocSize ) return; - + int newPreallocSize = minimumPreallocSize; - newPreallocSize += (1u< void QCPDataContainer::performAutoSqueeze() { const int totalAlloc = mData.capacity(); - const int postAllocSize = totalAlloc-mData.size(); + const int postAllocSize = totalAlloc - mData.size(); const int usedSize = size(); bool shrinkPostAllocation = false; bool shrinkPreAllocation = false; - if (totalAlloc > 650000) // if allocation is larger, shrink earlier with respect to total used size + if( totalAlloc > 650000 ) // if allocation is larger, shrink earlier with respect to total used size { - shrinkPostAllocation = postAllocSize > usedSize*1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! - shrinkPreAllocation = mPreallocSize*10 > usedSize; - } else if (totalAlloc > 1000) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother - { - shrinkPostAllocation = postAllocSize > usedSize*5; - shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller + shrinkPostAllocation = postAllocSize > usedSize * 1.5; // QVector grow strategy is 2^n for static data. Watch out not to oscillate! + shrinkPreAllocation = mPreallocSize * 10 > usedSize; } - - if (shrinkPreAllocation || shrinkPostAllocation) - squeeze(shrinkPreAllocation, shrinkPostAllocation); + else if( totalAlloc > 1000 ) // below 10 MiB raw data be generous with preallocated memory, below 1k points don't even bother + { + shrinkPostAllocation = postAllocSize > usedSize * 5; + shrinkPreAllocation = mPreallocSize > usedSize * 1.5; // preallocation can grow into postallocation, so can be smaller + } + + if( shrinkPreAllocation || shrinkPostAllocation ) + squeeze( shrinkPreAllocation, shrinkPostAllocation ); } /* end of 'src/datacontainer.cpp' */ - /* end of 'src/datacontainer.h' */ - /* including file 'src/plottable.h', size 8433 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -3251,28 +3435,28 @@ class QCP_LIB_DECL QCPSelectionDecorator public: QCPSelectionDecorator(); virtual ~QCPSelectionDecorator(); - + // getters: QPen pen() const { return mPen; } QBrush brush() const { return mBrush; } QCPScatterStyle scatterStyle() const { return mScatterStyle; } QCPScatterStyle::ScatterProperties usedScatterProperties() const { return mUsedScatterProperties; } - + // setters: - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setScatterStyle(const QCPScatterStyle &scatterStyle, QCPScatterStyle::ScatterProperties usedProperties=QCPScatterStyle::spPen); - void setUsedScatterProperties(const QCPScatterStyle::ScatterProperties &properties); - + void setPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setScatterStyle( const QCPScatterStyle& scatterStyle, QCPScatterStyle::ScatterProperties usedProperties = QCPScatterStyle::spPen ); + void setUsedScatterProperties( const QCPScatterStyle::ScatterProperties& properties ); + // non-virtual methods: - void applyPen(QCPPainter *painter) const; - void applyBrush(QCPPainter *painter) const; - QCPScatterStyle getFinalScatterStyle(const QCPScatterStyle &unselectedStyle) const; - + void applyPen( QCPPainter* painter ) const; + void applyBrush( QCPPainter* painter ) const; + QCPScatterStyle getFinalScatterStyle( const QCPScatterStyle& unselectedStyle ) const; + // introduced virtual methods: - virtual void copyFrom(const QCPSelectionDecorator *other); - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection); - + virtual void copyFrom( const QCPSelectionDecorator* other ); + virtual void drawDecoration( QCPPainter* painter, QCPDataSelection selection ); + protected: // property members: QPen mPen; @@ -3280,86 +3464,85 @@ protected: QCPScatterStyle mScatterStyle; QCPScatterStyle::ScatterProperties mUsedScatterProperties; // non-property members: - QCPAbstractPlottable *mPlottable; - + QCPAbstractPlottable* mPlottable; + // introduced virtual methods: - virtual bool registerWithPlottable(QCPAbstractPlottable *plottable); - + virtual bool registerWithPlottable( QCPAbstractPlottable* plottable ); + private: - Q_DISABLE_COPY(QCPSelectionDecorator) + Q_DISABLE_COPY( QCPSelectionDecorator ) friend class QCPAbstractPlottable; }; -Q_DECLARE_METATYPE(QCPSelectionDecorator*) - +Q_DECLARE_METATYPE( QCPSelectionDecorator* ) class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill) - Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis) - Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis) - Q_PROPERTY(QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged) - Q_PROPERTY(QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator) + Q_PROPERTY( QString name READ name WRITE setName ) + Q_PROPERTY( bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill ) + Q_PROPERTY( bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters ) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis ) + Q_PROPERTY( QCPAxis* valueAxis READ valueAxis WRITE setValueAxis ) + Q_PROPERTY( QCP::SelectionType selectable READ selectable WRITE setSelectable NOTIFY selectableChanged ) + Q_PROPERTY( QCPDataSelection selection READ selection WRITE setSelection NOTIFY selectionChanged ) + Q_PROPERTY( QCPSelectionDecorator* selectionDecorator READ selectionDecorator WRITE setSelectionDecorator ) /// \endcond public: - QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis); + QCPAbstractPlottable( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPAbstractPlottable(); - + // getters: QString name() const { return mName; } bool antialiasedFill() const { return mAntialiasedFill; } bool antialiasedScatters() const { return mAntialiasedScatters; } QPen pen() const { return mPen; } QBrush brush() const { return mBrush; } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } + QCPAxis* keyAxis() const { return mKeyAxis.data(); } + QCPAxis* valueAxis() const { return mValueAxis.data(); } QCP::SelectionType selectable() const { return mSelectable; } bool selected() const { return !mSelection.isEmpty(); } QCPDataSelection selection() const { return mSelection; } - QCPSelectionDecorator *selectionDecorator() const { return mSelectionDecorator; } - + QCPSelectionDecorator* selectionDecorator() const { return mSelectionDecorator; } + // setters: - void setName(const QString &name); - void setAntialiasedFill(bool enabled); - void setAntialiasedScatters(bool enabled); - void setPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setKeyAxis(QCPAxis *axis); - void setValueAxis(QCPAxis *axis); - Q_SLOT void setSelectable(QCP::SelectionType selectable); - Q_SLOT void setSelection(QCPDataSelection selection); - void setSelectionDecorator(QCPSelectionDecorator *decorator); + void setName( const QString& name ); + void setAntialiasedFill( bool enabled ); + void setAntialiasedScatters( bool enabled ); + void setPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setKeyAxis( QCPAxis* axis ); + void setValueAxis( QCPAxis* axis ); + Q_SLOT void setSelectable( QCP::SelectionType selectable ); + Q_SLOT void setSelection( QCPDataSelection selection ); + void setSelectionDecorator( QCPSelectionDecorator* decorator ); // introduced virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables - virtual QCPPlottableInterface1D *interface1D() { return 0; } - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const = 0; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const = 0; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE = 0; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables + virtual QCPPlottableInterface1D* interface1D() { return 0; } + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const = 0; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const = 0; + // non-property methods: - void coordsToPixels(double key, double value, double &x, double &y) const; - const QPointF coordsToPixels(double key, double value) const; - void pixelsToCoords(double x, double y, double &key, double &value) const; - void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const; - void rescaleAxes(bool onlyEnlarge=false) const; - void rescaleKeyAxis(bool onlyEnlarge=false) const; - void rescaleValueAxis(bool onlyEnlarge=false, bool inKeyRange=false) const; - bool addToLegend(QCPLegend *legend); + void coordsToPixels( double key, double value, double& x, double& y ) const; + const QPointF coordsToPixels( double key, double value ) const; + void pixelsToCoords( double x, double y, double& key, double& value ) const; + void pixelsToCoords( const QPointF& pixelPos, double& key, double& value ) const; + void rescaleAxes( bool onlyEnlarge = false ) const; + void rescaleKeyAxis( bool onlyEnlarge = false ) const; + void rescaleValueAxis( bool onlyEnlarge = false, bool inKeyRange = false ) const; + bool addToLegend( QCPLegend* legend ); bool addToLegend(); - bool removeFromLegend(QCPLegend *legend) const; + bool removeFromLegend( QCPLegend* legend ) const; bool removeFromLegend() const; - + signals: - void selectionChanged(bool selected); - void selectionChanged(const QCPDataSelection &selection); - void selectableChanged(QCP::SelectionType selectable); - + void selectionChanged( bool selected ); + void selectionChanged( const QCPDataSelection& selection ); + void selectableChanged( QCP::SelectionType selectable ); + protected: // property members: QString mName; @@ -3369,36 +3552,34 @@ protected: QPointer mKeyAxis, mValueAxis; QCP::SelectionType mSelectable; QCPDataSelection mSelection; - QCPSelectionDecorator *mSelectionDecorator; - + QCPSelectionDecorator* mSelectionDecorator; + // reimplemented virtual methods: virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE = 0; virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0; - + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const = 0; + // non-virtual methods: - void applyFillAntialiasingHint(QCPPainter *painter) const; - void applyScattersAntialiasingHint(QCPPainter *painter) const; + void applyFillAntialiasingHint( QCPPainter* painter ) const; + void applyScattersAntialiasingHint( QCPPainter* painter ) const; private: - Q_DISABLE_COPY(QCPAbstractPlottable) - + Q_DISABLE_COPY( QCPAbstractPlottable ) + friend class QCustomPlot; friend class QCPAxis; friend class QCPPlottableLegendItem; }; - /* end of 'src/plottable.h' */ - /* including file 'src/item.h', size 9384 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -3406,40 +3587,38 @@ class QCP_LIB_DECL QCPItemAnchor { Q_GADGET public: - QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name, int anchorId=-1); + QCPItemAnchor( QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString& name, int anchorId = -1 ); virtual ~QCPItemAnchor(); - + // getters: QString name() const { return mName; } virtual QPointF pixelPosition() const; - + protected: // property members: QString mName; - + // non-property members: - QCustomPlot *mParentPlot; - QCPAbstractItem *mParentItem; + QCustomPlot* mParentPlot; + QCPAbstractItem* mParentItem; int mAnchorId; QSet mChildrenX, mChildrenY; - + // introduced virtual methods: - virtual QCPItemPosition *toQCPItemPosition() { return 0; } - + virtual QCPItemPosition* toQCPItemPosition() { return 0; } + // non-virtual methods: - void addChildX(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildX(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - void addChildY(QCPItemPosition* pos); // called from pos when this anchor is set as parent - void removeChildY(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted - + void addChildX( QCPItemPosition* pos ); // called from pos when this anchor is set as parent + void removeChildX( QCPItemPosition* pos ); // called from pos when its parent anchor is reset or pos deleted + void addChildY( QCPItemPosition* pos ); // called from pos when this anchor is set as parent + void removeChildY( QCPItemPosition* pos ); // called from pos when its parent anchor is reset or pos deleted + private: - Q_DISABLE_COPY(QCPItemAnchor) - + Q_DISABLE_COPY( QCPItemAnchor ) + friend class QCPItemPosition; }; - - class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor { Q_GADGET @@ -3450,48 +3629,53 @@ public: \see setType */ - enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. - ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the viewport/widget, etc. - ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top - ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and - ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. - ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). - }; - Q_ENUMS(PositionType) - - QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name); + enum PositionType + { + ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget. + , + ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the viewport/widget, etc. + , + ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top + ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and + ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1. + , + ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes). + }; + Q_ENUMS( PositionType ) + + QCPItemPosition( QCustomPlot* parentPlot, QCPAbstractItem* parentItem, const QString& name ); virtual ~QCPItemPosition(); - + // getters: PositionType type() const { return typeX(); } PositionType typeX() const { return mPositionTypeX; } PositionType typeY() const { return mPositionTypeY; } - QCPItemAnchor *parentAnchor() const { return parentAnchorX(); } - QCPItemAnchor *parentAnchorX() const { return mParentAnchorX; } - QCPItemAnchor *parentAnchorY() const { return mParentAnchorY; } + QCPItemAnchor* parentAnchor() const { return parentAnchorX(); } + QCPItemAnchor* parentAnchorX() const { return mParentAnchorX; } + QCPItemAnchor* parentAnchorY() const { return mParentAnchorY; } double key() const { return mKey; } double value() const { return mValue; } - QPointF coords() const { return QPointF(mKey, mValue); } - QCPAxis *keyAxis() const { return mKeyAxis.data(); } - QCPAxis *valueAxis() const { return mValueAxis.data(); } - QCPAxisRect *axisRect() const; + QPointF coords() const { return QPointF( mKey, mValue ); } + QCPAxis* keyAxis() const { return mKeyAxis.data(); } + QCPAxis* valueAxis() const { return mValueAxis.data(); } + QCPAxisRect* axisRect() const; virtual QPointF pixelPosition() const Q_DECL_OVERRIDE; - + // setters: - void setType(PositionType type); - void setTypeX(PositionType type); - void setTypeY(PositionType type); - bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorX(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - bool setParentAnchorY(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false); - void setCoords(double key, double value); - void setCoords(const QPointF &coords); - void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); - void setAxisRect(QCPAxisRect *axisRect); - void setPixelPosition(const QPointF &pixelPosition); - + void setType( PositionType type ); + void setTypeX( PositionType type ); + void setTypeY( PositionType type ); + bool setParentAnchor( QCPItemAnchor* parentAnchor, bool keepPixelPosition = false ); + bool setParentAnchorX( QCPItemAnchor* parentAnchor, bool keepPixelPosition = false ); + bool setParentAnchorY( QCPItemAnchor* parentAnchor, bool keepPixelPosition = false ); + void setCoords( double key, double value ); + void setCoords( const QPointF& coords ); + void setAxes( QCPAxis* keyAxis, QCPAxis* valueAxis ); + void setAxisRect( QCPAxisRect* axisRect ); + void setPixelPosition( const QPointF& pixelPosition ); + protected: // property members: PositionType mPositionTypeX, mPositionTypeY; @@ -3499,56 +3683,54 @@ protected: QPointer mAxisRect; double mKey, mValue; QCPItemAnchor *mParentAnchorX, *mParentAnchorY; - - // reimplemented virtual methods: - virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } - -private: - Q_DISABLE_COPY(QCPItemPosition) - -}; -Q_DECLARE_METATYPE(QCPItemPosition::PositionType) + // reimplemented virtual methods: + virtual QCPItemPosition* toQCPItemPosition() Q_DECL_OVERRIDE { return this; } + +private: + Q_DISABLE_COPY( QCPItemPosition ) +}; +Q_DECLARE_METATYPE( QCPItemPosition::PositionType ) class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect) - Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + Q_PROPERTY( bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect ) + Q_PROPERTY( QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect ) + Q_PROPERTY( bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged ) + Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectionChanged ) /// \endcond public: - explicit QCPAbstractItem(QCustomPlot *parentPlot); + explicit QCPAbstractItem( QCustomPlot* parentPlot ); virtual ~QCPAbstractItem(); - + // getters: bool clipToAxisRect() const { return mClipToAxisRect; } - QCPAxisRect *clipAxisRect() const; + QCPAxisRect* clipAxisRect() const; bool selectable() const { return mSelectable; } bool selected() const { return mSelected; } - + // setters: - void setClipToAxisRect(bool clip); - void setClipAxisRect(QCPAxisRect *rect); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - + void setClipToAxisRect( bool clip ); + void setClipAxisRect( QCPAxisRect* rect ); + Q_SLOT void setSelectable( bool selectable ); + Q_SLOT void setSelected( bool selected ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE = 0; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE = 0; + // non-virtual methods: QList positions() const { return mPositions; } QList anchors() const { return mAnchors; } - QCPItemPosition *position(const QString &name) const; - QCPItemAnchor *anchor(const QString &name) const; - bool hasAnchor(const QString &name) const; - + QCPItemPosition* position( const QString& name ) const; + QCPItemAnchor* anchor( const QString& name ) const; + bool hasAnchor( const QString& name ) const; + signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - + void selectionChanged( bool selected ); + void selectableChanged( bool selectable ); + protected: // property members: bool mClipToAxisRect; @@ -3556,34 +3738,33 @@ protected: QList mPositions; QList mAnchors; bool mSelectable, mSelected; - + // reimplemented virtual methods: virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE = 0; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual QPointF anchorPixelPosition(int anchorId) const; - + virtual QPointF anchorPixelPosition( int anchorId ) const; + // non-virtual methods: - double rectDistance(const QRectF &rect, const QPointF &pos, bool filledRect) const; - QCPItemPosition *createPosition(const QString &name); - QCPItemAnchor *createAnchor(const QString &name, int anchorId); - + double rectDistance( const QRectF& rect, const QPointF& pos, bool filledRect ) const; + QCPItemPosition* createPosition( const QString& name ); + QCPItemAnchor* createAnchor( const QString& name, int anchorId ); + private: - Q_DISABLE_COPY(QCPAbstractItem) - + Q_DISABLE_COPY( QCPAbstractItem ) + friend class QCustomPlot; friend class QCPItemAnchor; }; /* end of 'src/item.h' */ - /* including file 'src/core.h', size 14886 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -3591,16 +3772,16 @@ class QCP_LIB_DECL QCustomPlot : public QWidget { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QRect viewport READ viewport WRITE setViewport) - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout) - Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend) - Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance) - Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag) - Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier) - Q_PROPERTY(bool openGl READ openGl WRITE setOpenGl) + Q_PROPERTY( QRect viewport READ viewport WRITE setViewport ) + Q_PROPERTY( QPixmap background READ background WRITE setBackground ) + Q_PROPERTY( bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled ) + Q_PROPERTY( Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode ) + Q_PROPERTY( QCPLayoutGrid* plotLayout READ plotLayout ) + Q_PROPERTY( bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend ) + Q_PROPERTY( int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance ) + Q_PROPERTY( bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag ) + Q_PROPERTY( Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier ) + Q_PROPERTY( bool openGl READ openGl WRITE setOpenGl ) /// \endcond public: /*! @@ -3608,33 +3789,41 @@ public: \see addLayer, moveLayer */ - enum LayerInsertMode { limBelow ///< Layer is inserted below other layer - ,limAbove ///< Layer is inserted above other layer - }; - Q_ENUMS(LayerInsertMode) - + enum LayerInsertMode + { + limBelow ///< Layer is inserted below other layer + , + limAbove ///< Layer is inserted above other layer + }; + Q_ENUMS( LayerInsertMode ) + /*! Defines with what timing the QCustomPlot surface is refreshed after a replot. \see replot */ - enum RefreshPriority { rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot - ,rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. - ,rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. - ,rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. - }; - Q_ENUMS(RefreshPriority) - - explicit QCustomPlot(QWidget *parent = 0); + enum RefreshPriority + { + rpImmediateRefresh ///< Replots immediately and repaints the widget immediately by calling QWidget::repaint() after the replot + , + rpQueuedRefresh ///< Replots immediately, but queues the widget repaint, by calling QWidget::update() after the replot. This way multiple redundant widget repaints can be avoided. + , + rpRefreshHint ///< Whether to use immediate or queued refresh depends on whether the plotting hint \ref QCP::phImmediateRefresh is set, see \ref setPlottingHints. + , + rpQueuedReplot ///< Queues the entire replot for the next event loop iteration. This way multiple redundant replots can be avoided. The actual replot is then done with \ref rpRefreshHint priority. + }; + Q_ENUMS( RefreshPriority ) + + explicit QCustomPlot( QWidget* parent = 0 ); virtual ~QCustomPlot(); - + // getters: QRect viewport() const { return mViewport; } double bufferDevicePixelRatio() const { return mBufferDevicePixelRatio; } QPixmap background() const { return mBackgroundPixmap; } bool backgroundScaled() const { return mBackgroundScaled; } Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } - QCPLayoutGrid *plotLayout() const { return mPlotLayout; } + QCPLayoutGrid* plotLayout() const { return mPlotLayout; } QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; } QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; } bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; } @@ -3644,129 +3833,129 @@ public: QCP::PlottingHints plottingHints() const { return mPlottingHints; } Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; } QCP::SelectionRectMode selectionRectMode() const { return mSelectionRectMode; } - QCPSelectionRect *selectionRect() const { return mSelectionRect; } + QCPSelectionRect* selectionRect() const { return mSelectionRect; } bool openGl() const { return mOpenGl; } - + // setters: - void setViewport(const QRect &rect); - void setBufferDevicePixelRatio(double ratio); - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements); - void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true); - void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements); - void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true); - void setAutoAddPlottableToLegend(bool on); - void setInteractions(const QCP::Interactions &interactions); - void setInteraction(const QCP::Interaction &interaction, bool enabled=true); - void setSelectionTolerance(int pixels); - void setNoAntialiasingOnDrag(bool enabled); - void setPlottingHints(const QCP::PlottingHints &hints); - void setPlottingHint(QCP::PlottingHint hint, bool enabled=true); - void setMultiSelectModifier(Qt::KeyboardModifier modifier); - void setSelectionRectMode(QCP::SelectionRectMode mode); - void setSelectionRect(QCPSelectionRect *selectionRect); - void setOpenGl(bool enabled, int multisampling=16); - + void setViewport( const QRect& rect ); + void setBufferDevicePixelRatio( double ratio ); + void setBackground( const QPixmap& pm ); + void setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatioMode mode = Qt::KeepAspectRatioByExpanding ); + void setBackground( const QBrush& brush ); + void setBackgroundScaled( bool scaled ); + void setBackgroundScaledMode( Qt::AspectRatioMode mode ); + void setAntialiasedElements( const QCP::AntialiasedElements& antialiasedElements ); + void setAntialiasedElement( QCP::AntialiasedElement antialiasedElement, bool enabled = true ); + void setNotAntialiasedElements( const QCP::AntialiasedElements& notAntialiasedElements ); + void setNotAntialiasedElement( QCP::AntialiasedElement notAntialiasedElement, bool enabled = true ); + void setAutoAddPlottableToLegend( bool on ); + void setInteractions( const QCP::Interactions& interactions ); + void setInteraction( const QCP::Interaction& interaction, bool enabled = true ); + void setSelectionTolerance( int pixels ); + void setNoAntialiasingOnDrag( bool enabled ); + void setPlottingHints( const QCP::PlottingHints& hints ); + void setPlottingHint( QCP::PlottingHint hint, bool enabled = true ); + void setMultiSelectModifier( Qt::KeyboardModifier modifier ); + void setSelectionRectMode( QCP::SelectionRectMode mode ); + void setSelectionRect( QCPSelectionRect* selectionRect ); + void setOpenGl( bool enabled, int multisampling = 16 ); + // non-property methods: // plottable interface: - QCPAbstractPlottable *plottable(int index); - QCPAbstractPlottable *plottable(); - bool removePlottable(QCPAbstractPlottable *plottable); - bool removePlottable(int index); + QCPAbstractPlottable* plottable( int index ); + QCPAbstractPlottable* plottable(); + bool removePlottable( QCPAbstractPlottable* plottable ); + bool removePlottable( int index ); int clearPlottables(); int plottableCount() const; QList selectedPlottables() const; - QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasPlottable(QCPAbstractPlottable *plottable) const; - + QCPAbstractPlottable* plottableAt( const QPointF& pos, bool onlySelectable = false ) const; + bool hasPlottable( QCPAbstractPlottable* plottable ) const; + // specialized interface for QCPGraph: - QCPGraph *graph(int index) const; - QCPGraph *graph() const; - QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0); - bool removeGraph(QCPGraph *graph); - bool removeGraph(int index); + QCPGraph* graph( int index ) const; + QCPGraph* graph() const; + QCPGraph* addGraph( QCPAxis* keyAxis = 0, QCPAxis* valueAxis = 0 ); + bool removeGraph( QCPGraph* graph ); + bool removeGraph( int index ); int clearGraphs(); int graphCount() const; QList selectedGraphs() const; // item interface: - QCPAbstractItem *item(int index) const; - QCPAbstractItem *item() const; - bool removeItem(QCPAbstractItem *item); - bool removeItem(int index); + QCPAbstractItem* item( int index ) const; + QCPAbstractItem* item() const; + bool removeItem( QCPAbstractItem* item ); + bool removeItem( int index ); int clearItems(); int itemCount() const; QList selectedItems() const; - QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const; - bool hasItem(QCPAbstractItem *item) const; - + QCPAbstractItem* itemAt( const QPointF& pos, bool onlySelectable = false ) const; + bool hasItem( QCPAbstractItem* item ) const; + // layer interface: - QCPLayer *layer(const QString &name) const; - QCPLayer *layer(int index) const; - QCPLayer *currentLayer() const; - bool setCurrentLayer(const QString &name); - bool setCurrentLayer(QCPLayer *layer); + QCPLayer* layer( const QString& name ) const; + QCPLayer* layer( int index ) const; + QCPLayer* currentLayer() const; + bool setCurrentLayer( const QString& name ); + bool setCurrentLayer( QCPLayer* layer ); int layerCount() const; - bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove); - bool removeLayer(QCPLayer *layer); - bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove); - + bool addLayer( const QString& name, QCPLayer* otherLayer = 0, LayerInsertMode insertMode = limAbove ); + bool removeLayer( QCPLayer* layer ); + bool moveLayer( QCPLayer* layer, QCPLayer* otherLayer, LayerInsertMode insertMode = limAbove ); + // axis rect/layout interface: int axisRectCount() const; - QCPAxisRect* axisRect(int index=0) const; + QCPAxisRect* axisRect( int index = 0 ) const; QList axisRects() const; - QCPLayoutElement* layoutElementAt(const QPointF &pos) const; - QCPAxisRect* axisRectAt(const QPointF &pos) const; - Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false); - + QCPLayoutElement* layoutElementAt( const QPointF& pos ) const; + QCPAxisRect* axisRectAt( const QPointF& pos ) const; + Q_SLOT void rescaleAxes( bool onlyVisiblePlottables = false ); + QList selectedAxes() const; QList selectedLegends() const; Q_SLOT void deselectAll(); - - bool savePdf(const QString &fileName, int width=0, int height=0, QCP::ExportPen exportPen=QCP::epAllowCosmetic, const QString &pdfCreator=QString(), const QString &pdfTitle=QString()); - bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1, int resolution=96, QCP::ResolutionUnit resolutionUnit=QCP::ruDotsPerInch); - QPixmap toPixmap(int width=0, int height=0, double scale=1.0); - void toPainter(QCPPainter *painter, int width=0, int height=0); - Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); - + + bool savePdf( const QString& fileName, int width = 0, int height = 0, QCP::ExportPen exportPen = QCP::epAllowCosmetic, const QString& pdfCreator = QString(), const QString& pdfTitle = QString() ); + bool savePng( const QString& fileName, int width = 0, int height = 0, double scale = 1.0, int quality = -1, int resolution = 96, QCP::ResolutionUnit resolutionUnit = QCP::ruDotsPerInch ); + bool saveJpg( const QString& fileName, int width = 0, int height = 0, double scale = 1.0, int quality = -1, int resolution = 96, QCP::ResolutionUnit resolutionUnit = QCP::ruDotsPerInch ); + bool saveBmp( const QString& fileName, int width = 0, int height = 0, double scale = 1.0, int resolution = 96, QCP::ResolutionUnit resolutionUnit = QCP::ruDotsPerInch ); + bool saveRastered( const QString& fileName, int width, int height, double scale, const char* format, int quality = -1, int resolution = 96, QCP::ResolutionUnit resolutionUnit = QCP::ruDotsPerInch ); + QPixmap toPixmap( int width = 0, int height = 0, double scale = 1.0 ); + void toPainter( QCPPainter* painter, int width = 0, int height = 0 ); + Q_SLOT void replot( QCustomPlot::RefreshPriority refreshPriority = QCustomPlot::rpRefreshHint ); + QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2; - QCPLegend *legend; - + QCPLegend* legend; + signals: - void mouseDoubleClick(QMouseEvent *event); - void mousePress(QMouseEvent *event); - void mouseMove(QMouseEvent *event); - void mouseRelease(QMouseEvent *event); - void mouseWheel(QWheelEvent *event); - - void plottableClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void plottableDoubleClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event); - void itemClick(QCPAbstractItem *item, QMouseEvent *event); - void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event); - void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event); - void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event); - + void mouseDoubleClick( QMouseEvent* event ); + void mousePress( QMouseEvent* event ); + void mouseMove( QMouseEvent* event ); + void mouseRelease( QMouseEvent* event ); + void mouseWheel( QWheelEvent* event ); + + void plottableClick( QCPAbstractPlottable* plottable, int dataIndex, QMouseEvent* event ); + void plottableDoubleClick( QCPAbstractPlottable* plottable, int dataIndex, QMouseEvent* event ); + void itemClick( QCPAbstractItem* item, QMouseEvent* event ); + void itemDoubleClick( QCPAbstractItem* item, QMouseEvent* event ); + void axisClick( QCPAxis* axis, QCPAxis::SelectablePart part, QMouseEvent* event ); + void axisDoubleClick( QCPAxis* axis, QCPAxis::SelectablePart part, QMouseEvent* event ); + void legendClick( QCPLegend* legend, QCPAbstractLegendItem* item, QMouseEvent* event ); + void legendDoubleClick( QCPLegend* legend, QCPAbstractLegendItem* item, QMouseEvent* event ); + void selectionChangedByUser(); void beforeReplot(); void afterReplot(); - + protected: // property members: QRect mViewport; double mBufferDevicePixelRatio; - QCPLayoutGrid *mPlotLayout; + QCPLayoutGrid* mPlotLayout; bool mAutoAddPlottableToLegend; QList mPlottables; - QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph + QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph QList mItems; QList mLayers; QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements; @@ -3778,13 +3967,13 @@ protected: QPixmap mScaledBackgroundPixmap; bool mBackgroundScaled; Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayer *mCurrentLayer; + QCPLayer* mCurrentLayer; QCP::PlottingHints mPlottingHints; Qt::KeyboardModifier mMultiSelectModifier; QCP::SelectionRectMode mSelectionRectMode; - QCPSelectionRect *mSelectionRect; + QCPSelectionRect* mSelectionRect; bool mOpenGl; - + // non-property members: QList > mPaintBuffers; QPoint mMousePressPos; @@ -3803,41 +3992,41 @@ protected: QSharedPointer mGlSurface; QSharedPointer mGlPaintDevice; #endif - + // reimplemented virtual methods: virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; virtual QSize sizeHint() const Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - + virtual void paintEvent( QPaintEvent* event ) Q_DECL_OVERRIDE; + virtual void resizeEvent( QResizeEvent* event ) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent( QMouseEvent* event ) Q_DECL_OVERRIDE; + virtual void mousePressEvent( QMouseEvent* event ) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent( QMouseEvent* event ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent( QMouseEvent* event ) Q_DECL_OVERRIDE; + virtual void wheelEvent( QWheelEvent* event ) Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual void draw(QCPPainter *painter); + virtual void draw( QCPPainter* painter ); virtual void updateLayout(); - virtual void axisRemoved(QCPAxis *axis); - virtual void legendRemoved(QCPLegend *legend); - Q_SLOT virtual void processRectSelection(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processRectZoom(QRect rect, QMouseEvent *event); - Q_SLOT virtual void processPointSelection(QMouseEvent *event); - + virtual void axisRemoved( QCPAxis* axis ); + virtual void legendRemoved( QCPLegend* legend ); + Q_SLOT virtual void processRectSelection( QRect rect, QMouseEvent* event ); + Q_SLOT virtual void processRectZoom( QRect rect, QMouseEvent* event ); + Q_SLOT virtual void processPointSelection( QMouseEvent* event ); + // non-virtual methods: - bool registerPlottable(QCPAbstractPlottable *plottable); - bool registerGraph(QCPGraph *graph); - bool registerItem(QCPAbstractItem* item); + bool registerPlottable( QCPAbstractPlottable* plottable ); + bool registerGraph( QCPGraph* graph ); + bool registerItem( QCPAbstractItem* item ); void updateLayerIndices() const; - QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const; - QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=0) const; - void drawBackground(QCPPainter *painter); + QCPLayerable* layerableAt( const QPointF& pos, bool onlySelectable, QVariant* selectionDetails = 0 ) const; + QList layerableListAt( const QPointF& pos, bool onlySelectable, QList* selectionDetails = 0 ) const; + void drawBackground( QCPPainter* painter ); void setupPaintBuffers(); - QCPAbstractPaintBuffer *createPaintBuffer(); + QCPAbstractPaintBuffer* createPaintBuffer(); bool hasInvalidatedPaintBuffers(); bool setupOpenGl(); void freeOpenGl(); - + friend class QCPLegend; friend class QCPAxis; friend class QCPLayer; @@ -3846,12 +4035,11 @@ protected: friend class QCPGraph; friend class QCPAbstractItem; }; -Q_DECLARE_METATYPE(QCustomPlot::LayerInsertMode) -Q_DECLARE_METATYPE(QCustomPlot::RefreshPriority) +Q_DECLARE_METATYPE( QCustomPlot::LayerInsertMode ) +Q_DECLARE_METATYPE( QCustomPlot::RefreshPriority ) /* end of 'src/core.h' */ - /* including file 'src/plottable1d.h', size 4544 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -3861,53 +4049,52 @@ public: virtual ~QCPPlottableInterface1D() {} // introduced pure virtual methods: virtual int dataCount() const = 0; - virtual double dataMainKey(int index) const = 0; - virtual double dataSortKey(int index) const = 0; - virtual double dataMainValue(int index) const = 0; - virtual QCPRange dataValueRange(int index) const = 0; - virtual QPointF dataPixelPosition(int index) const = 0; + virtual double dataMainKey( int index ) const = 0; + virtual double dataSortKey( int index ) const = 0; + virtual double dataMainValue( int index ) const = 0; + virtual QCPRange dataValueRange( int index ) const = 0; + virtual QPointF dataPixelPosition( int index ) const = 0; virtual bool sortKeyIsMainKey() const = 0; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const = 0; - virtual int findBegin(double sortKey, bool expandedRange=true) const = 0; - virtual int findEnd(double sortKey, bool expandedRange=true) const = 0; + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const = 0; + virtual int findBegin( double sortKey, bool expandedRange = true ) const = 0; + virtual int findEnd( double sortKey, bool expandedRange = true ) const = 0; }; template -class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) +class QCPAbstractPlottable1D : public QCPAbstractPlottable, public QCPPlottableInterface1D // no QCP_LIB_DECL, template class ends up in header (cpp included below) { // No Q_OBJECT macro due to template class - + public: - QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis); + QCPAbstractPlottable1D( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPAbstractPlottable1D(); - + // virtual methods of 1d plottable interface: virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual double dataMainKey( int index ) const Q_DECL_OVERRIDE; + virtual double dataSortKey( int index ) const Q_DECL_OVERRIDE; + virtual double dataMainValue( int index ) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange( int index ) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition( int index ) const Q_DECL_OVERRIDE; virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const Q_DECL_OVERRIDE; + virtual int findBegin( double sortKey, bool expandedRange = true ) const Q_DECL_OVERRIDE; + virtual int findEnd( double sortKey, bool expandedRange = true ) const Q_DECL_OVERRIDE; + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D* interface1D() Q_DECL_OVERRIDE { return this; } + protected: // property members: QSharedPointer > mDataContainer; - + // helpers for subclasses: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - void drawPolyline(QCPPainter *painter, const QVector &lineData) const; + void getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const; + void drawPolyline( QCPPainter* painter, const QVector& lineData ) const; private: - Q_DISABLE_COPY(QCPAbstractPlottable1D) - + Q_DISABLE_COPY( QCPAbstractPlottable1D ) }; // include implementation in header since it is a class template: @@ -4055,7 +4242,6 @@ private: /* end documentation of pure virtual functions */ - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractPlottable1D //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4101,9 +4287,8 @@ private: "QCPAbstractPlottable" constructor and allocates the \a mDataContainer. */ template -QCPAbstractPlottable1D::QCPAbstractPlottable1D(QCPAxis *keyAxis, QCPAxis *valueAxis) : - QCPAbstractPlottable(keyAxis, valueAxis), - mDataContainer(new QCPDataContainer) +QCPAbstractPlottable1D::QCPAbstractPlottable1D( QCPAxis* keyAxis, QCPAxis* valueAxis ) + : QCPAbstractPlottable( keyAxis, valueAxis ), mDataContainer( new QCPDataContainer ) { } @@ -4125,12 +4310,13 @@ int QCPAbstractPlottable1D::dataCount() const \copydoc QCPPlottableInterface1D::dataMainKey */ template -double QCPAbstractPlottable1D::dataMainKey(int index) const +double QCPAbstractPlottable1D::dataMainKey( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - return (mDataContainer->constBegin()+index)->mainKey(); - } else + return ( mDataContainer->constBegin() + index )->mainKey(); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return 0; @@ -4141,12 +4327,13 @@ double QCPAbstractPlottable1D::dataMainKey(int index) const \copydoc QCPPlottableInterface1D::dataSortKey */ template -double QCPAbstractPlottable1D::dataSortKey(int index) const +double QCPAbstractPlottable1D::dataSortKey( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - return (mDataContainer->constBegin()+index)->sortKey(); - } else + return ( mDataContainer->constBegin() + index )->sortKey(); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return 0; @@ -4157,12 +4344,13 @@ double QCPAbstractPlottable1D::dataSortKey(int index) const \copydoc QCPPlottableInterface1D::dataMainValue */ template -double QCPAbstractPlottable1D::dataMainValue(int index) const +double QCPAbstractPlottable1D::dataMainValue( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - return (mDataContainer->constBegin()+index)->mainValue(); - } else + return ( mDataContainer->constBegin() + index )->mainValue(); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return 0; @@ -4173,15 +4361,16 @@ double QCPAbstractPlottable1D::dataMainValue(int index) const \copydoc QCPPlottableInterface1D::dataValueRange */ template -QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const +QCPRange QCPAbstractPlottable1D::dataValueRange( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - return (mDataContainer->constBegin()+index)->valueRange(); - } else + return ( mDataContainer->constBegin() + index )->valueRange(); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; - return QCPRange(0, 0); + return QCPRange( 0, 0 ); } } @@ -4189,13 +4378,14 @@ QCPRange QCPAbstractPlottable1D::dataValueRange(int index) const \copydoc QCPPlottableInterface1D::dataPixelPosition */ template -QPointF QCPAbstractPlottable1D::dataPixelPosition(int index) const +QPointF QCPAbstractPlottable1D::dataPixelPosition( int index ) const { - if (index >= 0 && index < mDataContainer->size()) + if( index >= 0 && index < mDataContainer->size() ) { - const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin()+index; - return coordsToPixels(it->mainKey(), it->mainValue()); - } else + const typename QCPDataContainer::const_iterator it = mDataContainer->constBegin() + index; + return coordsToPixels( it->mainKey(), it->mainValue() ); + } + else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return QPointF(); @@ -4219,47 +4409,48 @@ bool QCPAbstractPlottable1D::sortKeyIsMainKey() const \seebaseclassmethod */ template -QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF &rect, bool onlySelectable) const +QCPDataSelection QCPAbstractPlottable1D::selectTestRect( const QRectF& rect, bool onlySelectable ) const { QCPDataSelection result; - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return result; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return result; - + // convert rect given in pixels to ranges given in plot coordinates: double key1, value1, key2, value2; - pixelsToCoords(rect.topLeft(), key1, value1); - pixelsToCoords(rect.bottomRight(), key2, value2); - QCPRange keyRange(key1, key2); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 - QCPRange valueRange(value1, value2); + pixelsToCoords( rect.topLeft(), key1, value1 ); + pixelsToCoords( rect.bottomRight(), key2, value2 ); + QCPRange keyRange( key1, key2 ); // QCPRange normalizes internally so we don't have to care about whether key1 < key2 + QCPRange valueRange( value1, value2 ); typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + if( DataType::sortKeyIsMainKey() ) // we can assume that data is sorted by main key, so can reduce the searched key interval: { - begin = mDataContainer->findBegin(keyRange.lower, false); - end = mDataContainer->findEnd(keyRange.upper, false); + begin = mDataContainer->findBegin( keyRange.lower, false ); + end = mDataContainer->findEnd( keyRange.upper, false ); } - if (begin == end) + if( begin == end ) return result; - - int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + + int currentSegmentBegin = -1; // -1 means we're currently not in a segment that's contained in rect + for( typename QCPDataContainer::const_iterator it = begin; it != end; ++it ) { - if (currentSegmentBegin == -1) + if( currentSegmentBegin == -1 ) { - if (valueRange.contains(it->mainValue()) && keyRange.contains(it->mainKey())) // start segment - currentSegmentBegin = it-mDataContainer->constBegin(); - } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended + if( valueRange.contains( it->mainValue() ) && keyRange.contains( it->mainKey() ) ) // start segment + currentSegmentBegin = it - mDataContainer->constBegin(); + } + else if( !valueRange.contains( it->mainValue() ) || !keyRange.contains( it->mainKey() ) ) // segment just ended { - result.addDataRange(QCPDataRange(currentSegmentBegin, it-mDataContainer->constBegin()), false); + result.addDataRange( QCPDataRange( currentSegmentBegin, it - mDataContainer->constBegin() ), false ); currentSegmentBegin = -1; } } // process potential last segment: - if (currentSegmentBegin != -1) - result.addDataRange(QCPDataRange(currentSegmentBegin, end-mDataContainer->constBegin()), false); - + if( currentSegmentBegin != -1 ) + result.addDataRange( QCPDataRange( currentSegmentBegin, end - mDataContainer->constBegin() ), false ); + result.simplify(); return result; } @@ -4268,18 +4459,18 @@ QCPDataSelection QCPAbstractPlottable1D::selectTestRect(const QRectF & \copydoc QCPPlottableInterface1D::findBegin */ template -int QCPAbstractPlottable1D::findBegin(double sortKey, bool expandedRange) const +int QCPAbstractPlottable1D::findBegin( double sortKey, bool expandedRange ) const { - return mDataContainer->findBegin(sortKey, expandedRange)-mDataContainer->constBegin(); + return mDataContainer->findBegin( sortKey, expandedRange ) - mDataContainer->constBegin(); } /*! \copydoc QCPPlottableInterface1D::findEnd */ template -int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange) const +int QCPAbstractPlottable1D::findEnd( double sortKey, bool expandedRange ) const { - return mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin(); + return mDataContainer->findEnd( sortKey, expandedRange ) - mDataContainer->constBegin(); } /*! @@ -4293,55 +4484,55 @@ int QCPAbstractPlottable1D::findEnd(double sortKey, bool expandedRange \seebaseclassmethod */ template -double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const +double QCPAbstractPlottable1D::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const { - if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) + if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) return -1; - if (!mKeyAxis || !mValueAxis) + if( !mKeyAxis || !mValueAxis ) return -1; - + QCPDataSelection selectionResult; - double minDistSqr = (std::numeric_limits::max)(); + double minDistSqr = ( std::numeric_limits::max )(); int minDistIndex = mDataContainer->size(); - + typename QCPDataContainer::const_iterator begin = mDataContainer->constBegin(); typename QCPDataContainer::const_iterator end = mDataContainer->constEnd(); - if (DataType::sortKeyIsMainKey()) // we can assume that data is sorted by main key, so can reduce the searched key interval: + if( DataType::sortKeyIsMainKey() ) // we can assume that data is sorted by main key, so can reduce the searched key interval: { // determine which key range comes into question, taking selection tolerance around pos into account: double posKeyMin, posKeyMax, dummy; - pixelsToCoords(pos-QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMin, dummy); - pixelsToCoords(pos+QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), posKeyMax, dummy); - if (posKeyMin > posKeyMax) - qSwap(posKeyMin, posKeyMax); - begin = mDataContainer->findBegin(posKeyMin, true); - end = mDataContainer->findEnd(posKeyMax, true); + pixelsToCoords( pos - QPointF( mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance() ), posKeyMin, dummy ); + pixelsToCoords( pos + QPointF( mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance() ), posKeyMax, dummy ); + if( posKeyMin > posKeyMax ) + qSwap( posKeyMin, posKeyMax ); + begin = mDataContainer->findBegin( posKeyMin, true ); + end = mDataContainer->findEnd( posKeyMax, true ); } - if (begin == end) + if( begin == end ) return -1; - QCPRange keyRange(mKeyAxis->range()); - QCPRange valueRange(mValueAxis->range()); - for (typename QCPDataContainer::const_iterator it=begin; it!=end; ++it) + QCPRange keyRange( mKeyAxis->range() ); + QCPRange valueRange( mValueAxis->range() ); + for( typename QCPDataContainer::const_iterator it = begin; it != end; ++it ) { const double mainKey = it->mainKey(); const double mainValue = it->mainValue(); - if (keyRange.contains(mainKey) && valueRange.contains(mainValue)) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points + if( keyRange.contains( mainKey ) && valueRange.contains( mainValue ) ) // make sure data point is inside visible range, for speedup in cases where sort key isn't main key and we iterate over all points { - const double currentDistSqr = QCPVector2D(coordsToPixels(mainKey, mainValue)-pos).lengthSquared(); - if (currentDistSqr < minDistSqr) + const double currentDistSqr = QCPVector2D( coordsToPixels( mainKey, mainValue ) - pos ).lengthSquared(); + if( currentDistSqr < minDistSqr ) { minDistSqr = currentDistSqr; - minDistIndex = it-mDataContainer->constBegin(); + minDistIndex = it - mDataContainer->constBegin(); } } } - if (minDistIndex != mDataContainer->size()) - selectionResult.addDataRange(QCPDataRange(minDistIndex, minDistIndex+1), false); - + if( minDistIndex != mDataContainer->size() ) + selectionResult.addDataRange( QCPDataRange( minDistIndex, minDistIndex + 1 ), false ); + selectionResult.simplify(); - if (details) - details->setValue(selectionResult); - return qSqrt(minDistSqr); + if( details ) + details->setValue( selectionResult ); + return qSqrt( minDistSqr ); } /*! @@ -4355,22 +4546,23 @@ double QCPAbstractPlottable1D::selectTest(const QPointF &pos, bool onl \see setSelection */ template -void QCPAbstractPlottable1D::getDataSegments(QList &selectedSegments, QList &unselectedSegments) const +void QCPAbstractPlottable1D::getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const { selectedSegments.clear(); unselectedSegments.clear(); - if (mSelectable == QCP::stWhole) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty + if( mSelectable == QCP::stWhole ) // stWhole selection type draws the entire plottable with selected style if mSelection isn't empty { - if (selected()) - selectedSegments << QCPDataRange(0, dataCount()); + if( selected() ) + selectedSegments << QCPDataRange( 0, dataCount() ); else - unselectedSegments << QCPDataRange(0, dataCount()); - } else + unselectedSegments << QCPDataRange( 0, dataCount() ); + } + else { - QCPDataSelection sel(selection()); + QCPDataSelection sel( selection() ); sel.simplify(); selectedSegments = sel.dataRanges(); - unselectedSegments = sel.inverse(QCPDataRange(0, dataCount())).dataRanges(); + unselectedSegments = sel.inverse( QCPDataRange( 0, dataCount() ) ).dataRanges(); } } @@ -4385,56 +4577,56 @@ void QCPAbstractPlottable1D::getDataSegments(QList &sele style allows. */ template -void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const +void QCPAbstractPlottable1D::drawPolyline( QCPPainter* painter, const QVector& lineData ) const { // if drawing solid line and not in PDF, use much faster line drawing instead of polyline: - if (mParentPlot->plottingHints().testFlag(QCP::phFastPolylines) && + if( mParentPlot->plottingHints().testFlag( QCP::phFastPolylines ) && painter->pen().style() == Qt::SolidLine && - !painter->modes().testFlag(QCPPainter::pmVectorized) && - !painter->modes().testFlag(QCPPainter::pmNoCaching)) + !painter->modes().testFlag( QCPPainter::pmVectorized ) && + !painter->modes().testFlag( QCPPainter::pmNoCaching ) ) { int i = 0; bool lastIsNan = false; const int lineDataSize = lineData.size(); - while (i < lineDataSize && (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()))) // make sure first point is not NaN + while( i < lineDataSize && ( qIsNaN( lineData.at( i ).y() ) || qIsNaN( lineData.at( i ).x() ) ) ) // make sure first point is not NaN ++i; - ++i; // because drawing works in 1 point retrospect - while (i < lineDataSize) + ++i; // because drawing works in 1 point retrospect + while( i < lineDataSize ) { - if (!qIsNaN(lineData.at(i).y()) && !qIsNaN(lineData.at(i).x())) // NaNs create a gap in the line + if( !qIsNaN( lineData.at( i ).y() ) && !qIsNaN( lineData.at( i ).x() ) ) // NaNs create a gap in the line { - if (!lastIsNan) - painter->drawLine(lineData.at(i-1), lineData.at(i)); + if( !lastIsNan ) + painter->drawLine( lineData.at( i - 1 ), lineData.at( i ) ); else lastIsNan = false; - } else + } + else lastIsNan = true; ++i; } - } else + } + else { int segmentStart = 0; int i = 0; const int lineDataSize = lineData.size(); - while (i < lineDataSize) + while( i < lineDataSize ) { - if (qIsNaN(lineData.at(i).y()) || qIsNaN(lineData.at(i).x()) || qIsInf(lineData.at(i).y())) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block + if( qIsNaN( lineData.at( i ).y() ) || qIsNaN( lineData.at( i ).x() ) || qIsInf( lineData.at( i ).y() ) ) // NaNs create a gap in the line. Also filter Infs which make drawPolyline block { - painter->drawPolyline(lineData.constData()+segmentStart, i-segmentStart); // i, because we don't want to include the current NaN point - segmentStart = i+1; + painter->drawPolyline( lineData.constData() + segmentStart, i - segmentStart ); // i, because we don't want to include the current NaN point + segmentStart = i + 1; } ++i; } // draw last segment: - painter->drawPolyline(lineData.constData()+segmentStart, lineDataSize-segmentStart); + painter->drawPolyline( lineData.constData() + segmentStart, lineDataSize - segmentStart ); } } /* end of 'src/plottable1d.cpp' */ - /* end of 'src/plottable1d.h' */ - /* including file 'src/colorgradient.h', size 6243 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -4447,77 +4639,92 @@ public: \see setColorInterpolation */ - enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated - ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) - }; - Q_ENUMS(ColorInterpolation) - + enum ColorInterpolation + { + ciRGB ///< Color channels red, green and blue are linearly interpolated + , + ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance) + }; + Q_ENUMS( ColorInterpolation ) + /*! Defines the available presets that can be loaded with \ref loadPreset. See the documentation there for an image of the presets. */ - enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) - ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) - ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) - ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) - ,gpCandy ///< Blue over pink to white - ,gpGeography ///< Colors suitable to represent different elevations on geographical maps - ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) - ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white - ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values - ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) - ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) - ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) - }; - Q_ENUMS(GradientPreset) - + enum GradientPreset + { + gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation) + , + gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation) + , + gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation) + , + gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation) + , + gpCandy ///< Blue over pink to white + , + gpGeography ///< Colors suitable to represent different elevations on geographical maps + , + gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates) + , + gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white + , + gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values + , + gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates) + , + gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates) + , + gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic) + }; + Q_ENUMS( GradientPreset ) + QCPColorGradient(); - QCPColorGradient(GradientPreset preset); - bool operator==(const QCPColorGradient &other) const; - bool operator!=(const QCPColorGradient &other) const { return !(*this == other); } - + QCPColorGradient( GradientPreset preset ); + bool operator==( const QCPColorGradient& other ) const; + bool operator!=( const QCPColorGradient& other ) const { return !( *this == other ); } + // getters: int levelCount() const { return mLevelCount; } QMap colorStops() const { return mColorStops; } ColorInterpolation colorInterpolation() const { return mColorInterpolation; } bool periodic() const { return mPeriodic; } - + // setters: - void setLevelCount(int n); - void setColorStops(const QMap &colorStops); - void setColorStopAt(double position, const QColor &color); - void setColorInterpolation(ColorInterpolation interpolation); - void setPeriodic(bool enabled); - + void setLevelCount( int n ); + void setColorStops( const QMap& colorStops ); + void setColorStopAt( double position, const QColor& color ); + void setColorInterpolation( ColorInterpolation interpolation ); + void setPeriodic( bool enabled ); + // non-property methods: - void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - void colorize(const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false); - QRgb color(double position, const QCPRange &range, bool logarithmic=false); - void loadPreset(GradientPreset preset); + void colorize( const double* data, const QCPRange& range, QRgb* scanLine, int n, int dataIndexFactor = 1, bool logarithmic = false ); + void colorize( const double* data, const unsigned char* alpha, const QCPRange& range, QRgb* scanLine, int n, int dataIndexFactor = 1, bool logarithmic = false ); + QRgb color( double position, const QCPRange& range, bool logarithmic = false ); + void loadPreset( GradientPreset preset ); void clearColorStops(); QCPColorGradient inverted() const; - + protected: // property members: int mLevelCount; QMap mColorStops; ColorInterpolation mColorInterpolation; bool mPeriodic; - + // non-property members: - QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) + QVector mColorBuffer; // have colors premultiplied with alpha (for usage with QImage::Format_ARGB32_Premultiplied) bool mColorBufferInvalidated; - + // non-virtual methods: bool stopsUseAlpha() const; void updateColorBuffer(); }; -Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) -Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) +Q_DECLARE_METATYPE( QCPColorGradient::ColorInterpolation ) +Q_DECLARE_METATYPE( QCPColorGradient::GradientPreset ) /* end of 'src/colorgradient.h' */ - /* including file 'src/selectiondecorator-bracket.h', size 4442 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -4525,24 +4732,29 @@ class QCP_LIB_DECL QCPSelectionDecoratorBracket : public QCPSelectionDecorator { Q_GADGET public: - /*! Defines which shape is drawn at the boundaries of selected data ranges. Some of the bracket styles further allow specifying a height and/or width, see \ref setBracketHeight and \ref setBracketWidth. */ - enum BracketStyle { bsSquareBracket ///< A square bracket is drawn. - ,bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. - ,bsPlus ///< A plus is drawn. - ,bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. + enum BracketStyle + { + bsSquareBracket ///< A square bracket is drawn. + , + bsHalfEllipse ///< A half ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + , + bsEllipse ///< An ellipse is drawn. The size of the ellipse is given by the bracket width/height properties. + , + bsPlus ///< A plus is drawn. + , + bsUserStyle ///< Start custom bracket styles at this index when subclassing and reimplementing \ref drawBracket. }; - Q_ENUMS(BracketStyle) - + Q_ENUMS( BracketStyle ) + QCPSelectionDecoratorBracket(); virtual ~QCPSelectionDecoratorBracket(); - + // getters: QPen bracketPen() const { return mBracketPen; } QBrush bracketBrush() const { return mBracketBrush; } @@ -4551,22 +4763,22 @@ public: BracketStyle bracketStyle() const { return mBracketStyle; } bool tangentToData() const { return mTangentToData; } int tangentAverage() const { return mTangentAverage; } - + // setters: - void setBracketPen(const QPen &pen); - void setBracketBrush(const QBrush &brush); - void setBracketWidth(int width); - void setBracketHeight(int height); - void setBracketStyle(BracketStyle style); - void setTangentToData(bool enabled); - void setTangentAverage(int pointCount); - + void setBracketPen( const QPen& pen ); + void setBracketBrush( const QBrush& brush ); + void setBracketWidth( int width ); + void setBracketHeight( int height ); + void setBracketStyle( BracketStyle style ); + void setTangentToData( bool enabled ); + void setTangentAverage( int pointCount ); + // introduced virtual methods: - virtual void drawBracket(QCPPainter *painter, int direction) const; - + virtual void drawBracket( QCPPainter* painter, int direction ) const; + // virtual methods: - virtual void drawDecoration(QCPPainter *painter, QCPDataSelection selection) Q_DECL_OVERRIDE; - + virtual void drawDecoration( QCPPainter* painter, QCPDataSelection selection ) Q_DECL_OVERRIDE; + protected: // property members: QPen mBracketPen; @@ -4576,17 +4788,15 @@ protected: BracketStyle mBracketStyle; bool mTangentToData; int mTangentAverage; - + // non-virtual methods: - double getTangentAngle(const QCPPlottableInterface1D *interface1d, int dataIndex, int direction) const; - QPointF getPixelCoordinates(const QCPPlottableInterface1D *interface1d, int dataIndex) const; - + double getTangentAngle( const QCPPlottableInterface1D* interface1d, int dataIndex, int direction ) const; + QPointF getPixelCoordinates( const QCPPlottableInterface1D* interface1d, int dataIndex ) const; }; -Q_DECLARE_METATYPE(QCPSelectionDecoratorBracket::BracketStyle) +Q_DECLARE_METATYPE( QCPSelectionDecoratorBracket::BracketStyle ) /* end of 'src/selectiondecorator-bracket.h' */ - /* including file 'src/layoutelements/layoutelement-axisrect.h', size 7507 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -4594,16 +4804,16 @@ class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap background READ background WRITE setBackground) - Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled) - Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode) - Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom) + Q_PROPERTY( QPixmap background READ background WRITE setBackground ) + Q_PROPERTY( bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled ) + Q_PROPERTY( Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode ) + Q_PROPERTY( Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag ) + Q_PROPERTY( Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom ) /// \endcond public: - explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true); + explicit QCPAxisRect( QCustomPlot* parentPlot, bool setupDefaultAxes = true ); virtual ~QCPAxisRect(); - + // getters: QPixmap background() const { return mBackgroundPixmap; } QBrush backgroundBrush() const { return mBackgroundBrush; } @@ -4611,46 +4821,46 @@ public: Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; } Qt::Orientations rangeDrag() const { return mRangeDrag; } Qt::Orientations rangeZoom() const { return mRangeZoom; } - QCPAxis *rangeDragAxis(Qt::Orientation orientation); - QCPAxis *rangeZoomAxis(Qt::Orientation orientation); - QList rangeDragAxes(Qt::Orientation orientation); - QList rangeZoomAxes(Qt::Orientation orientation); - double rangeZoomFactor(Qt::Orientation orientation); - + QCPAxis* rangeDragAxis( Qt::Orientation orientation ); + QCPAxis* rangeZoomAxis( Qt::Orientation orientation ); + QList rangeDragAxes( Qt::Orientation orientation ); + QList rangeZoomAxes( Qt::Orientation orientation ); + double rangeZoomFactor( Qt::Orientation orientation ); + // setters: - void setBackground(const QPixmap &pm); - void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding); - void setBackground(const QBrush &brush); - void setBackgroundScaled(bool scaled); - void setBackgroundScaledMode(Qt::AspectRatioMode mode); - void setRangeDrag(Qt::Orientations orientations); - void setRangeZoom(Qt::Orientations orientations); - void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeDragAxes(QList axes); - void setRangeDragAxes(QList horizontal, QList vertical); - void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical); - void setRangeZoomAxes(QList axes); - void setRangeZoomAxes(QList horizontal, QList vertical); - void setRangeZoomFactor(double horizontalFactor, double verticalFactor); - void setRangeZoomFactor(double factor); - + void setBackground( const QPixmap& pm ); + void setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatioMode mode = Qt::KeepAspectRatioByExpanding ); + void setBackground( const QBrush& brush ); + void setBackgroundScaled( bool scaled ); + void setBackgroundScaledMode( Qt::AspectRatioMode mode ); + void setRangeDrag( Qt::Orientations orientations ); + void setRangeZoom( Qt::Orientations orientations ); + void setRangeDragAxes( QCPAxis* horizontal, QCPAxis* vertical ); + void setRangeDragAxes( QList axes ); + void setRangeDragAxes( QList horizontal, QList vertical ); + void setRangeZoomAxes( QCPAxis* horizontal, QCPAxis* vertical ); + void setRangeZoomAxes( QList axes ); + void setRangeZoomAxes( QList horizontal, QList vertical ); + void setRangeZoomFactor( double horizontalFactor, double verticalFactor ); + void setRangeZoomFactor( double factor ); + // non-property methods: - int axisCount(QCPAxis::AxisType type) const; - QCPAxis *axis(QCPAxis::AxisType type, int index=0) const; - QList axes(QCPAxis::AxisTypes types) const; + int axisCount( QCPAxis::AxisType type ) const; + QCPAxis* axis( QCPAxis::AxisType type, int index = 0 ) const; + QList axes( QCPAxis::AxisTypes types ) const; QList axes() const; - QCPAxis *addAxis(QCPAxis::AxisType type, QCPAxis *axis=0); - QList addAxes(QCPAxis::AxisTypes types); - bool removeAxis(QCPAxis *axis); - QCPLayoutInset *insetLayout() const { return mInsetLayout; } - - void zoom(const QRectF &pixelRect); - void zoom(const QRectF &pixelRect, const QList &affectedAxes); - void setupFullAxesBox(bool connectRanges=false); + QCPAxis* addAxis( QCPAxis::AxisType type, QCPAxis* axis = 0 ); + QList addAxes( QCPAxis::AxisTypes types ); + bool removeAxis( QCPAxis* axis ); + QCPLayoutInset* insetLayout() const { return mInsetLayout; } + + void zoom( const QRectF& pixelRect ); + void zoom( const QRectF& pixelRect, const QList& affectedAxes ); + void setupFullAxesBox( bool connectRanges = false ); QList plottables() const; QList graphs() const; QList items() const; - + // read-only interface imitating a QRect: int left() const { return mRect.left(); } int right() const { return mRect.right(); } @@ -4664,10 +4874,10 @@ public: QPoint bottomLeft() const { return mRect.bottomLeft(); } QPoint bottomRight() const { return mRect.bottomRight(); } QPoint center() const { return mRect.center(); } - + // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + virtual void update( UpdatePhase phase ) Q_DECL_OVERRIDE; + virtual QList elements( bool recursive ) const Q_DECL_OVERRIDE; protected: // property members: @@ -4676,43 +4886,41 @@ protected: QPixmap mScaledBackgroundPixmap; bool mBackgroundScaled; Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayoutInset *mInsetLayout; + QCPLayoutInset* mInsetLayout; Qt::Orientations mRangeDrag, mRangeZoom; QList > mRangeDragHorzAxis, mRangeDragVertAxis; QList > mRangeZoomHorzAxis, mRangeZoomVertAxis; double mRangeZoomFactorHorz, mRangeZoomFactorVert; - + // non-property members: QList mDragStartHorzRange, mDragStartVertRange; QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; bool mDragging; QHash > mAxes; - + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual int calculateAutoMargin(QCP::MarginSide side) Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual int calculateAutoMargin( QCP::MarginSide side ) Q_DECL_OVERRIDE; virtual void layoutChanged() Q_DECL_OVERRIDE; // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - + virtual void mousePressEvent( QMouseEvent* event, const QVariant& details ) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void wheelEvent( QWheelEvent* event ) Q_DECL_OVERRIDE; + // non-property methods: - void drawBackground(QCPPainter *painter); - void updateAxesOffset(QCPAxis::AxisType type); - + void drawBackground( QCPPainter* painter ); + void updateAxesOffset( QCPAxis::AxisType type ); + private: - Q_DISABLE_COPY(QCPAxisRect) - + Q_DISABLE_COPY( QCPAxisRect ) + friend class QCustomPlot; }; - /* end of 'src/layoutelements/layoutelement-axisrect.h' */ - /* including file 'src/layoutelements/layoutelement-legend.h', size 10397 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -4720,108 +4928,106 @@ class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPLegend* parentLegend READ parentLegend) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged) + Q_PROPERTY( QCPLegend* parentLegend READ parentLegend ) + Q_PROPERTY( QFont font READ font WRITE setFont ) + Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) + Q_PROPERTY( QFont selectedFont READ selectedFont WRITE setSelectedFont ) + Q_PROPERTY( QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor ) + Q_PROPERTY( bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged ) + Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectableChanged ) /// \endcond public: - explicit QCPAbstractLegendItem(QCPLegend *parent); - + explicit QCPAbstractLegendItem( QCPLegend* parent ); + // getters: - QCPLegend *parentLegend() const { return mParentLegend; } + QCPLegend* parentLegend() const { return mParentLegend; } QFont font() const { return mFont; } QColor textColor() const { return mTextColor; } QFont selectedFont() const { return mSelectedFont; } QColor selectedTextColor() const { return mSelectedTextColor; } bool selectable() const { return mSelectable; } bool selected() const { return mSelected; } - + // setters: - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - + void setFont( const QFont& font ); + void setTextColor( const QColor& color ); + void setSelectedFont( const QFont& font ); + void setSelectedTextColor( const QColor& color ); + Q_SLOT void setSelectable( bool selectable ); + Q_SLOT void setSelected( bool selected ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - + void selectionChanged( bool selected ); + void selectableChanged( bool selectable ); + protected: // property members: - QCPLegend *mParentLegend; + QCPLegend* mParentLegend; QFont mFont; QColor mTextColor; QFont mSelectedFont; QColor mSelectedTextColor; bool mSelectable, mSelected; - + // reimplemented virtual methods: virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; virtual QRect clipRect() const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE = 0; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE = 0; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; + private: - Q_DISABLE_COPY(QCPAbstractLegendItem) - + Q_DISABLE_COPY( QCPAbstractLegendItem ) + friend class QCPLegend; }; - class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem { Q_OBJECT public: - QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable); - + QCPPlottableLegendItem( QCPLegend* parent, QCPAbstractPlottable* plottable ); + // getters: - QCPAbstractPlottable *plottable() { return mPlottable; } - + QCPAbstractPlottable* plottable() { return mPlottable; } + protected: // property members: - QCPAbstractPlottable *mPlottable; - + QCPAbstractPlottable* mPlottable; + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; - + // non-virtual methods: QPen getIconBorderPen() const; QColor getTextColor() const; QFont getFont() const; }; - class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) - Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding) - Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen) - Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged) - Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged) - Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen) - Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) + Q_PROPERTY( QPen borderPen READ borderPen WRITE setBorderPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QFont font READ font WRITE setFont ) + Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) + Q_PROPERTY( QSize iconSize READ iconSize WRITE setIconSize ) + Q_PROPERTY( int iconTextPadding READ iconTextPadding WRITE setIconTextPadding ) + Q_PROPERTY( QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen ) + Q_PROPERTY( SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged ) + Q_PROPERTY( SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged ) + Q_PROPERTY( QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen ) + Q_PROPERTY( QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen ) + Q_PROPERTY( QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush ) + Q_PROPERTY( QFont selectedFont READ selectedFont WRITE setSelectedFont ) + Q_PROPERTY( QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor ) /// \endcond public: /*! @@ -4829,17 +5035,21 @@ public: \see setSelectedParts, setSelectableParts */ - enum SelectablePart { spNone = 0x000 ///< 0x000 None - ,spLegendBox = 0x001 ///< 0x001 The legend box (frame) - ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) - }; - Q_ENUMS(SelectablePart) - Q_FLAGS(SelectableParts) - Q_DECLARE_FLAGS(SelectableParts, SelectablePart) - + enum SelectablePart + { + spNone = 0x000 ///< 0x000 None + , + spLegendBox = 0x001 ///< 0x001 The legend box (frame) + , + spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems) + }; + Q_ENUMS( SelectablePart ) + Q_FLAGS( SelectableParts ) + Q_DECLARE_FLAGS( SelectableParts, SelectablePart ) + explicit QCPLegend(); virtual ~QCPLegend(); - + // getters: QPen borderPen() const { return mBorderPen; } QBrush brush() const { return mBrush; } @@ -4855,43 +5065,43 @@ public: QBrush selectedBrush() const { return mSelectedBrush; } QFont selectedFont() const { return mSelectedFont; } QColor selectedTextColor() const { return mSelectedTextColor; } - + // setters: - void setBorderPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setIconSize(const QSize &size); - void setIconSize(int width, int height); - void setIconTextPadding(int padding); - void setIconBorderPen(const QPen &pen); - Q_SLOT void setSelectableParts(const SelectableParts &selectableParts); - Q_SLOT void setSelectedParts(const SelectableParts &selectedParts); - void setSelectedBorderPen(const QPen &pen); - void setSelectedIconBorderPen(const QPen &pen); - void setSelectedBrush(const QBrush &brush); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - + void setBorderPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setFont( const QFont& font ); + void setTextColor( const QColor& color ); + void setIconSize( const QSize& size ); + void setIconSize( int width, int height ); + void setIconTextPadding( int padding ); + void setIconBorderPen( const QPen& pen ); + Q_SLOT void setSelectableParts( const SelectableParts& selectableParts ); + Q_SLOT void setSelectedParts( const SelectableParts& selectedParts ); + void setSelectedBorderPen( const QPen& pen ); + void setSelectedIconBorderPen( const QPen& pen ); + void setSelectedBrush( const QBrush& brush ); + void setSelectedFont( const QFont& font ); + void setSelectedTextColor( const QColor& color ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + // non-virtual methods: - QCPAbstractLegendItem *item(int index) const; - QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const; + QCPAbstractLegendItem* item( int index ) const; + QCPPlottableLegendItem* itemWithPlottable( const QCPAbstractPlottable* plottable ) const; int itemCount() const; - bool hasItem(QCPAbstractLegendItem *item) const; - bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const; - bool addItem(QCPAbstractLegendItem *item); - bool removeItem(int index); - bool removeItem(QCPAbstractLegendItem *item); + bool hasItem( QCPAbstractLegendItem* item ) const; + bool hasItemWithPlottable( const QCPAbstractPlottable* plottable ) const; + bool addItem( QCPAbstractLegendItem* item ); + bool removeItem( int index ); + bool removeItem( QCPAbstractLegendItem* item ); void clearItems(); QList selectedItems() const; - + signals: - void selectionChanged(QCPLegend::SelectableParts parts); - void selectableChanged(QCPLegend::SelectableParts parts); - + void selectionChanged( QCPLegend::SelectableParts parts ); + void selectableChanged( QCPLegend::SelectableParts parts ); + protected: // property members: QPen mBorderPen, mIconBorderPen; @@ -4905,32 +5115,31 @@ protected: QBrush mSelectedBrush; QFont mSelectedFont; QColor mSelectedTextColor; - + // reimplemented virtual methods: - virtual void parentPlotInitialized(QCustomPlot *parentPlot) Q_DECL_OVERRIDE; + virtual void parentPlotInitialized( QCustomPlot* parentPlot ) Q_DECL_OVERRIDE; virtual QCP::Interaction selectionCategory() const Q_DECL_OVERRIDE; - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; + // non-virtual methods: QPen getBorderPen() const; QBrush getBrush() const; - + private: - Q_DISABLE_COPY(QCPLegend) - + Q_DISABLE_COPY( QCPLegend ) + friend class QCustomPlot; friend class QCPAbstractLegendItem; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts) -Q_DECLARE_METATYPE(QCPLegend::SelectablePart) +Q_DECLARE_OPERATORS_FOR_FLAGS( QCPLegend::SelectableParts ) +Q_DECLARE_METATYPE( QCPLegend::SelectablePart ) /* end of 'src/layoutelements/layoutelement-legend.h' */ - /* including file 'src/layoutelements/layoutelement-textelement.h', size 5353 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -4938,21 +5147,21 @@ class QCP_LIB_DECL QCPTextElement : public QCPLayoutElement { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor) - Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged) - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged) + Q_PROPERTY( QString text READ text WRITE setText ) + Q_PROPERTY( QFont font READ font WRITE setFont ) + Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor ) + Q_PROPERTY( QFont selectedFont READ selectedFont WRITE setSelectedFont ) + Q_PROPERTY( QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor ) + Q_PROPERTY( bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged ) + Q_PROPERTY( bool selected READ selected WRITE setSelected NOTIFY selectionChanged ) /// \endcond public: - explicit QCPTextElement(QCustomPlot *parentPlot); - QCPTextElement(QCustomPlot *parentPlot, const QString &text); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QString &fontFamily, double pointSize); - QCPTextElement(QCustomPlot *parentPlot, const QString &text, const QFont &font); - + explicit QCPTextElement( QCustomPlot* parentPlot ); + QCPTextElement( QCustomPlot* parentPlot, const QString& text ); + QCPTextElement( QCustomPlot* parentPlot, const QString& text, double pointSize ); + QCPTextElement( QCustomPlot* parentPlot, const QString& text, const QString& fontFamily, double pointSize ); + QCPTextElement( QCustomPlot* parentPlot, const QString& text, const QFont& font ); + // getters: QString text() const { return mText; } int textFlags() const { return mTextFlags; } @@ -4962,29 +5171,29 @@ public: QColor selectedTextColor() const { return mSelectedTextColor; } bool selectable() const { return mSelectable; } bool selected() const { return mSelected; } - + // setters: - void setText(const QString &text); - void setTextFlags(int flags); - void setFont(const QFont &font); - void setTextColor(const QColor &color); - void setSelectedFont(const QFont &font); - void setSelectedTextColor(const QColor &color); - Q_SLOT void setSelectable(bool selectable); - Q_SLOT void setSelected(bool selected); - + void setText( const QString& text ); + void setTextFlags( int flags ); + void setFont( const QFont& font ); + void setTextColor( const QColor& color ); + void setSelectedFont( const QFont& font ); + void setSelectedTextColor( const QColor& color ); + Q_SLOT void setSelectable( bool selectable ); + Q_SLOT void setSelected( bool selected ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual void mousePressEvent( QMouseEvent* event, const QVariant& details ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void mouseDoubleClickEvent( QMouseEvent* event, const QVariant& details ) Q_DECL_OVERRIDE; + signals: - void selectionChanged(bool selected); - void selectableChanged(bool selectable); - void clicked(QMouseEvent *event); - void doubleClicked(QMouseEvent *event); - + void selectionChanged( bool selected ); + void selectableChanged( bool selectable ); + void clicked( QMouseEvent* event ); + void doubleClicked( QMouseEvent* event ); + protected: // property members: QString mText; @@ -4995,106 +5204,102 @@ protected: QColor mSelectedTextColor; QRect mTextBoundingRect; bool mSelectable, mSelected; - + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; virtual QSize minimumOuterSizeHint() const Q_DECL_OVERRIDE; virtual QSize maximumOuterSizeHint() const Q_DECL_OVERRIDE; // events: - virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) Q_DECL_OVERRIDE; - virtual void deselectEvent(bool *selectionStateChanged) Q_DECL_OVERRIDE; - + virtual void selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) Q_DECL_OVERRIDE; + virtual void deselectEvent( bool* selectionStateChanged ) Q_DECL_OVERRIDE; + // non-virtual methods: QFont mainFont() const; QColor mainTextColor() const; - + private: - Q_DISABLE_COPY(QCPTextElement) + Q_DISABLE_COPY( QCPTextElement ) }; - - /* end of 'src/layoutelements/layoutelement-textelement.h' */ - /* including file 'src/layoutelements/layoutelement-colorscale.h', size 5923 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ - class QCPColorScaleAxisRectPrivate : public QCPAxisRect { Q_OBJECT public: - explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale); + explicit QCPColorScaleAxisRectPrivate( QCPColorScale* parentColorScale ); + protected: - QCPColorScale *mParentColorScale; + QCPColorScale* mParentColorScale; QImage mGradientImage; bool mGradientImageInvalidated; // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale using QCPAxisRect::calculateAutoMargin; - using QCPAxisRect::mousePressEvent; using QCPAxisRect::mouseMoveEvent; + using QCPAxisRect::mousePressEvent; using QCPAxisRect::mouseReleaseEvent; - using QCPAxisRect::wheelEvent; using QCPAxisRect::update; - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + using QCPAxisRect::wheelEvent; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; void updateGradientImage(); - Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts); - Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts); + Q_SLOT void axisSelectionChanged( QCPAxis::SelectableParts selectedParts ); + Q_SLOT void axisSelectableChanged( QCPAxis::SelectableParts selectableParts ); friend class QCPColorScale; }; - class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType) - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(QString label READ label WRITE setLabel) - Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth) - Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag) - Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom) + Q_PROPERTY( QCPAxis::AxisType type READ type WRITE setType ) + Q_PROPERTY( QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged ) + Q_PROPERTY( QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged ) + Q_PROPERTY( QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged ) + Q_PROPERTY( QString label READ label WRITE setLabel ) + Q_PROPERTY( int barWidth READ barWidth WRITE setBarWidth ) + Q_PROPERTY( bool rangeDrag READ rangeDrag WRITE setRangeDrag ) + Q_PROPERTY( bool rangeZoom READ rangeZoom WRITE setRangeZoom ) /// \endcond public: - explicit QCPColorScale(QCustomPlot *parentPlot); + explicit QCPColorScale( QCustomPlot* parentPlot ); virtual ~QCPColorScale(); - + // getters: - QCPAxis *axis() const { return mColorAxis.data(); } + QCPAxis* axis() const { return mColorAxis.data(); } QCPAxis::AxisType type() const { return mType; } QCPRange dataRange() const { return mDataRange; } QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } QCPColorGradient gradient() const { return mGradient; } QString label() const; - int barWidth () const { return mBarWidth; } + int barWidth() const { return mBarWidth; } bool rangeDrag() const; bool rangeZoom() const; - + // setters: - void setType(QCPAxis::AxisType type); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setLabel(const QString &str); - void setBarWidth(int width); - void setRangeDrag(bool enabled); - void setRangeZoom(bool enabled); - + void setType( QCPAxis::AxisType type ); + Q_SLOT void setDataRange( const QCPRange& dataRange ); + Q_SLOT void setDataScaleType( QCPAxis::ScaleType scaleType ); + Q_SLOT void setGradient( const QCPColorGradient& gradient ); + void setLabel( const QString& str ); + void setBarWidth( int width ); + void setRangeDrag( bool enabled ); + void setRangeZoom( bool enabled ); + // non-property methods: QList colorMaps() const; - void rescaleDataRange(bool onlyVisibleMaps); - + void rescaleDataRange( bool onlyVisibleMaps ); + // reimplemented virtual methods: - virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; - + virtual void update( UpdatePhase phase ) Q_DECL_OVERRIDE; + signals: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); + void dataRangeChanged( const QCPRange& newRange ); + void dataScaleTypeChanged( QCPAxis::ScaleType scaleType ); + void gradientChanged( const QCPColorGradient& newGradient ); protected: // property members: @@ -5103,29 +5308,27 @@ protected: QCPAxis::ScaleType mDataScaleType; QCPColorGradient mGradient; int mBarWidth; - + // non-property members: QPointer mAxisRect; QPointer mColorAxis; - + // reimplemented virtual methods: - virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const Q_DECL_OVERRIDE; + virtual void applyDefaultAntialiasingHint( QCPPainter* painter ) const Q_DECL_OVERRIDE; // events: - virtual void mousePressEvent(QMouseEvent *event, const QVariant &details) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *event, const QPointF &startPos) Q_DECL_OVERRIDE; - virtual void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; - + virtual void mousePressEvent( QMouseEvent* event, const QVariant& details ) Q_DECL_OVERRIDE; + virtual void mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) Q_DECL_OVERRIDE; + virtual void wheelEvent( QWheelEvent* event ) Q_DECL_OVERRIDE; + private: - Q_DISABLE_COPY(QCPColorScale) - + Q_DISABLE_COPY( QCPColorScale ) + friend class QCPColorScaleAxisRectPrivate; }; - /* end of 'src/layoutelements/layoutelement-colorscale.h' */ - /* including file 'src/plottables/plottable-graph.h', size 9294 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5133,21 +5336,20 @@ class QCP_LIB_DECL QCPGraphData { public: QCPGraphData(); - QCPGraphData(double key, double value); - + QCPGraphData( double key, double value ); + inline double sortKey() const { return key; } - inline static QCPGraphData fromSortKey(double sortKey) { return QCPGraphData(sortKey, 0); } + inline static QCPGraphData fromSortKey( double sortKey ) { return QCPGraphData( sortKey, 0 ); } inline static bool sortKeyIsMainKey() { return true; } - + inline double mainKey() const { return key; } inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - + + inline QCPRange valueRange() const { return QCPRange( value, value ); } + double key, value; }; -Q_DECLARE_TYPEINFO(QCPGraphData, Q_PRIMITIVE_TYPE); - +Q_DECLARE_TYPEINFO( QCPGraphData, Q_PRIMITIVE_TYPE ); /*! \typedef QCPGraphDataContainer @@ -5164,11 +5366,11 @@ class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph) - Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling) + Q_PROPERTY( LineStyle lineStyle READ lineStyle WRITE setLineStyle ) + Q_PROPERTY( QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle ) + Q_PROPERTY( int scatterSkip READ scatterSkip WRITE setScatterSkip ) + Q_PROPERTY( QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph ) + Q_PROPERTY( bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling ) /// \endcond public: /*! @@ -5176,45 +5378,52 @@ public: current pen of the graph (\ref setPen). \see setLineStyle */ - enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented - ///< with symbols according to the scatter style, see \ref setScatterStyle) - ,lsLine ///< data points are connected by a straight line - ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point - ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point - ,lsStepCenter ///< line is drawn as steps where the step is in between two data points - ,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 - }; - Q_ENUMS(LineStyle) - - explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); + enum LineStyle + { + lsNone ///< data points are not connected with any lines (e.g. data only represented + ///< with symbols according to the scatter style, see \ref setScatterStyle) + , + lsLine ///< data points are connected by a straight line + , + lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point + , + lsStepRight ///< line is drawn as steps where the step height is the value of the right data point + , + lsStepCenter ///< line is drawn as steps where the step is in between two data points + , + 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 + }; + Q_ENUMS( LineStyle ) + + explicit QCPGraph( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPGraph(); - + // getters: QSharedPointer data() const { return mDataContainer; } LineStyle lineStyle() const { return mLineStyle; } QCPScatterStyle scatterStyle() const { return mScatterStyle; } int scatterSkip() const { return mScatterSkip; } - QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); } + QCPGraph* channelFillGraph() const { return mChannelFillGraph.data(); } bool adaptiveSampling() const { return mAdaptiveSampling; } - + // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setLineStyle(LineStyle ls); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setChannelFillGraph(QCPGraph *targetGraph); - void setAdaptiveSampling(bool enabled); - + void setData( QSharedPointer data ); + void setData( const QVector& keys, const QVector& values, bool alreadySorted = false ); + void setLineStyle( LineStyle ls ); + void setScatterStyle( const QCPScatterStyle& style ); + void setScatterSkip( int skip ); + void setChannelFillGraph( QCPGraph* targetGraph ); + void setAdaptiveSampling( bool enabled ); + // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - + void addData( const QVector& keys, const QVector& values, bool alreadySorted = false ); + void addData( double key, double value ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + protected: // property members: LineStyle mLineStyle; @@ -5222,49 +5431,48 @@ protected: int mScatterSkip; QPointer mChannelFillGraph; bool mAdaptiveSampling; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual void drawFill(QCPPainter *painter, QVector *lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; - virtual void drawLinePlot(QCPPainter *painter, const QVector &lines) const; - virtual void drawImpulsePlot(QCPPainter *painter, const QVector &lines) const; - - virtual void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; - virtual void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; - + virtual void drawFill( QCPPainter* painter, QVector* lines ) const; + virtual void drawScatterPlot( QCPPainter* painter, const QVector& scatters, const QCPScatterStyle& style ) const; + virtual void drawLinePlot( QCPPainter* painter, const QVector& lines ) const; + virtual void drawImpulsePlot( QCPPainter* painter, const QVector& lines ) const; + + virtual void getOptimizedLineData( QVector* lineData, const QCPGraphDataContainer::const_iterator& begin, const QCPGraphDataContainer::const_iterator& end ) const; + virtual void getOptimizedScatterData( QVector* scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end ) const; + // non-virtual methods: - void getVisibleDataBounds(QCPGraphDataContainer::const_iterator &begin, QCPGraphDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - void getLines(QVector *lines, const QCPDataRange &dataRange) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange) const; - QVector dataToLines(const QVector &data) const; - QVector dataToStepLeftLines(const QVector &data) const; - QVector dataToStepRightLines(const QVector &data) const; - QVector dataToStepCenterLines(const QVector &data) const; - QVector dataToImpulseLines(const QVector &data) const; - QVector getNonNanSegments(const QVector *lineData, Qt::Orientation keyOrientation) const; - QVector > getOverlappingSegments(QVector thisSegments, const QVector *thisData, QVector otherSegments, const QVector *otherData) const; - bool segmentsIntersect(double aLower, double aUpper, double bLower, double bUpper, int &bPrecedence) const; - QPointF getFillBasePoint(QPointF matchingDataPoint) const; - const QPolygonF getFillPolygon(const QVector *lineData, QCPDataRange segment) const; - const QPolygonF getChannelFillPolygon(const QVector *lineData, QCPDataRange thisSegment, const QVector *otherData, QCPDataRange otherSegment) const; - int findIndexBelowX(const QVector *data, double x) const; - int findIndexAboveX(const QVector *data, double x) const; - int findIndexBelowY(const QVector *data, double y) const; - int findIndexAboveY(const QVector *data, double y) const; - double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; - + void getVisibleDataBounds( QCPGraphDataContainer::const_iterator& begin, QCPGraphDataContainer::const_iterator& end, const QCPDataRange& rangeRestriction ) const; + void getLines( QVector* lines, const QCPDataRange& dataRange ) const; + void getScatters( QVector* scatters, const QCPDataRange& dataRange ) const; + QVector dataToLines( const QVector& data ) const; + QVector dataToStepLeftLines( const QVector& data ) const; + QVector dataToStepRightLines( const QVector& data ) const; + QVector dataToStepCenterLines( const QVector& data ) const; + QVector dataToImpulseLines( const QVector& data ) const; + QVector getNonNanSegments( const QVector* lineData, Qt::Orientation keyOrientation ) const; + QVector > getOverlappingSegments( QVector thisSegments, const QVector* thisData, QVector otherSegments, const QVector* otherData ) const; + bool segmentsIntersect( double aLower, double aUpper, double bLower, double bUpper, int& bPrecedence ) const; + QPointF getFillBasePoint( QPointF matchingDataPoint ) const; + const QPolygonF getFillPolygon( const QVector* lineData, QCPDataRange segment ) const; + const QPolygonF getChannelFillPolygon( const QVector* lineData, QCPDataRange thisSegment, const QVector* otherData, QCPDataRange otherSegment ) const; + int findIndexBelowX( const QVector* data, double x ) const; + int findIndexAboveX( const QVector* data, double x ) const; + int findIndexBelowY( const QVector* data, double y ) const; + int findIndexAboveY( const QVector* data, double y ) const; + double pointDistance( const QPointF& pixelPoint, QCPGraphDataContainer::const_iterator& closestData ) const; + friend class QCustomPlot; friend class QCPLegend; }; -Q_DECLARE_METATYPE(QCPGraph::LineStyle) +Q_DECLARE_METATYPE( QCPGraph::LineStyle ) /* end of 'src/plottables/plottable-graph.h' */ - /* including file 'src/plottables/plottable-curve.h', size 7409 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5272,21 +5480,20 @@ class QCP_LIB_DECL QCPCurveData { public: QCPCurveData(); - QCPCurveData(double t, double key, double value); - + QCPCurveData( double t, double key, double value ); + inline double sortKey() const { return t; } - inline static QCPCurveData fromSortKey(double sortKey) { return QCPCurveData(sortKey, 0, 0); } + inline static QCPCurveData fromSortKey( double sortKey ) { return QCPCurveData( sortKey, 0, 0 ); } inline static bool sortKeyIsMainKey() { return false; } - + inline double mainKey() const { return key; } inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } - + + inline QCPRange valueRange() const { return QCPRange( value, value ); } + double t, key, value; }; -Q_DECLARE_TYPEINFO(QCPCurveData, Q_PRIMITIVE_TYPE); - +Q_DECLARE_TYPEINFO( QCPCurveData, Q_PRIMITIVE_TYPE ); /*! \typedef QCPCurveDataContainer @@ -5304,9 +5511,9 @@ class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable1D { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle) - Q_PROPERTY(int scatterSkip READ scatterSkip WRITE setScatterSkip) - Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle) + Q_PROPERTY( QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle ) + Q_PROPERTY( int scatterSkip READ scatterSkip WRITE setScatterSkip ) + Q_PROPERTY( LineStyle lineStyle READ lineStyle WRITE setLineStyle ) /// \endcond public: /*! @@ -5314,72 +5521,74 @@ public: current pen of the curve (\ref setPen). \see setLineStyle */ - enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters) - ,lsLine ///< Data points are connected with a straight line - }; - Q_ENUMS(LineStyle) - - explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis); + enum LineStyle + { + lsNone ///< No line is drawn between data points (e.g. only scatters) + , + lsLine ///< Data points are connected with a straight line + }; + Q_ENUMS( LineStyle ) + + explicit QCPCurve( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPCurve(); - + // getters: QSharedPointer data() const { return mDataContainer; } QCPScatterStyle scatterStyle() const { return mScatterStyle; } int scatterSkip() const { return mScatterSkip; } LineStyle lineStyle() const { return mLineStyle; } - + // setters: - void setData(QSharedPointer data); - void setData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void setData(const QVector &keys, const QVector &values); - void setScatterStyle(const QCPScatterStyle &style); - void setScatterSkip(int skip); - void setLineStyle(LineStyle style); - + void setData( QSharedPointer data ); + void setData( const QVector& t, const QVector& keys, const QVector& values, bool alreadySorted = false ); + void setData( const QVector& keys, const QVector& values ); + void setScatterStyle( const QCPScatterStyle& style ); + void setScatterSkip( int skip ); + void setLineStyle( LineStyle style ); + // non-property methods: - void addData(const QVector &t, const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(const QVector &keys, const QVector &values); - void addData(double t, double key, double value); - void addData(double key, double value); - + void addData( const QVector& t, const QVector& keys, const QVector& values, bool alreadySorted = false ); + void addData( const QVector& keys, const QVector& values ); + void addData( double t, double key, double value ); + void addData( double key, double value ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + protected: // property members: QCPScatterStyle mScatterStyle; int mScatterSkip; LineStyle mLineStyle; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual void drawCurveLine(QCPPainter *painter, const QVector &lines) const; - virtual void drawScatterPlot(QCPPainter *painter, const QVector &points, const QCPScatterStyle &style) const; - + virtual void drawCurveLine( QCPPainter* painter, const QVector& lines ) const; + virtual void drawScatterPlot( QCPPainter* painter, const QVector& points, const QCPScatterStyle& style ) const; + // non-virtual methods: - void getCurveLines(QVector *lines, const QCPDataRange &dataRange, double penWidth) const; - void getScatters(QVector *scatters, const QCPDataRange &dataRange, double scatterWidth) const; - int getRegion(double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QPointF getOptimizedPoint(int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - QVector getOptimizedCornerPoints(int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin) const; - bool mayTraverse(int prevRegion, int currentRegion) const; - bool getTraverse(double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF &crossA, QPointF &crossB) const; - void getTraverseCornerPoints(int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector &beforeTraverse, QVector &afterTraverse) const; - double pointDistance(const QPointF &pixelPoint, QCPCurveDataContainer::const_iterator &closestData) const; - + void getCurveLines( QVector* lines, const QCPDataRange& dataRange, double penWidth ) const; + void getScatters( QVector* scatters, const QCPDataRange& dataRange, double scatterWidth ) const; + int getRegion( double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const; + QPointF getOptimizedPoint( int prevRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const; + QVector getOptimizedCornerPoints( int prevRegion, int currentRegion, double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin ) const; + bool mayTraverse( int prevRegion, int currentRegion ) const; + bool getTraverse( double prevKey, double prevValue, double key, double value, double keyMin, double valueMax, double keyMax, double valueMin, QPointF& crossA, QPointF& crossB ) const; + void getTraverseCornerPoints( int prevRegion, int currentRegion, double keyMin, double valueMax, double keyMax, double valueMin, QVector& beforeTraverse, QVector& afterTraverse ) const; + double pointDistance( const QPointF& pixelPoint, QCPCurveDataContainer::const_iterator& closestData ) const; + friend class QCustomPlot; friend class QCPLegend; }; -Q_DECLARE_METATYPE(QCPCurve::LineStyle) +Q_DECLARE_METATYPE( QCPCurve::LineStyle ) /* end of 'src/plottables/plottable-curve.h' */ - /* including file 'src/plottables/plottable-bars.h', size 8933 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5387,8 +5596,8 @@ class QCP_LIB_DECL QCPBarsGroup : public QObject { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(SpacingType spacingType READ spacingType WRITE setSpacingType) - Q_PROPERTY(double spacing READ spacing WRITE setSpacing) + Q_PROPERTY( SpacingType spacingType READ spacingType WRITE setSpacingType ) + Q_PROPERTY( double spacing READ spacing WRITE setSpacing ) /// \endcond public: /*! @@ -5397,76 +5606,78 @@ public: \see setSpacingType, setSpacing */ - enum SpacingType { stAbsolute ///< Bar spacing is in absolute pixels - ,stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size - ,stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(SpacingType) - - explicit QCPBarsGroup(QCustomPlot *parentPlot); + enum SpacingType + { + stAbsolute ///< Bar spacing is in absolute pixels + , + stAxisRectRatio ///< Bar spacing is given by a fraction of the axis rect size + , + stPlotCoords ///< Bar spacing is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS( SpacingType ) + + explicit QCPBarsGroup( QCustomPlot* parentPlot ); virtual ~QCPBarsGroup(); - + // getters: SpacingType spacingType() const { return mSpacingType; } double spacing() const { return mSpacing; } - + // setters: - void setSpacingType(SpacingType spacingType); - void setSpacing(double spacing); - + void setSpacingType( SpacingType spacingType ); + void setSpacing( double spacing ); + // non-virtual methods: QList bars() const { return mBars; } - QCPBars* bars(int index) const; + QCPBars* bars( int index ) const; int size() const { return mBars.size(); } bool isEmpty() const { return mBars.isEmpty(); } void clear(); - bool contains(QCPBars *bars) const { return mBars.contains(bars); } - void append(QCPBars *bars); - void insert(int i, QCPBars *bars); - void remove(QCPBars *bars); - + bool contains( QCPBars* bars ) const { return mBars.contains( bars ); } + void append( QCPBars* bars ); + void insert( int i, QCPBars* bars ); + void remove( QCPBars* bars ); + protected: // non-property members: - QCustomPlot *mParentPlot; + QCustomPlot* mParentPlot; SpacingType mSpacingType; double mSpacing; QList mBars; - + // non-virtual methods: - void registerBars(QCPBars *bars); - void unregisterBars(QCPBars *bars); - + void registerBars( QCPBars* bars ); + void unregisterBars( QCPBars* bars ); + // virtual methods: - double keyPixelOffset(const QCPBars *bars, double keyCoord); - double getPixelSpacing(const QCPBars *bars, double keyCoord); - + double keyPixelOffset( const QCPBars* bars, double keyCoord ); + double getPixelSpacing( const QCPBars* bars, double keyCoord ); + private: - Q_DISABLE_COPY(QCPBarsGroup) - + Q_DISABLE_COPY( QCPBarsGroup ) + friend class QCPBars; }; -Q_DECLARE_METATYPE(QCPBarsGroup::SpacingType) - +Q_DECLARE_METATYPE( QCPBarsGroup::SpacingType ) class QCP_LIB_DECL QCPBarsData { public: QCPBarsData(); - QCPBarsData(double key, double value); - + QCPBarsData( double key, double value ); + inline double sortKey() const { return key; } - inline static QCPBarsData fromSortKey(double sortKey) { return QCPBarsData(sortKey, 0); } - inline static bool sortKeyIsMainKey() { return true; } - + inline static QCPBarsData fromSortKey( double sortKey ) { return QCPBarsData( sortKey, 0 ); } + inline static bool sortKeyIsMainKey() { return true; } + inline double mainKey() const { return key; } inline double mainValue() const { return value; } - - inline QCPRange valueRange() const { return QCPRange(value, value); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here - + + inline QCPRange valueRange() const { return QCPRange( value, value ); } // note that bar base value isn't held in each QCPBarsData and thus can't/shouldn't be returned here + double key, value; }; -Q_DECLARE_TYPEINFO(QCPBarsData, Q_PRIMITIVE_TYPE); - +Q_DECLARE_TYPEINFO( QCPBarsData, Q_PRIMITIVE_TYPE ); /*! \typedef QCPBarsDataContainer @@ -5483,13 +5694,13 @@ class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable1D { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(double width READ width WRITE setWidth) - Q_PROPERTY(WidthType widthType READ widthType WRITE setWidthType) - Q_PROPERTY(QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup) - Q_PROPERTY(double baseValue READ baseValue WRITE setBaseValue) - Q_PROPERTY(double stackingGap READ stackingGap WRITE setStackingGap) - Q_PROPERTY(QCPBars* barBelow READ barBelow) - Q_PROPERTY(QCPBars* barAbove READ barAbove) + Q_PROPERTY( double width READ width WRITE setWidth ) + Q_PROPERTY( WidthType widthType READ widthType WRITE setWidthType ) + Q_PROPERTY( QCPBarsGroup* barsGroup READ barsGroup WRITE setBarsGroup ) + Q_PROPERTY( double baseValue READ baseValue WRITE setBaseValue ) + Q_PROPERTY( double stackingGap READ stackingGap WRITE setStackingGap ) + Q_PROPERTY( QCPBars* barBelow READ barBelow ) + Q_PROPERTY( QCPBars* barAbove READ barAbove ) /// \endcond public: /*! @@ -5498,76 +5709,79 @@ public: \see setWidthType, setWidth */ - enum WidthType { wtAbsolute ///< Bar width is in absolute pixels - ,wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size - ,wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range - }; - Q_ENUMS(WidthType) - - explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + enum WidthType + { + wtAbsolute ///< Bar width is in absolute pixels + , + wtAxisRectRatio ///< Bar width is given by a fraction of the axis rect size + , + wtPlotCoords ///< Bar width is in key coordinates and thus scales with the key axis range + }; + Q_ENUMS( WidthType ) + + explicit QCPBars( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPBars(); - + // getters: double width() const { return mWidth; } WidthType widthType() const { return mWidthType; } - QCPBarsGroup *barsGroup() const { return mBarsGroup; } + QCPBarsGroup* barsGroup() const { return mBarsGroup; } double baseValue() const { return mBaseValue; } double stackingGap() const { return mStackingGap; } - QCPBars *barBelow() const { return mBarBelow.data(); } - QCPBars *barAbove() const { return mBarAbove.data(); } + QCPBars* barBelow() const { return mBarBelow.data(); } + QCPBars* barAbove() const { return mBarAbove.data(); } QSharedPointer data() const { return mDataContainer; } - + // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setBarsGroup(QCPBarsGroup *barsGroup); - void setBaseValue(double baseValue); - void setStackingGap(double pixels); - + void setData( QSharedPointer data ); + void setData( const QVector& keys, const QVector& values, bool alreadySorted = false ); + void setWidth( double width ); + void setWidthType( WidthType widthType ); + void setBarsGroup( QCPBarsGroup* barsGroup ); + void setBaseValue( double baseValue ); + void setStackingGap( double pixels ); + // non-property methods: - void addData(const QVector &keys, const QVector &values, bool alreadySorted=false); - void addData(double key, double value); - void moveBelow(QCPBars *bars); - void moveAbove(QCPBars *bars); - + void addData( const QVector& keys, const QVector& values, bool alreadySorted = false ); + void addData( double key, double value ); + void moveBelow( QCPBars* bars ); + void moveAbove( QCPBars* bars ); + // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; - + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const Q_DECL_OVERRIDE; + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition( int index ) const Q_DECL_OVERRIDE; + protected: // property members: double mWidth; WidthType mWidthType; - QCPBarsGroup *mBarsGroup; + QCPBarsGroup* mBarsGroup; double mBaseValue; double mStackingGap; QPointer mBarBelow, mBarAbove; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + // non-virtual methods: - void getVisibleDataBounds(QCPBarsDataContainer::const_iterator &begin, QCPBarsDataContainer::const_iterator &end) const; - QRectF getBarRect(double key, double value) const; - void getPixelWidth(double key, double &lower, double &upper) const; - double getStackedBaseValue(double key, bool positive) const; - static void connectBars(QCPBars* lower, QCPBars* upper); - + void getVisibleDataBounds( QCPBarsDataContainer::const_iterator& begin, QCPBarsDataContainer::const_iterator& end ) const; + QRectF getBarRect( double key, double value ) const; + void getPixelWidth( double key, double& lower, double& upper ) const; + double getStackedBaseValue( double key, bool positive ) const; + static void connectBars( QCPBars* lower, QCPBars* upper ); + friend class QCustomPlot; friend class QCPLegend; friend class QCPBarsGroup; }; -Q_DECLARE_METATYPE(QCPBars::WidthType) +Q_DECLARE_METATYPE( QCPBars::WidthType ) /* end of 'src/plottables/plottable-bars.h' */ - /* including file 'src/plottables/plottable-statisticalbox.h', size 7516 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5575,28 +5789,27 @@ class QCP_LIB_DECL QCPStatisticalBoxData { public: QCPStatisticalBoxData(); - QCPStatisticalBoxData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers=QVector()); - + QCPStatisticalBoxData( double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers = QVector() ); + inline double sortKey() const { return key; } - inline static QCPStatisticalBoxData fromSortKey(double sortKey) { return QCPStatisticalBoxData(sortKey, 0, 0, 0, 0, 0); } + inline static QCPStatisticalBoxData fromSortKey( double sortKey ) { return QCPStatisticalBoxData( sortKey, 0, 0, 0, 0, 0 ); } inline static bool sortKeyIsMainKey() { return true; } - + inline double mainKey() const { return key; } inline double mainValue() const { return median; } - + inline QCPRange valueRange() const { - QCPRange result(minimum, maximum); - for (QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it) - result.expand(*it); + QCPRange result( minimum, maximum ); + for( QVector::const_iterator it = outliers.constBegin(); it != outliers.constEnd(); ++it ) + result.expand( *it ); return result; } - + double key, minimum, lowerQuartile, median, upperQuartile, maximum; QVector outliers; }; -Q_DECLARE_TYPEINFO(QCPStatisticalBoxData, Q_MOVABLE_TYPE); - +Q_DECLARE_TYPEINFO( QCPStatisticalBoxData, Q_MOVABLE_TYPE ); /*! \typedef QCPStatisticalBoxDataContainer @@ -5614,17 +5827,17 @@ class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D data() const { return mDataContainer; } double width() const { return mWidth; } @@ -5636,26 +5849,26 @@ public: QCPScatterStyle outlierStyle() const { return mOutlierStyle; } // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void setWidth(double width); - void setWhiskerWidth(double width); - void setWhiskerPen(const QPen &pen); - void setWhiskerBarPen(const QPen &pen); - void setWhiskerAntialiased(bool enabled); - void setMedianPen(const QPen &pen); - void setOutlierStyle(const QCPScatterStyle &style); - + void setData( QSharedPointer data ); + void setData( const QVector& keys, const QVector& minimum, const QVector& lowerQuartile, const QVector& median, const QVector& upperQuartile, const QVector& maximum, bool alreadySorted = false ); + void setWidth( double width ); + void setWhiskerWidth( double width ); + void setWhiskerPen( const QPen& pen ); + void setWhiskerBarPen( const QPen& pen ); + void setWhiskerAntialiased( bool enabled ); + void setMedianPen( const QPen& pen ); + void setOutlierStyle( const QCPScatterStyle& style ); + // non-property methods: - void addData(const QVector &keys, const QVector &minimum, const QVector &lowerQuartile, const QVector &median, const QVector &upperQuartile, const QVector &maximum, bool alreadySorted=false); - void addData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector &outliers=QVector()); - + void addData( const QVector& keys, const QVector& minimum, const QVector& lowerQuartile, const QVector& median, const QVector& upperQuartile, const QVector& maximum, bool alreadySorted = false ); + void addData( double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum, const QVector& outliers = QVector() ); + // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const Q_DECL_OVERRIDE; + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + protected: // property members: double mWidth; @@ -5664,163 +5877,160 @@ protected: bool mWhiskerAntialiased; QPen mMedianPen; QCPScatterStyle mOutlierStyle; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + // introduced virtual methods: - virtual void drawStatisticalBox(QCPPainter *painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle &outlierStyle) const; - + virtual void drawStatisticalBox( QCPPainter* painter, QCPStatisticalBoxDataContainer::const_iterator it, const QCPScatterStyle& outlierStyle ) const; + // non-virtual methods: - void getVisibleDataBounds(QCPStatisticalBoxDataContainer::const_iterator &begin, QCPStatisticalBoxDataContainer::const_iterator &end) const; - QRectF getQuartileBox(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBackboneLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - QVector getWhiskerBarLines(QCPStatisticalBoxDataContainer::const_iterator it) const; - + void getVisibleDataBounds( QCPStatisticalBoxDataContainer::const_iterator& begin, QCPStatisticalBoxDataContainer::const_iterator& end ) const; + QRectF getQuartileBox( QCPStatisticalBoxDataContainer::const_iterator it ) const; + QVector getWhiskerBackboneLines( QCPStatisticalBoxDataContainer::const_iterator it ) const; + QVector getWhiskerBarLines( QCPStatisticalBoxDataContainer::const_iterator it ) const; + friend class QCustomPlot; friend class QCPLegend; }; /* end of 'src/plottables/plottable-statisticalbox.h' */ - /* including file 'src/plottables/plottable-colormap.h', size 7070 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ class QCP_LIB_DECL QCPColorMapData { public: - QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange); + QCPColorMapData( int keySize, int valueSize, const QCPRange& keyRange, const QCPRange& valueRange ); ~QCPColorMapData(); - QCPColorMapData(const QCPColorMapData &other); - QCPColorMapData &operator=(const QCPColorMapData &other); - + QCPColorMapData( const QCPColorMapData& other ); + QCPColorMapData& operator=( const QCPColorMapData& other ); + // getters: int keySize() const { return mKeySize; } int valueSize() const { return mValueSize; } QCPRange keyRange() const { return mKeyRange; } QCPRange valueRange() const { return mValueRange; } QCPRange dataBounds() const { return mDataBounds; } - double data(double key, double value); - double cell(int keyIndex, int valueIndex); - unsigned char alpha(int keyIndex, int valueIndex); - + double data( double key, double value ); + double cell( int keyIndex, int valueIndex ); + unsigned char alpha( int keyIndex, int valueIndex ); + // setters: - void setSize(int keySize, int valueSize); - void setKeySize(int keySize); - void setValueSize(int valueSize); - void setRange(const QCPRange &keyRange, const QCPRange &valueRange); - void setKeyRange(const QCPRange &keyRange); - void setValueRange(const QCPRange &valueRange); - void setData(double key, double value, double z); - void setCell(int keyIndex, int valueIndex, double z); - void setAlpha(int keyIndex, int valueIndex, unsigned char alpha); - + void setSize( int keySize, int valueSize ); + void setKeySize( int keySize ); + void setValueSize( int valueSize ); + void setRange( const QCPRange& keyRange, const QCPRange& valueRange ); + void setKeyRange( const QCPRange& keyRange ); + void setValueRange( const QCPRange& valueRange ); + void setData( double key, double value, double z ); + void setCell( int keyIndex, int valueIndex, double z ); + void setAlpha( int keyIndex, int valueIndex, unsigned char alpha ); + // non-property methods: void recalculateDataBounds(); void clear(); void clearAlpha(); - void fill(double z); - void fillAlpha(unsigned char alpha); + void fill( double z ); + void fillAlpha( unsigned char alpha ); bool isEmpty() const { return mIsEmpty; } - void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const; - void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const; - + void coordToCell( double key, double value, int* keyIndex, int* valueIndex ) const; + void cellToCoord( int keyIndex, int valueIndex, double* key, double* value ) const; + protected: // property members: int mKeySize, mValueSize; QCPRange mKeyRange, mValueRange; bool mIsEmpty; - + // non-property members: - double *mData; - unsigned char *mAlpha; + double* mData; + unsigned char* mAlpha; QCPRange mDataBounds; bool mDataModified; - - bool createAlpha(bool initializeOpaque=true); - + + bool createAlpha( bool initializeOpaque = true ); + friend class QCPColorMap; }; - class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged) - Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged) - Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged) - Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate) - Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary) - Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale) + Q_PROPERTY( QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged ) + Q_PROPERTY( QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged ) + Q_PROPERTY( QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged ) + Q_PROPERTY( bool interpolate READ interpolate WRITE setInterpolate ) + Q_PROPERTY( bool tightBoundary READ tightBoundary WRITE setTightBoundary ) + Q_PROPERTY( QCPColorScale* colorScale READ colorScale WRITE setColorScale ) /// \endcond public: - explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis); + explicit QCPColorMap( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPColorMap(); - + // getters: - QCPColorMapData *data() const { return mMapData; } + QCPColorMapData* data() const { return mMapData; } QCPRange dataRange() const { return mDataRange; } QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; } bool interpolate() const { return mInterpolate; } bool tightBoundary() const { return mTightBoundary; } QCPColorGradient gradient() const { return mGradient; } - QCPColorScale *colorScale() const { return mColorScale.data(); } - + QCPColorScale* colorScale() const { return mColorScale.data(); } + // setters: - void setData(QCPColorMapData *data, bool copy=false); - Q_SLOT void setDataRange(const QCPRange &dataRange); - Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType); - Q_SLOT void setGradient(const QCPColorGradient &gradient); - void setInterpolate(bool enabled); - void setTightBoundary(bool enabled); - void setColorScale(QCPColorScale *colorScale); - + void setData( QCPColorMapData* data, bool copy = false ); + Q_SLOT void setDataRange( const QCPRange& dataRange ); + Q_SLOT void setDataScaleType( QCPAxis::ScaleType scaleType ); + Q_SLOT void setGradient( const QCPColorGradient& gradient ); + void setInterpolate( bool enabled ); + void setTightBoundary( bool enabled ); + void setColorScale( QCPColorScale* colorScale ); + // non-property methods: - void rescaleDataRange(bool recalculateDataBounds=false); - Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18)); - + void rescaleDataRange( bool recalculateDataBounds = false ); + Q_SLOT void updateLegendIcon( Qt::TransformationMode transformMode = Qt::SmoothTransformation, const QSize& thumbSize = QSize( 32, 18 ) ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + signals: - void dataRangeChanged(const QCPRange &newRange); - void dataScaleTypeChanged(QCPAxis::ScaleType scaleType); - void gradientChanged(const QCPColorGradient &newGradient); - + void dataRangeChanged( const QCPRange& newRange ); + void dataScaleTypeChanged( QCPAxis::ScaleType scaleType ); + void gradientChanged( const QCPColorGradient& newGradient ); + protected: // property members: QCPRange mDataRange; QCPAxis::ScaleType mDataScaleType; - QCPColorMapData *mMapData; + QCPColorMapData* mMapData; QCPColorGradient mGradient; bool mInterpolate; bool mTightBoundary; QPointer mColorScale; - + // non-property members: QImage mMapImage, mUndersampledMapImage; QPixmap mLegendIcon; bool mMapImageInvalidated; - + // introduced virtual methods: virtual void updateMapImage(); - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + friend class QCustomPlot; friend class QCPLegend; }; /* end of 'src/plottables/plottable-colormap.h' */ - /* including file 'src/plottables/plottable-financial.h', size 8622 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5828,21 +6038,20 @@ class QCP_LIB_DECL QCPFinancialData { public: QCPFinancialData(); - QCPFinancialData(double key, double open, double high, double low, double close); - + QCPFinancialData( double key, double open, double high, double low, double close ); + inline double sortKey() const { return key; } - inline static QCPFinancialData fromSortKey(double sortKey) { return QCPFinancialData(sortKey, 0, 0, 0, 0); } - inline static bool sortKeyIsMainKey() { return true; } - + inline static QCPFinancialData fromSortKey( double sortKey ) { return QCPFinancialData( sortKey, 0, 0, 0, 0 ); } + inline static bool sortKeyIsMainKey() { return true; } + inline double mainKey() const { return key; } inline double mainValue() const { return open; } - - inline QCPRange valueRange() const { return QCPRange(low, high); } // open and close must lie between low and high, so we don't need to check them - + + inline QCPRange valueRange() const { return QCPRange( low, high ); } // open and close must lie between low and high, so we don't need to check them + double key, open, high, low, close; }; -Q_DECLARE_TYPEINFO(QCPFinancialData, Q_PRIMITIVE_TYPE); - +Q_DECLARE_TYPEINFO( QCPFinancialData, Q_PRIMITIVE_TYPE ); /*! \typedef QCPFinancialDataContainer @@ -5859,14 +6068,14 @@ class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D data() const { return mDataContainer; } ChartStyle chartStyle() const { return mChartStyle; } @@ -5904,32 +6120,32 @@ public: QBrush brushNegative() const { return mBrushNegative; } QPen penPositive() const { return mPenPositive; } QPen penNegative() const { return mPenNegative; } - + // setters: - void setData(QSharedPointer data); - void setData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void setChartStyle(ChartStyle style); - void setWidth(double width); - void setWidthType(WidthType widthType); - void setTwoColored(bool twoColored); - void setBrushPositive(const QBrush &brush); - void setBrushNegative(const QBrush &brush); - void setPenPositive(const QPen &pen); - void setPenNegative(const QPen &pen); - + void setData( QSharedPointer data ); + void setData( const QVector& keys, const QVector& open, const QVector& high, const QVector& low, const QVector& close, bool alreadySorted = false ); + void setChartStyle( ChartStyle style ); + void setWidth( double width ); + void setWidthType( WidthType widthType ); + void setTwoColored( bool twoColored ); + void setBrushPositive( const QBrush& brush ); + void setBrushNegative( const QBrush& brush ); + void setPenPositive( const QPen& pen ); + void setPenNegative( const QPen& pen ); + // non-property methods: - void addData(const QVector &keys, const QVector &open, const QVector &high, const QVector &low, const QVector &close, bool alreadySorted=false); - void addData(double key, double open, double high, double low, double close); - + void addData( const QVector& keys, const QVector& open, const QVector& high, const QVector& low, const QVector& close, bool alreadySorted = false ); + void addData( double key, double open, double high, double low, double close ); + // reimplemented virtual methods: - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const Q_DECL_OVERRIDE; + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + // static methods: - static QCPFinancialDataContainer timeSeriesToOhlc(const QVector &time, const QVector &value, double timeBinSize, double timeBinOffset = 0); - + static QCPFinancialDataContainer timeSeriesToOhlc( const QVector& time, const QVector& value, double timeBinSize, double timeBinOffset = 0 ); + protected: // property members: ChartStyle mChartStyle; @@ -5938,28 +6154,27 @@ protected: bool mTwoColored; QBrush mBrushPositive, mBrushNegative; QPen mPenPositive, mPenNegative; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + // non-virtual methods: - void drawOhlcPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - void drawCandlestickPlot(QCPPainter *painter, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, bool isSelected); - double getPixelWidth(double key, double keyPixel) const; - double ohlcSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - double candlestickSelectTest(const QPointF &pos, const QCPFinancialDataContainer::const_iterator &begin, const QCPFinancialDataContainer::const_iterator &end, QCPFinancialDataContainer::const_iterator &closestDataPoint) const; - void getVisibleDataBounds(QCPFinancialDataContainer::const_iterator &begin, QCPFinancialDataContainer::const_iterator &end) const; - QRectF selectionHitBox(QCPFinancialDataContainer::const_iterator it) const; - + void drawOhlcPlot( QCPPainter* painter, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, bool isSelected ); + void drawCandlestickPlot( QCPPainter* painter, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, bool isSelected ); + double getPixelWidth( double key, double keyPixel ) const; + double ohlcSelectTest( const QPointF& pos, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, QCPFinancialDataContainer::const_iterator& closestDataPoint ) const; + double candlestickSelectTest( const QPointF& pos, const QCPFinancialDataContainer::const_iterator& begin, const QCPFinancialDataContainer::const_iterator& end, QCPFinancialDataContainer::const_iterator& closestDataPoint ) const; + void getVisibleDataBounds( QCPFinancialDataContainer::const_iterator& begin, QCPFinancialDataContainer::const_iterator& end ) const; + QRectF selectionHitBox( QCPFinancialDataContainer::const_iterator it ) const; + friend class QCustomPlot; friend class QCPLegend; }; -Q_DECLARE_METATYPE(QCPFinancial::ChartStyle) +Q_DECLARE_METATYPE( QCPFinancial::ChartStyle ) /* end of 'src/plottables/plottable-financial.h' */ - /* including file 'src/plottables/plottable-errorbar.h', size 7727 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -5967,13 +6182,12 @@ class QCP_LIB_DECL QCPErrorBarsData { public: QCPErrorBarsData(); - explicit QCPErrorBarsData(double error); - QCPErrorBarsData(double errorMinus, double errorPlus); - + explicit QCPErrorBarsData( double error ); + QCPErrorBarsData( double errorMinus, double errorPlus ); + double errorMinus, errorPlus; }; -Q_DECLARE_TYPEINFO(QCPErrorBarsData, Q_PRIMITIVE_TYPE); - +Q_DECLARE_TYPEINFO( QCPErrorBarsData, Q_PRIMITIVE_TYPE ); /*! \typedef QCPErrorBarsDataContainer @@ -5996,65 +6210,67 @@ class QCP_LIB_DECL QCPErrorBars : public QCPAbstractPlottable, public QCPPlottab { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QSharedPointer data READ data WRITE setData) - Q_PROPERTY(QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable) - Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType) - Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth) - Q_PROPERTY(double symbolGap READ symbolGap WRITE setSymbolGap) + Q_PROPERTY( QSharedPointer data READ data WRITE setData ) + Q_PROPERTY( QCPAbstractPlottable* dataPlottable READ dataPlottable WRITE setDataPlottable ) + Q_PROPERTY( ErrorType errorType READ errorType WRITE setErrorType ) + Q_PROPERTY( double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth ) + Q_PROPERTY( double symbolGap READ symbolGap WRITE setSymbolGap ) /// \endcond public: - /*! Defines in which orientation the error bars shall appear. If your data needs both error dimensions, create two \ref QCPErrorBars with different \ref ErrorType. \see setErrorType */ - enum ErrorType { etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) - ,etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) + enum ErrorType + { + etKeyError ///< The errors are for the key dimension (bars appear parallel to the key axis) + , + etValueError ///< The errors are for the value dimension (bars appear parallel to the value axis) }; - Q_ENUMS(ErrorType) - - explicit QCPErrorBars(QCPAxis *keyAxis, QCPAxis *valueAxis); + Q_ENUMS( ErrorType ) + + explicit QCPErrorBars( QCPAxis* keyAxis, QCPAxis* valueAxis ); virtual ~QCPErrorBars(); // getters: QSharedPointer data() const { return mDataContainer; } - QCPAbstractPlottable *dataPlottable() const { return mDataPlottable.data(); } + QCPAbstractPlottable* dataPlottable() const { return mDataPlottable.data(); } ErrorType errorType() const { return mErrorType; } double whiskerWidth() const { return mWhiskerWidth; } double symbolGap() const { return mSymbolGap; } - + // setters: - void setData(QSharedPointer data); - void setData(const QVector &error); - void setData(const QVector &errorMinus, const QVector &errorPlus); - void setDataPlottable(QCPAbstractPlottable* plottable); - void setErrorType(ErrorType type); - void setWhiskerWidth(double pixels); - void setSymbolGap(double pixels); - + void setData( QSharedPointer data ); + void setData( const QVector& error ); + void setData( const QVector& errorMinus, const QVector& errorPlus ); + void setDataPlottable( QCPAbstractPlottable* plottable ); + void setErrorType( ErrorType type ); + void setWhiskerWidth( double pixels ); + void setSymbolGap( double pixels ); + // non-property methods: - void addData(const QVector &error); - void addData(const QVector &errorMinus, const QVector &errorPlus); - void addData(double error); - void addData(double errorMinus, double errorPlus); - + void addData( const QVector& error ); + void addData( const QVector& errorMinus, const QVector& errorPlus ); + void addData( double error ); + void addData( double errorMinus, double errorPlus ); + // virtual methods of 1d plottable interface: virtual int dataCount() const Q_DECL_OVERRIDE; - virtual double dataMainKey(int index) const Q_DECL_OVERRIDE; - virtual double dataSortKey(int index) const Q_DECL_OVERRIDE; - virtual double dataMainValue(int index) const Q_DECL_OVERRIDE; - virtual QCPRange dataValueRange(int index) const Q_DECL_OVERRIDE; - virtual QPointF dataPixelPosition(int index) const Q_DECL_OVERRIDE; + virtual double dataMainKey( int index ) const Q_DECL_OVERRIDE; + virtual double dataSortKey( int index ) const Q_DECL_OVERRIDE; + virtual double dataMainValue( int index ) const Q_DECL_OVERRIDE; + virtual QCPRange dataValueRange( int index ) const Q_DECL_OVERRIDE; + virtual QPointF dataPixelPosition( int index ) const Q_DECL_OVERRIDE; virtual bool sortKeyIsMainKey() const Q_DECL_OVERRIDE; - virtual QCPDataSelection selectTestRect(const QRectF &rect, bool onlySelectable) const Q_DECL_OVERRIDE; - virtual int findBegin(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - virtual int findEnd(double sortKey, bool expandedRange=true) const Q_DECL_OVERRIDE; - + virtual QCPDataSelection selectTestRect( const QRectF& rect, bool onlySelectable ) const Q_DECL_OVERRIDE; + virtual int findBegin( double sortKey, bool expandedRange = true ) const Q_DECL_OVERRIDE; + virtual int findEnd( double sortKey, bool expandedRange = true ) const Q_DECL_OVERRIDE; + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D* interface1D() Q_DECL_OVERRIDE { return this; } + protected: // property members: QSharedPointer mDataContainer; @@ -6062,29 +6278,28 @@ protected: ErrorType mErrorType; double mWhiskerWidth; double mSymbolGap; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const Q_DECL_OVERRIDE; - virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const Q_DECL_OVERRIDE; - virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const Q_DECL_OVERRIDE; + virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const Q_DECL_OVERRIDE; + virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const Q_DECL_OVERRIDE; + // non-virtual methods: - void getErrorBarLines(QCPErrorBarsDataContainer::const_iterator it, QVector &backbones, QVector &whiskers) const; - void getVisibleDataBounds(QCPErrorBarsDataContainer::const_iterator &begin, QCPErrorBarsDataContainer::const_iterator &end, const QCPDataRange &rangeRestriction) const; - double pointDistance(const QPointF &pixelPoint, QCPErrorBarsDataContainer::const_iterator &closestData) const; + void getErrorBarLines( QCPErrorBarsDataContainer::const_iterator it, QVector& backbones, QVector& whiskers ) const; + void getVisibleDataBounds( QCPErrorBarsDataContainer::const_iterator& begin, QCPErrorBarsDataContainer::const_iterator& end, const QCPDataRange& rangeRestriction ) const; + double pointDistance( const QPointF& pixelPoint, QCPErrorBarsDataContainer::const_iterator& closestData ) const; // helpers: - void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; - bool errorBarVisible(int index) const; - bool rectIntersectsLine(const QRectF &pixelRect, const QLineF &line) const; - + void getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const; + bool errorBarVisible( int index ) const; + bool rectIntersectsLine( const QRectF& pixelRect, const QLineF& line ) const; + friend class QCustomPlot; friend class QCPLegend; }; /* end of 'src/plottables/plottable-errorbar.h' */ - /* including file 'src/items/item-straightline.h', size 3117 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6092,42 +6307,41 @@ class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) /// \endcond public: - explicit QCPItemStraightLine(QCustomPlot *parentPlot); + explicit QCPItemStraightLine( QCustomPlot* parentPlot ); virtual ~QCPItemStraightLine(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const point1; - QCPItemPosition * const point2; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const point1; + QCPItemPosition* const point2; + protected: // property members: QPen mPen, mSelectedPen; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + // non-virtual methods: - QLineF getRectClippedStraightLine(const QCPVector2D &point1, const QCPVector2D &vec, const QRect &rect) const; + QLineF getRectClippedStraightLine( const QCPVector2D& point1, const QCPVector2D& vec, const QRect& rect ) const; QPen mainPen() const; }; /* end of 'src/items/item-straightline.h' */ - /* including file 'src/items/item-line.h', size 3407 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6135,49 +6349,48 @@ class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QCPLineEnding head READ head WRITE setHead ) + Q_PROPERTY( QCPLineEnding tail READ tail WRITE setTail ) /// \endcond public: - explicit QCPItemLine(QCustomPlot *parentPlot); + explicit QCPItemLine( QCustomPlot* parentPlot ); virtual ~QCPItemLine(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } QCPLineEnding head() const { return mHead; } QCPLineEnding tail() const { return mTail; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setHead( const QCPLineEnding& head ); + void setTail( const QCPLineEnding& tail ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const end; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const start; + QCPItemPosition* const end; + protected: // property members: QPen mPen, mSelectedPen; QCPLineEnding mHead, mTail; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + // non-virtual methods: - QLineF getRectClippedLine(const QCPVector2D &start, const QCPVector2D &end, const QRect &rect) const; + QLineF getRectClippedLine( const QCPVector2D& start, const QCPVector2D& end, const QRect& rect ) const; QPen mainPen() const; }; /* end of 'src/items/item-line.h' */ - /* including file 'src/items/item-curve.h', size 3379 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6185,50 +6398,49 @@ class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QCPLineEnding head READ head WRITE setHead) - Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QCPLineEnding head READ head WRITE setHead ) + Q_PROPERTY( QCPLineEnding tail READ tail WRITE setTail ) /// \endcond public: - explicit QCPItemCurve(QCustomPlot *parentPlot); + explicit QCPItemCurve( QCustomPlot* parentPlot ); virtual ~QCPItemCurve(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } QCPLineEnding head() const { return mHead; } QCPLineEnding tail() const { return mTail; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setHead(const QCPLineEnding &head); - void setTail(const QCPLineEnding &tail); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setHead( const QCPLineEnding& head ); + void setTail( const QCPLineEnding& tail ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const start; - QCPItemPosition * const startDir; - QCPItemPosition * const endDir; - QCPItemPosition * const end; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const start; + QCPItemPosition* const startDir; + QCPItemPosition* const endDir; + QCPItemPosition* const end; + protected: // property members: QPen mPen, mSelectedPen; QCPLineEnding mHead, mTail; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + // non-virtual methods: QPen mainPen() const; }; /* end of 'src/items/item-curve.h' */ - /* including file 'src/items/item-rect.h', size 3688 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6236,50 +6448,58 @@ class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush ) /// \endcond public: - explicit QCPItemRect(QCustomPlot *parentPlot); + explicit QCPItemRect( QCustomPlot* parentPlot ); virtual ~QCPItemRect(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } QBrush brush() const { return mBrush; } QBrush selectedBrush() const { return mSelectedBrush; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setSelectedBrush( const QBrush& brush ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const topLeft; + QCPItemPosition* const bottomRight; + QCPItemAnchor* const top; + QCPItemAnchor* const topRight; + QCPItemAnchor* const right; + QCPItemAnchor* const bottom; + QCPItemAnchor* const bottomLeft; + QCPItemAnchor* const left; + protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - + enum AnchorIndex + { + aiTop, + aiTopRight, + aiRight, + aiBottom, + aiBottomLeft, + aiLeft + }; + // property members: QPen mPen, mSelectedPen; QBrush mBrush, mSelectedBrush; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition( int anchorId ) const Q_DECL_OVERRIDE; + // non-virtual methods: QPen mainPen() const; QBrush mainBrush() const; @@ -6287,7 +6507,6 @@ protected: /* end of 'src/items/item-rect.h' */ - /* including file 'src/items/item-text.h', size 5554 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6295,24 +6514,24 @@ class QCP_LIB_DECL QCPItemText : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(QFont font READ font WRITE setFont) - Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont) - Q_PROPERTY(QString text READ text WRITE setText) - Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment) - Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment) - Q_PROPERTY(double rotation READ rotation WRITE setRotation) - Q_PROPERTY(QMargins padding READ padding WRITE setPadding) + Q_PROPERTY( QColor color READ color WRITE setColor ) + Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor ) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush ) + Q_PROPERTY( QFont font READ font WRITE setFont ) + Q_PROPERTY( QFont selectedFont READ selectedFont WRITE setSelectedFont ) + Q_PROPERTY( QString text READ text WRITE setText ) + Q_PROPERTY( Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment ) + Q_PROPERTY( Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment ) + Q_PROPERTY( double rotation READ rotation WRITE setRotation ) + Q_PROPERTY( QMargins padding READ padding WRITE setPadding ) /// \endcond public: - explicit QCPItemText(QCustomPlot *parentPlot); + explicit QCPItemText( QCustomPlot* parentPlot ); virtual ~QCPItemText(); - + // getters: QColor color() const { return mColor; } QColor selectedColor() const { return mSelectedColor; } @@ -6327,38 +6546,48 @@ public: Qt::Alignment textAlignment() const { return mTextAlignment; } double rotation() const { return mRotation; } QMargins padding() const { return mPadding; } - + // setters; - void setColor(const QColor &color); - void setSelectedColor(const QColor &color); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setFont(const QFont &font); - void setSelectedFont(const QFont &font); - void setText(const QString &text); - void setPositionAlignment(Qt::Alignment alignment); - void setTextAlignment(Qt::Alignment alignment); - void setRotation(double degrees); - void setPadding(const QMargins &padding); - + void setColor( const QColor& color ); + void setSelectedColor( const QColor& color ); + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setSelectedBrush( const QBrush& brush ); + void setFont( const QFont& font ); + void setSelectedFont( const QFont& font ); + void setText( const QString& text ); + void setPositionAlignment( Qt::Alignment alignment ); + void setTextAlignment( Qt::Alignment alignment ); + void setRotation( double degrees ); + void setPadding( const QMargins& padding ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const position; - QCPItemAnchor * const topLeft; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRight; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const position; + QCPItemAnchor* const topLeft; + QCPItemAnchor* const top; + QCPItemAnchor* const topRight; + QCPItemAnchor* const right; + QCPItemAnchor* const bottomRight; + QCPItemAnchor* const bottom; + QCPItemAnchor* const bottomLeft; + QCPItemAnchor* const left; + protected: - enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft}; - + enum AnchorIndex + { + aiTopLeft, + aiTop, + aiTopRight, + aiRight, + aiBottomRight, + aiBottom, + aiBottomLeft, + aiLeft + }; + // property members: QColor mColor, mSelectedColor; QPen mPen, mSelectedPen; @@ -6369,13 +6598,13 @@ protected: Qt::Alignment mTextAlignment; double mRotation; QMargins mPadding; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition( int anchorId ) const Q_DECL_OVERRIDE; + // non-virtual methods: - QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const; + QPointF getTextDrawPoint( const QPointF& pos, const QRectF& rect, Qt::Alignment positionAlignment ) const; QFont mainFont() const; QColor mainColor() const; QPen mainPen() const; @@ -6384,7 +6613,6 @@ protected: /* end of 'src/items/item-text.h' */ - /* including file 'src/items/item-ellipse.h', size 3868 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6392,53 +6620,64 @@ class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush ) /// \endcond public: - explicit QCPItemEllipse(QCustomPlot *parentPlot); + explicit QCPItemEllipse( QCustomPlot* parentPlot ); virtual ~QCPItemEllipse(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } QBrush brush() const { return mBrush; } QBrush selectedBrush() const { return mSelectedBrush; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setSelectedBrush( const QBrush& brush ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const topLeftRim; - QCPItemAnchor * const top; - QCPItemAnchor * const topRightRim; - QCPItemAnchor * const right; - QCPItemAnchor * const bottomRightRim; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeftRim; - QCPItemAnchor * const left; - QCPItemAnchor * const center; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const topLeft; + QCPItemPosition* const bottomRight; + QCPItemAnchor* const topLeftRim; + QCPItemAnchor* const top; + QCPItemAnchor* const topRightRim; + QCPItemAnchor* const right; + QCPItemAnchor* const bottomRightRim; + QCPItemAnchor* const bottom; + QCPItemAnchor* const bottomLeftRim; + QCPItemAnchor* const left; + QCPItemAnchor* const center; + protected: - enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter}; - + enum AnchorIndex + { + aiTopLeftRim, + aiTop, + aiTopRightRim, + aiRight, + aiBottomRightRim, + aiBottom, + aiBottomLeftRim, + aiLeft, + aiCenter + }; + // property members: QPen mPen, mSelectedPen; QBrush mBrush, mSelectedBrush; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition( int anchorId ) const Q_DECL_OVERRIDE; + // non-virtual methods: QPen mainPen() const; QBrush mainBrush() const; @@ -6446,7 +6685,6 @@ protected: /* end of 'src/items/item-ellipse.h' */ - /* including file 'src/items/item-pixmap.h', size 4373 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6454,17 +6692,17 @@ class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) - Q_PROPERTY(bool scaled READ scaled WRITE setScaled) - Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode) - Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode) - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) + Q_PROPERTY( QPixmap pixmap READ pixmap WRITE setPixmap ) + Q_PROPERTY( bool scaled READ scaled WRITE setScaled ) + Q_PROPERTY( Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode ) + Q_PROPERTY( Qt::TransformationMode transformationMode READ transformationMode ) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) /// \endcond public: - explicit QCPItemPixmap(QCustomPlot *parentPlot); + explicit QCPItemPixmap( QCustomPlot* parentPlot ); virtual ~QCPItemPixmap(); - + // getters: QPixmap pixmap() const { return mPixmap; } bool scaled() const { return mScaled; } @@ -6472,28 +6710,36 @@ public: Qt::TransformationMode transformationMode() const { return mTransformationMode; } QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } - + // setters; - void setPixmap(const QPixmap &pixmap); - void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio, Qt::TransformationMode transformationMode=Qt::SmoothTransformation); - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - + void setPixmap( const QPixmap& pixmap ); + void setScaled( bool scaled, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio, Qt::TransformationMode transformationMode = Qt::SmoothTransformation ); + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const topLeft; - QCPItemPosition * const bottomRight; - QCPItemAnchor * const top; - QCPItemAnchor * const topRight; - QCPItemAnchor * const right; - QCPItemAnchor * const bottom; - QCPItemAnchor * const bottomLeft; - QCPItemAnchor * const left; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const topLeft; + QCPItemPosition* const bottomRight; + QCPItemAnchor* const top; + QCPItemAnchor* const topRight; + QCPItemAnchor* const right; + QCPItemAnchor* const bottom; + QCPItemAnchor* const bottomLeft; + QCPItemAnchor* const left; + protected: - enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft}; - + enum AnchorIndex + { + aiTop, + aiTopRight, + aiRight, + aiBottom, + aiBottomLeft, + aiLeft + }; + // property members: QPixmap mPixmap; QPixmap mScaledPixmap; @@ -6502,20 +6748,19 @@ protected: Qt::AspectRatioMode mAspectRatioMode; Qt::TransformationMode mTransformationMode; QPen mPen, mSelectedPen; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition( int anchorId ) const Q_DECL_OVERRIDE; + // non-virtual methods: - void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); - QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const; + void updateScaledPixmap( QRect finalRect = QRect(), bool flipHorz = false, bool flipVert = false ); + QRect getFinalRect( bool* flippedHorz = 0, bool* flippedVert = 0 ) const; QPen mainPen() const; }; /* end of 'src/items/item-pixmap.h' */ - /* including file 'src/items/item-tracer.h', size 4762 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6523,15 +6768,15 @@ class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(QBrush brush READ brush WRITE setBrush) - Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush) - Q_PROPERTY(double size READ size WRITE setSize) - Q_PROPERTY(TracerStyle style READ style WRITE setStyle) - Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph) - Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey) - Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( QBrush brush READ brush WRITE setBrush ) + Q_PROPERTY( QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush ) + Q_PROPERTY( double size READ size WRITE setSize ) + Q_PROPERTY( TracerStyle style READ style WRITE setStyle ) + Q_PROPERTY( QCPGraph* graph READ graph WRITE setGraph ) + Q_PROPERTY( double graphKey READ graphKey WRITE setGraphKey ) + Q_PROPERTY( bool interpolating READ interpolating WRITE setInterpolating ) /// \endcond public: /*! @@ -6539,15 +6784,21 @@ public: \see setStyle */ - enum TracerStyle { tsNone ///< The tracer is not visible - ,tsPlus ///< A plus shaped crosshair with limited size - ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect - ,tsCircle ///< A circle - ,tsSquare ///< A square - }; - Q_ENUMS(TracerStyle) + enum TracerStyle + { + tsNone ///< The tracer is not visible + , + tsPlus ///< A plus shaped crosshair with limited size + , + tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect + , + tsCircle ///< A circle + , + tsSquare ///< A square + }; + Q_ENUMS( TracerStyle ) - explicit QCPItemTracer(QCustomPlot *parentPlot); + explicit QCPItemTracer( QCustomPlot* parentPlot ); virtual ~QCPItemTracer(); // getters: @@ -6557,28 +6808,28 @@ public: QBrush selectedBrush() const { return mSelectedBrush; } double size() const { return mSize; } TracerStyle style() const { return mStyle; } - QCPGraph *graph() const { return mGraph; } + QCPGraph* graph() const { return mGraph; } double graphKey() const { return mGraphKey; } bool interpolating() const { return mInterpolating; } // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setBrush(const QBrush &brush); - void setSelectedBrush(const QBrush &brush); - void setSize(double size); - void setStyle(TracerStyle style); - void setGraph(QCPGraph *graph); - void setGraphKey(double key); - void setInterpolating(bool enabled); + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setBrush( const QBrush& brush ); + void setSelectedBrush( const QBrush& brush ); + void setSize( double size ); + void setStyle( TracerStyle style ); + void setGraph( QCPGraph* graph ); + void setGraphKey( double key ); + void setInterpolating( bool enabled ); // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + // non-virtual methods: void updatePosition(); - QCPItemPosition * const position; + QCPItemPosition* const position; protected: // property members: @@ -6586,22 +6837,21 @@ protected: QBrush mBrush, mSelectedBrush; double mSize; TracerStyle mStyle; - QCPGraph *mGraph; + QCPGraph* mGraph; double mGraphKey; bool mInterpolating; // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; // non-virtual methods: QPen mainPen() const; QBrush mainBrush() const; }; -Q_DECLARE_METATYPE(QCPItemTracer::TracerStyle) +Q_DECLARE_METATYPE( QCPItemTracer::TracerStyle ) /* end of 'src/items/item-tracer.h' */ - /* including file 'src/items/item-bracket.h', size 3969 */ /* commit ce344b3f96a62e5f652585e55f1ae7c7883cd45b 2018-06-25 01:03:39 +0200 */ @@ -6609,10 +6859,10 @@ class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - Q_PROPERTY(QPen pen READ pen WRITE setPen) - Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen) - Q_PROPERTY(double length READ length WRITE setLength) - Q_PROPERTY(BracketStyle style READ style WRITE setStyle) + Q_PROPERTY( QPen pen READ pen WRITE setPen ) + Q_PROPERTY( QPen selectedPen READ selectedPen WRITE setSelectedPen ) + Q_PROPERTY( double length READ length WRITE setLength ) + Q_PROPERTY( BracketStyle style READ style WRITE setStyle ) /// \endcond public: /*! @@ -6621,53 +6871,59 @@ public: \see setStyle */ - enum BracketStyle { bsSquare ///< A brace with angled edges - ,bsRound ///< A brace with round edges - ,bsCurly ///< A curly brace - ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression + enum BracketStyle + { + bsSquare ///< A brace with angled edges + , + bsRound ///< A brace with round edges + , + bsCurly ///< A curly brace + , + bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression }; - Q_ENUMS(BracketStyle) + Q_ENUMS( BracketStyle ) - explicit QCPItemBracket(QCustomPlot *parentPlot); + explicit QCPItemBracket( QCustomPlot* parentPlot ); virtual ~QCPItemBracket(); - + // getters: QPen pen() const { return mPen; } QPen selectedPen() const { return mSelectedPen; } double length() const { return mLength; } BracketStyle style() const { return mStyle; } - + // setters; - void setPen(const QPen &pen); - void setSelectedPen(const QPen &pen); - void setLength(double length); - void setStyle(BracketStyle style); - + void setPen( const QPen& pen ); + void setSelectedPen( const QPen& pen ); + void setLength( double length ); + void setStyle( BracketStyle style ); + // reimplemented virtual methods: - virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; - - QCPItemPosition * const left; - QCPItemPosition * const right; - QCPItemAnchor * const center; - + virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; + + QCPItemPosition* const left; + QCPItemPosition* const right; + QCPItemAnchor* const center; + protected: // property members: - enum AnchorIndex {aiCenter}; + enum AnchorIndex + { + aiCenter + }; QPen mPen, mSelectedPen; double mLength; BracketStyle mStyle; - + // reimplemented virtual methods: - virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE; - virtual QPointF anchorPixelPosition(int anchorId) const Q_DECL_OVERRIDE; - + virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + virtual QPointF anchorPixelPosition( int anchorId ) const Q_DECL_OVERRIDE; + // non-virtual methods: QPen mainPen() const; }; -Q_DECLARE_METATYPE(QCPItemBracket::BracketStyle) +Q_DECLARE_METATYPE( QCPItemBracket::BracketStyle ) /* end of 'src/items/item-bracket.h' */ - -#endif // QCUSTOMPLOT_H - +#endif // QCUSTOMPLOT_H diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake index 1c2f274..30a0de0 100644 --- a/cmake/FindFFmpeg.cmake +++ b/cmake/FindFFmpeg.cmake @@ -1,147 +1,131 @@ -# - Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC) +# * Try to find the required ffmpeg components(default: AVFORMAT, AVUTIL, AVCODEC) # -# Once done this will define -# FFMPEG_FOUND - System has the all required components. -# FFMPEG_INCLUDE_DIRS - Include directory necessary for using the required components headers. -# FFMPEG_LIBRARIES - Link these to use the required ffmpeg components. -# FFMPEG_DEFINITIONS - Compiler switches required for using the required ffmpeg components. +# Once done this will define FFMPEG_FOUND - System has the all required components. FFMPEG_INCLUDE_DIRS - Include directory necessary for +# using the required components headers. FFMPEG_LIBRARIES - Link these to use the required ffmpeg components. FFMPEG_DEFINITIONS - Compiler +# switches required for using the required ffmpeg components. # -# For each of the components it will additionally set. -# - AVCODEC -# - AVDEVICE -# - AVFORMAT -# - AVUTIL -# - POSTPROCESS -# - SWSCALE -# the following variables will be defined -# _FOUND - System has -# _INCLUDE_DIRS - Include directory necessary for using the headers -# _LIBRARIES - Link these to use -# _DEFINITIONS - Compiler switches required for using -# _VERSION - The components version +# For each of the components it will additionally set. - AVCODEC - AVDEVICE - AVFORMAT - AVUTIL - POSTPROCESS - SWSCALE the following variables will +# be defined _FOUND - System has _INCLUDE_DIRS - Include directory necessary for using the +# headers _LIBRARIES - Link these to use _DEFINITIONS - Compiler switches required for using +# _VERSION - The components version # -# Copyright (c) 2006, Matthias Kretz, -# Copyright (c) 2008, Alexander Neundorf, -# Copyright (c) 2011, Michael Jansen, +# Copyright (c) 2006, Matthias Kretz, Copyright (c) 2008, Alexander Neundorf, Copyright (c) 2011, Michael Jansen, +# # -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# Redistribution and use is allowed according to the terms of the BSD license. For details see the accompanying COPYING-CMAKE-SCRIPTS file. -include(FindPackageHandleStandardArgs) +INCLUDE(FindPackageHandleStandardArgs) # The default components were taken from a survey over other FindFFMPEG.cmake files -if (NOT FFmpeg_FIND_COMPONENTS) - set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) -endif () +IF(NOT FFmpeg_FIND_COMPONENTS) + SET(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) +ENDIF() # -### Macro: set_component_found +# Macro: set_component_found # # Marks the given component as found if both *_LIBRARIES AND *_INCLUDE_DIRS is present. # -macro(set_component_found _component ) - if (${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) +MACRO(set_component_found _component) + IF(${_component}_LIBRARIES AND ${_component}_INCLUDE_DIRS) # message(STATUS " - ${_component} found.") - set(${_component}_FOUND TRUE) - else () + SET(${_component}_FOUND TRUE) + ELSE() # message(STATUS " - ${_component} not found.") - endif () -endmacro() + ENDIF() +ENDMACRO() # -### Macro: find_component +# Macro: find_component # -# Checks for the given component by invoking pkgconfig and then looking up the libraries and -# include directories. +# Checks for the given component by invoking pkgconfig and then looking up the libraries and include directories. # -macro(find_component _component _pkgconfig _library _header) +MACRO(find_component _component _pkgconfig _library _header) - if (NOT WIN32) - # use pkg-config to get the directories and then use these values - # in the FIND_PATH() and FIND_LIBRARY() calls - find_package(PkgConfig) - if (PKG_CONFIG_FOUND) - pkg_check_modules(PC_${_component} ${_pkgconfig}) - endif () - endif (NOT WIN32) + IF(NOT WIN32) + # use pkg-config to get the directories and then use these values in the FIND_PATH() and FIND_LIBRARY() calls + FIND_PACKAGE(PkgConfig) + IF(PKG_CONFIG_FOUND) + PKG_CHECK_MODULES(PC_${_component} ${_pkgconfig}) + ENDIF() + ENDIF(NOT WIN32) - find_path(${_component}_INCLUDE_DIRS ${_header} - HINTS - ${PC_LIB${_component}_INCLUDEDIR} - ${PC_LIB${_component}_INCLUDE_DIRS} - PATH_SUFFIXES - ffmpeg - ) + FIND_PATH( + ${_component}_INCLUDE_DIRS ${_header} + HINTS ${PC_LIB${_component}_INCLUDEDIR} ${PC_LIB${_component}_INCLUDE_DIRS} + PATH_SUFFIXES ffmpeg) - find_library(${_component}_LIBRARIES NAMES ${_library} - HINTS - ${PC_LIB${_component}_LIBDIR} - ${PC_LIB${_component}_LIBRARY_DIRS} - ) - - set(${_component}_DEFINITIONS ${PC_${_component}_CFLAGS_OTHER} CACHE STRING "The ${_component} CFLAGS.") - set(${_component}_VERSION ${PC_${_component}_VERSION} CACHE STRING "The ${_component} version number.") - - set_component_found(${_component}) - - mark_as_advanced( - ${_component}_INCLUDE_DIRS + FIND_LIBRARY( ${_component}_LIBRARIES - ${_component}_DEFINITIONS - ${_component}_VERSION) + NAMES ${_library} + HINTS ${PC_LIB${_component}_LIBDIR} ${PC_LIB${_component}_LIBRARY_DIRS}) -endmacro() + SET(${_component}_DEFINITIONS + ${PC_${_component}_CFLAGS_OTHER} + CACHE STRING "The ${_component} CFLAGS.") + SET(${_component}_VERSION + ${PC_${_component}_VERSION} + CACHE STRING "The ${_component} version number.") + SET_COMPONENT_FOUND(${_component}) + + MARK_AS_ADVANCED(${_component}_INCLUDE_DIRS ${_component}_LIBRARIES ${_component}_DEFINITIONS ${_component}_VERSION) + +ENDMACRO() # Check for cached results. If there are skip the costly part. -if (NOT FFMPEG_LIBRARIES) +IF(NOT FFMPEG_LIBRARIES) # Check for all possible component. - find_component(AVCODEC libavcodec avcodec libavcodec/avcodec.h) - find_component(AVFORMAT libavformat avformat libavformat/avformat.h) - find_component(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) - find_component(AVUTIL libavutil avutil libavutil/avutil.h) - find_component(SWSCALE libswscale swscale libswscale/swscale.h) - find_component(POSTPROC libpostproc postproc libpostproc/postprocess.h) + FIND_COMPONENT(AVCODEC libavcodec avcodec libavcodec/avcodec.h) + FIND_COMPONENT(AVFORMAT libavformat avformat libavformat/avformat.h) + FIND_COMPONENT(AVDEVICE libavdevice avdevice libavdevice/avdevice.h) + FIND_COMPONENT(AVUTIL libavutil avutil libavutil/avutil.h) + FIND_COMPONENT(SWSCALE libswscale swscale libswscale/swscale.h) + FIND_COMPONENT(POSTPROC libpostproc postproc libpostproc/postprocess.h) # Check if the required components were found and add their stuff to the FFMPEG_* vars. - foreach (_component ${FFmpeg_FIND_COMPONENTS}) - if (${_component}_FOUND) + FOREACH(_component ${FFmpeg_FIND_COMPONENTS}) + IF(${_component}_FOUND) # message(STATUS "Required component ${_component} present.") - set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) - set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) - list(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) - else () + SET(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${${_component}_LIBRARIES}) + SET(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} ${${_component}_DEFINITIONS}) + LIST(APPEND FFMPEG_INCLUDE_DIRS ${${_component}_INCLUDE_DIRS}) + ELSE() # message(STATUS "Required component ${_component} missing.") - endif () - endforeach () + ENDIF() + ENDFOREACH() # Build the include path with duplicates removed. - if (FFMPEG_INCLUDE_DIRS) - list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) - endif () + IF(FFMPEG_INCLUDE_DIRS) + LIST(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS) + ENDIF() # cache the vars. - set(FFMPEG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} CACHE STRING "The FFmpeg include directories." FORCE) - set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} CACHE STRING "The FFmpeg libraries." FORCE) - set(FFMPEG_DEFINITIONS ${FFMPEG_DEFINITIONS} CACHE STRING "The FFmpeg cflags." FORCE) + SET(FFMPEG_INCLUDE_DIRS + ${FFMPEG_INCLUDE_DIRS} + CACHE STRING "The FFmpeg include directories." FORCE) + SET(FFMPEG_LIBRARIES + ${FFMPEG_LIBRARIES} + CACHE STRING "The FFmpeg libraries." FORCE) + SET(FFMPEG_DEFINITIONS + ${FFMPEG_DEFINITIONS} + CACHE STRING "The FFmpeg cflags." FORCE) - mark_as_advanced(FFMPEG_INCLUDE_DIRS - FFMPEG_LIBRARIES - FFMPEG_DEFINITIONS) + MARK_AS_ADVANCED(FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES FFMPEG_DEFINITIONS) -endif () +ENDIF() # Now set the noncached _FOUND vars for the components. -foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) - set_component_found(${_component}) -endforeach () +FOREACH(_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE) + SET_COMPONENT_FOUND(${_component}) +ENDFOREACH() # Compile the list of required vars -set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) -foreach (_component ${FFmpeg_FIND_COMPONENTS}) - list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) -endforeach () +SET(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS) +FOREACH(_component ${FFmpeg_FIND_COMPONENTS}) + LIST(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS) +ENDFOREACH() # Give a nice error message if some of the required vars are missing. -find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) \ No newline at end of file +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS}) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1e9a867..03cedf0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,5 @@ -### -### CMakeLists for examples -### - - -ADD_SUBDIRECTORY( modules ) +# +# CMakeLists for examples +# +ADD_SUBDIRECTORY(modules) diff --git a/examples/modules/CMakeLists.txt b/examples/modules/CMakeLists.txt index 498122b..e6903c7 100644 --- a/examples/modules/CMakeLists.txt +++ b/examples/modules/CMakeLists.txt @@ -1,21 +1,16 @@ -### -### CMakeLists for modules_example -### +# +# CMakeLists for modules_example +# +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9) -CMAKE_MINIMUM_REQUIRED( VERSION 2.8.9 ) +PROJECT("modules_example") -PROJECT( "modules_example" ) - -# THIS -# FIND_PACKAGE( Calyp ) -#INCLUDE_DIRECTORIES( ${CALYP_INCLUDE_DIRS} ) -# OR -INCLUDE_DIRECTORIES( ../../lib ) +# THIS FIND_PACKAGE( Calyp ) INCLUDE_DIRECTORIES( ${CALYP_INCLUDE_DIRS} ) OR +INCLUDE_DIRECTORIES(../../lib) ADD_LIBRARY(FrameBinarization SHARED FrameBinarization_APIv1.cpp) -TARGET_LINK_LIBRARIES( FrameBinarization ${CALYP_LINKER_LIBS} ) +TARGET_LINK_LIBRARIES(FrameBinarization ${CALYP_LINKER_LIBS}) ADD_LIBRARY(AbsoluteFrameDifferenceExample SHARED AbsoluteFrameDifferenceExample.cpp) -TARGET_LINK_LIBRARIES( AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY} ${CALYP_LINKER_LIBS} ) - +TARGET_LINK_LIBRARIES(AbsoluteFrameDifferenceExample ${PROJECT_LIBRARY} ${CALYP_LINKER_LIBS}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d73bccb..ff27d83 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,12 +1,12 @@ -### -### CMakeLists for calyp lib component -### +# +# CMakeLists for calyp lib component +# INCLUDE(GNUInstallDirs) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) -set(Calyp_Lib_SRCS +SET(Calyp_Lib_SRCS LibMemory.h CalypLib.h CalypDefs.h @@ -29,76 +29,57 @@ set(Calyp_Lib_SRCS CalypOptions.cpp # Modules CalypModuleIf.h - CalypOpenCVModuleIf.h -) + CalypOpenCVModuleIf.h) -LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY} ) -LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} ) +LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${PROJECT_LIBRARY}) +LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) -IF( USE_FFMPEG ) - LIST( APPEND Calyp_Lib_SRCS StreamHandlerLibav.h ) - LIST( APPEND Calyp_Lib_SRCS StreamHandlerLibav.cpp ) +IF(USE_FFMPEG) + LIST(APPEND Calyp_Lib_SRCS StreamHandlerLibav.h) + LIST(APPEND Calyp_Lib_SRCS StreamHandlerLibav.cpp) - LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${FFMPEG_LIBRARIES} ) - LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS} ) + LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${FFMPEG_LIBRARIES}) + LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${FFMPEG_INCLUDE_DIRS}) ENDIF() -IF( USE_OPENCV ) - LIST( APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h ) - LIST( APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp ) +IF(USE_OPENCV) + LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.h) + LIST(APPEND Calyp_Lib_SRCS StreamHandlerOpenCV.cpp) - LIST( APPEND Calyp_Lib_SRCS CalypOpenCVModuleIf.cpp ) + LIST(APPEND Calyp_Lib_SRCS CalypOpenCVModuleIf.cpp) - LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES} ) - LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS} ) + LIST(APPEND CMAKE_CFG_LINKER_LIBSS ${OpenCV_LIBRARIES}) + LIST(APPEND CMAKE_CFG_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS}) ENDIF() -set(Calyp_Lib_HEADERS - CalypDefs.h - CalypFrame.h - CalypStream.h - CalypOptions.h - CalypModuleIf.h - CalypOpenCVModuleIf.h -) +SET(Calyp_Lib_HEADERS CalypDefs.h CalypFrame.h CalypStream.h CalypOptions.h CalypModuleIf.h CalypOpenCVModuleIf.h) -CONFIGURE_FILE( CalypConfig.cmake.in CalypConfig.cmake @ONLY) +CONFIGURE_FILE(CalypConfig.cmake.in CalypConfig.cmake @ONLY) -INCLUDE_DIRECTORIES( ${FFMPEG_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ) +INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) -IF( USE_STATIC ) - ADD_LIBRARY( ${PROJECT_LIBRARY} STATIC ${Calyp_Lib_SRCS} ) +IF(USE_STATIC) + ADD_LIBRARY(${PROJECT_LIBRARY} STATIC ${Calyp_Lib_SRCS}) ELSE() - ADD_LIBRARY( ${PROJECT_LIBRARY} SHARED ${Calyp_Lib_SRCS} ) + ADD_LIBRARY(${PROJECT_LIBRARY} SHARED ${Calyp_Lib_SRCS}) ENDIF() +TARGET_LINK_LIBRARIES(${PROJECT_LIBRARY} ${FFMPEG_LIBRARIES} ${OpenCV_LIBRARIES}) -TARGET_LINK_LIBRARIES( ${PROJECT_LIBRARY} - ${FFMPEG_LIBRARIES} - ${OpenCV_LIBRARIES} -) +TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY} PUBLIC $ $) -TARGET_INCLUDE_DIRECTORIES(${PROJECT_LIBRARY} - PUBLIC - $ - $ -) +SET_TARGET_PROPERTIES(${PROJECT_LIBRARY} PROPERTIES VERSION ${CALYP_VERSION} SOVERSION ${CALYP_VERSION_MAJOR}) -SET_TARGET_PROPERTIES( ${PROJECT_LIBRARY} - PROPERTIES VERSION ${CALYP_VERSION} - SOVERSION ${CALYP_VERSION_MAJOR} -) - -IF( NOT USE_STATIC ) - INSTALL( TARGETS ${PROJECT_LIBRARY} +IF(NOT USE_STATIC) + INSTALL( + TARGETS ${PROJECT_LIBRARY} RUNTIME DESTINATION bin LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ) - INSTALL(FILES ${Calyp_Lib_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CalypConfig.cmake DESTINATION share/calyp ) + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") + INSTALL(FILES ${Calyp_Lib_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") + INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CalypConfig.cmake DESTINATION share/calyp) ENDIF() -IF( BUILD_TESTS ) - ADD_SUBDIRECTORY( tests ) +IF(BUILD_TESTS) + ADD_SUBDIRECTORY(tests) ENDIF() diff --git a/lib/tests/CMakeLists.txt b/lib/tests/CMakeLists.txt index 55d824c..3856fc4 100644 --- a/lib/tests/CMakeLists.txt +++ b/lib/tests/CMakeLists.txt @@ -1,11 +1,10 @@ -### -### CMakeLists for playuver lib tests component -### +# +# CMakeLists for playuver lib tests component +# -INCLUDE_DIRECTORIES( ${GTEST_INCLUDE_DIRS} ) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") -ADD_EXECUTABLE(PlaYUVerFrameQualityTests PlaYUVerFrameQualityTests.cpp ) -TARGET_LINK_LIBRARIES(PlaYUVerFrameQualityTests ${PROJECT_LIBRARY} gtest gtest_main ) +ADD_EXECUTABLE(PlaYUVerFrameQualityTests PlaYUVerFrameQualityTests.cpp) +TARGET_LINK_LIBRARIES(PlaYUVerFrameQualityTests ${PROJECT_LIBRARY} gtest gtest_main) ADD_TEST(PlaYUVerFrameQualityTests PlaYUVerFrameQualityTests) - diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index c284506..6ab5b21 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,72 +1,72 @@ -### -### CMakeLists for calyp modules component -### +# +# CMakeLists for calyp modules component +# -OPTION( CALYP_THREADED_MODULES "Use threads for modules" OFF ) -SET( CALYP_EXTRA_MODULES_DIR "CALYP_EXTRA_MODULES_DIR" CACHE PATH "Location of extra Calyp modules") +OPTION(CALYP_THREADED_MODULES "Use threads for modules" OFF) +SET(CALYP_EXTRA_MODULES_DIR + "CALYP_EXTRA_MODULES_DIR" + CACHE PATH "Location of extra Calyp modules") -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -set(Calyp_Mod_SRCS - CalypModulesFactory.cpp -) +SET(Calyp_Mod_SRCS CalypModulesFactory.cpp) # # Modules List # # SET( MODULE_LOCATION "") -ADD_MODULE( FilterComponentLuma "FilterComponent" ) -ADD_MODULE( FilterComponentChromaU "FilterComponent" ) -ADD_MODULE( FilterComponentChromaV "FilterComponent" ) -ADD_MODULE( FrameDifference "FrameDifference" ) -ADD_MODULE( FrameMask "FrameMask" ) -ADD_MODULE( FrameRotate "FrameRotate" ) -ADD_MODULE( AbsoluteFrameDifference "AbsoluteFrameDifference" ) -ADD_MODULE( InterFrameVariance "InterFrameVariance" ) -ADD_MODULE( FrameBinarization "FrameBinarization" ) -ADD_MODULE( FrameShift "FrameShift" ) -ADD_MODULE( FrameConcatenation "FrameConcatenation" ) -ADD_MODULE( SetChromaHalfScale "SetChromaHalfScale" ) -ADD_MODULE( EightBitsSampling "EightBitsSampling" ) -ADD_MODULE( FrameCrop "FrameCrop" ) -ADD_MODULE( LumaAverage "LumaAverage" ) -ADD_MODULE( WeightedPSNR "WeightedPSNR" ) -ADD_MODULE( HEVCIntraPrediction "HEVCIntraPrediction" ) -ADD_MODULE( OptimiseDisplay "OptimiseDisplay" ) +ADD_MODULE(FilterComponentLuma "FilterComponent") +ADD_MODULE(FilterComponentChromaU "FilterComponent") +ADD_MODULE(FilterComponentChromaV "FilterComponent") +ADD_MODULE(FrameDifference "FrameDifference") +ADD_MODULE(FrameMask "FrameMask") +ADD_MODULE(FrameRotate "FrameRotate") +ADD_MODULE(AbsoluteFrameDifference "AbsoluteFrameDifference") +ADD_MODULE(InterFrameVariance "InterFrameVariance") +ADD_MODULE(FrameBinarization "FrameBinarization") +ADD_MODULE(FrameShift "FrameShift") +ADD_MODULE(FrameConcatenation "FrameConcatenation") +ADD_MODULE(SetChromaHalfScale "SetChromaHalfScale") +ADD_MODULE(EightBitsSampling "EightBitsSampling") +ADD_MODULE(FrameCrop "FrameCrop") +ADD_MODULE(LumaAverage "LumaAverage") +ADD_MODULE(WeightedPSNR "WeightedPSNR") +ADD_MODULE(HEVCIntraPrediction "HEVCIntraPrediction") +ADD_MODULE(OptimiseDisplay "OptimiseDisplay") -ADD_MODULE_USE_OPENCV( MeasureOpticalFlowDualTVL1 "MeasureOpticalFlowDualTVL1" VERSION 2.4.13.0 MODULES video optflow ) -ADD_MODULE_USE_OPENCV( DisparityStereoBM "DisparityStereoBM" VERSION 2.4.13.0 MODULES calib3d ) -ADD_MODULE_USE_OPENCV( DisparityStereoSGBM "DisparityStereoSGBM" VERSION 2.4.13.0 MODULES calib3d ) -ADD_MODULE_USE_OPENCV( OpticalFlowDualTVL1 "OpticalFlow" VERSION 3.1.0 MODULES optflow ) -ADD_MODULE_USE_OPENCV( OpticalFlowSparseToDense "OpticalFlow" VERSION 3.1.0 MODULES optflow ) -ADD_MODULE_USE_OPENCV( OpticalFlowFarneback "OpticalFlow" VERSION 3.1.0 MODULES video optflow ) -ADD_MODULE_USE_OPENCV( OpticalDeepFlow "OpticalFlow" VERSION 3.1.0 MODULES video optflow ) -ADD_MODULE_USE_OPENCV( SaliencyDetectionSpectral "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) -ADD_MODULE_USE_OPENCV( SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) -ADD_MODULE_USE_OPENCV( SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency ) +ADD_MODULE_USE_OPENCV(MeasureOpticalFlowDualTVL1 "MeasureOpticalFlowDualTVL1" VERSION 2.4.13.0 MODULES video optflow) +ADD_MODULE_USE_OPENCV(DisparityStereoBM "DisparityStereoBM" VERSION 2.4.13.0 MODULES calib3d) +ADD_MODULE_USE_OPENCV(DisparityStereoSGBM "DisparityStereoSGBM" VERSION 2.4.13.0 MODULES calib3d) +ADD_MODULE_USE_OPENCV(OpticalFlowDualTVL1 "OpticalFlow" VERSION 3.1.0 MODULES optflow) +ADD_MODULE_USE_OPENCV(OpticalFlowSparseToDense "OpticalFlow" VERSION 3.1.0 MODULES optflow) +ADD_MODULE_USE_OPENCV(OpticalFlowFarneback "OpticalFlow" VERSION 3.1.0 MODULES video optflow) +ADD_MODULE_USE_OPENCV(OpticalDeepFlow "OpticalFlow" VERSION 3.1.0 MODULES video optflow) +ADD_MODULE_USE_OPENCV(SaliencyDetectionSpectral "SaliencyDetection" VERSION 3.3.0 MODULES saliency) +ADD_MODULE_USE_OPENCV(SaliencyDetectionFineGrained "SaliencyDetection" VERSION 3.3.0 MODULES saliency) +ADD_MODULE_USE_OPENCV(SaliencyDetectionBinWangApr2014 "SaliencyDetection" VERSION 3.3.0 MODULES saliency) -ADD_MODULE_USE_OPENCV( FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core ) +ADD_MODULE_USE_OPENCV(FrameResampling "FrameResampling" VERSION 3.3.0 MODULES core) -ADD_MODULE_USE_OPENCV( ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core ) -ADD_MODULE_USE_OPENCV( ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core ) -ADD_MODULE_USE_OPENCV( ThreeSixtyFaceConcatenation "ThreeSixtyFaceConcatenation" VERSION 3.1.0 MODULES core ) +ADD_MODULE_USE_OPENCV(ThreeSixtySpatialtoTemporal "ThreeSixtySpatialtoTemporal" VERSION 3.1.0 MODULES core) +ADD_MODULE_USE_OPENCV(ThreeSixtyFaceExtraction "ThreeSixtyFaceExtraction" VERSION 3.1.0 MODULES core) +ADD_MODULE_USE_OPENCV(ThreeSixtyFaceConcatenation "ThreeSixtyFaceConcatenation" VERSION 3.1.0 MODULES core) -IF(EXISTS ${CALYP_EXTRA_MODULES_DIR} ) - ADD_EXTRA_MODULES( ${CALYP_EXTRA_MODULES_DIR} ) +IF(EXISTS ${CALYP_EXTRA_MODULES_DIR}) + ADD_EXTRA_MODULES(${CALYP_EXTRA_MODULES_DIR}) ENDIF() # # Create header and auxiliar files # CREATE_MODULE_MACROS() -INCLUDE_DIRECTORIES( ${OpenCV_INCLUDE_DIRS} ) -ADD_LIBRARY( CalypModules ${Calyp_Mod_SRCS} ) -TARGET_LINK_LIBRARIES( CalypModules ${PROJECT_LIBRARY} ${OpenCV_LIBRARIES} ) -IF( USE_DYNLOAD ) - TARGET_LINK_LIBRARIES( CalypModules -ldl ) +INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) +ADD_LIBRARY(CalypModules ${Calyp_Mod_SRCS}) +TARGET_LINK_LIBRARIES(CalypModules ${PROJECT_LIBRARY} ${OpenCV_LIBRARIES}) +IF(USE_DYNLOAD) + TARGET_LINK_LIBRARIES(CalypModules -ldl) ENDIF() -IF( BUILD_TESTS ) - ADD_SUBDIRECTORY( tests ) -ENDIF() \ No newline at end of file +IF(BUILD_TESTS) + ADD_SUBDIRECTORY(tests) +ENDIF() diff --git a/modules/tests/CMakeLists.txt b/modules/tests/CMakeLists.txt index 0f4fbf6..036ebfd 100644 --- a/modules/tests/CMakeLists.txt +++ b/modules/tests/CMakeLists.txt @@ -1,18 +1,14 @@ -### -### CMakeLists for playuver lib tests component -### +# +# CMakeLists for playuver lib tests component +# -INCLUDE_DIRECTORIES( ${GTEST_INCLUDE_DIRS} ) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) ADD_DEFINITIONS(-DCALYP_TEST_DATA_DIR=\"${CALYP_TEST_DATA_DIR}\") -foreach(module ${MODULES_LIST_NAME}) - ADD_EXECUTABLE(TestModuleCreate_${module} TestModuleCreate.cpp ) - TARGET_COMPILE_DEFINITIONS(TestModuleCreate_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") - TARGET_LINK_LIBRARIES(TestModuleCreate_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main ) - ADD_TEST(TestModuleCreate_${module} TestModuleCreate_${module}) -endforeach(module ${MODULES_LIST_NAME}) - - - - +FOREACH(module ${MODULES_LIST_NAME}) + ADD_EXECUTABLE(TestModuleCreate_${module} TestModuleCreate.cpp) + TARGET_COMPILE_DEFINITIONS(TestModuleCreate_${module} PUBLIC -DCALYP_TEST_MODULE_NAME=\"${module}\") + TARGET_LINK_LIBRARIES(TestModuleCreate_${module} ${PROJECT_LIBRARY} CalypModules gtest gtest_main) + ADD_TEST(TestModuleCreate_${module} TestModuleCreate_${module}) +ENDFOREACH(module ${MODULES_LIST_NAME}) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c95a7c1..5a5b115 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,22 +1,13 @@ -### -### CMakeLists for calyp tools component -### +# +# CMakeLists for calyp tools component +# -INCLUDE_DIRECTORIES( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) -set(Calyp_Tools_SRCS - main.cpp - CalypTools.cpp - CalypToolsCmdParser.cpp -) +SET(Calyp_Tools_SRCS main.cpp CalypTools.cpp CalypToolsCmdParser.cpp) -ADD_EXECUTABLE( ${PROJECT_NAME}Tools ${Calyp_Tools_SRCS} ) - -TARGET_LINK_LIBRARIES( ${PROJECT_NAME}Tools ${PROJECT_LIBRARY} CalypModules ) - -INSTALL(TARGETS ${PROJECT_NAME}Tools DESTINATION bin ) +ADD_EXECUTABLE(${PROJECT_NAME}Tools ${Calyp_Tools_SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME}Tools ${PROJECT_LIBRARY} CalypModules) +INSTALL(TARGETS ${PROJECT_NAME}Tools DESTINATION bin)