diff --git a/.clang-tidy b/.clang-tidy index 378727e..79b09ae 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,45 +1,47 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers' -WarningsAsErrors: '' -HeaderFilterRegex: '' +Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers" +WarningsAsErrors: "" +HeaderFilterRegex: "" AnalyzeTemporaryDtors: false -FormatStyle: none +FormatStyle: none +Diagnostics: + UnusedIncludes: Strict CheckOptions: - - key: llvm-else-after-return.WarnOnConditionVariables - value: '0' - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons - value: '0' - - key: google-readability-namespace-comments.ShortNamespaceLines - value: '10' - - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField - value: '0' - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: '1' - - key: cert-dcl16-c.NewSuffixes - value: 'L;LL;LU;LLU' - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: google-readability-namespace-comments.SpacesBeforeComments - value: '2' - - key: modernize-loop-convert.MaxCopySize - value: '16' - - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors - value: '1' - - key: modernize-use-nullptr.NullMacros - value: 'NULL' - - key: llvm-qualified-auto.AddConstToQualified - value: '0' - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: llvm-else-after-return.WarnOnUnfixable - value: '0' - - key: google-readability-function-size.StatementThreshold - value: '800' - - key: readability-magic-numbers.IgnorePowersOf2IntegerValues - value: '1' + - key: llvm-else-after-return.WarnOnConditionVariables + value: "0" + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons + value: "0" + - key: google-readability-namespace-comments.ShortNamespaceLines + value: "10" + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: "0" + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: "1" + - key: cert-dcl16-c.NewSuffixes + value: "L;LL;LU;LLU" + - key: google-readability-braces-around-statements.ShortStatementLines + value: "1" + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: google-readability-namespace-comments.SpacesBeforeComments + value: "2" + - key: modernize-loop-convert.MaxCopySize + value: "16" + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: "1" + - key: modernize-use-nullptr.NullMacros + value: "NULL" + - key: llvm-qualified-auto.AddConstToQualified + value: "0" + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: llvm-else-after-return.WarnOnUnfixable + value: "0" + - key: google-readability-function-size.StatementThreshold + value: "800" + - key: readability-magic-numbers.IgnorePowersOf2IntegerValues + value: "1" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 816b43c..ac0ee1d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: - master - devel pull_request: - branches: [ master ] + branches: [master] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) @@ -21,44 +21,44 @@ jobs: runs-on: ubuntu-latest steps: - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install gcc-10 g++-10 cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install cmake qtbase5-dev qt6-base-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Build with default options - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Build with default options + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-12 -D CMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: Build without threads - run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DCALYP_MANAGED_RESOURCES=OFF -DCALYP_THREADED_MODULES=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Build without threads + run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-12 -D CMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DCALYP_MANAGED_RESOURCES=OFF -DCALYP_THREADED_MODULES=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: Build without dependencies - run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DUSE_OPENCV=OFF -DUSE_FFMPEG=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Build without dependencies + run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-12 -D CMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_WERROR=ON -DUSE_OPENCV=OFF -DUSE_FFMPEG=OFF; cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} check-tests: runs-on: ubuntu-latest steps: - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install gcc-10 g++-10 cmake qtbase5-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install cmake qtbase5-dev qt6-base-dev libavcodec-dev libavformat-dev libavutil-dev libopencv-dev libopencv-video-dev libopencv-contrib-dev - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Check out tests data - uses: actions/checkout@master - with: - repository: 'pixlra/calyp-testdata' - path: ${{github.workspace}}/tests_data + - name: Check out tests data + uses: actions/checkout@master + with: + repository: "pixlra/calyp-testdata" + path: ${{github.workspace}}/tests_data - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-10 -D CMAKE_CXX_COMPILER=g++-10 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON -DCALYP_TEST_DATA_DIR=${{github.workspace}}/tests_data + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=gcc-12 -D CMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON -DCALYP_TEST_DATA_DIR=${{github.workspace}}/tests_data - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: CalypLib tests - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t test \ No newline at end of file + - name: CalypLib tests + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -t test diff --git a/CMakeLists.txt b/CMakeLists.txt index 60bddde..a65ad95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,20 @@ INCLUDE(FetchContent) SET(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/deps") +FETCHCONTENT_DECLARE( + fmtformat + GIT_REPOSITORY https://github.com/fmtlib/fmt + GIT_TAG 9.1.0 + ) + +SET_PACKAGE_PROPERTIES( + fmtformat PROPERTIES + URL "https://github.com/fmtlib/fmt" + DESCRIPTION "A modern formatting library" + TYPE REQUIRED + ) + FETCHCONTENT_MAKEAVAILABLE(fmtformat) + # Doxygen IF(BUILD_DOC) FIND_PACKAGE(Doxygen) @@ -241,7 +255,7 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "Release") ENDIF() -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -funroll-loops -Wno-unused-function") # if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") endif() diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4833524..5f157fc 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -7,15 +7,24 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/docks ${CMAKE_CURRENT_SOURCE_DIR}/widgets ) -OPTION(USE_QTDBUS "Build with QtDBus" ON) +OPTION(USE_QT6 "Build with Qt6" ON) +OPTION(USE_QTDBUS "Build with QtDBus" OFF) OPTION(USE_FERVOR "Add Fervor support" OFF) OPTION(CALYP_MANAGED_RESOURCES "Handle streams in separate threads" ON) OPTION(CALYP_THREADED_MODULES "Use threads for modules" ON) +if(${USE_QT6}) +FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Core Gui Widgets Concurrent) +IF (NOT Qt6_FOUND) +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets Concurrent) +ENDIF() +ELSE() +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets Concurrent) +ENDIF() + 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_LINKER_LIBS Qt::Core Qt::Gui Qt::Widgets Qt::Concurrent) LIST(APPEND QT_MODULES Core Gui Widgets Concurrent) IF(USE_QTDBUS) @@ -31,11 +40,12 @@ IF(USE_QTDBUS) ${Qt5DBus_FOUND} PARENT_SCOPE ) - LIST(APPEND QT_LINKER_LIBS Qt5::DBus) + LIST(APPEND QT_LINKER_LIBS Qt::DBus) LIST(APPEND QT_MODULES DBus) ENDIF() ENDIF() + ADD_DEFINITIONS( -DQT_NO_CAST_TO_ASCII # -DQT_NO_CAST_FROM_ASCII @@ -107,7 +117,7 @@ IF(USE_FERVOR) FIND_PACKAGE(Qt5 REQUIRED Network WebKit WebKitWidgets) - LIST(APPEND QT_LINKER_LIBS Qt5::Network Qt5::WebKit Qt5::WebKitWidgets) + LIST(APPEND QT_LINKER_LIBS Qt::Network Qt::WebKit Qt::WebKitWidgets) LIST(APPEND QT_MODULES Network WebKit WebKitWidgets) # LIST(APPEND APP_LINKER_LIBS ${FERVOR_DEPENDENCIES} ) @@ -130,8 +140,8 @@ SET_PACKAGE_PROPERTIES( ) 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}) +QT_WRAP_UI(Calyp_App_UI_Wrap ${Calyp_App_UI}) +QT_ADD_RESOURCES(Calyp_App_RCC ${Calyp_App_RCC}) # Instruct CMake to run moc automatically when needed. SET(CMAKE_AUTOMOC ON) diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index 9f8ebd9..7633366 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -48,8 +48,7 @@ #include "fvupdater.h" #endif -MainWindow::MainWindow() - : m_pcCurrentSubWindow( NULL ), m_pcCurrentVideoSubWindow( NULL ), m_pcAboutDialog( NULL ) +MainWindow::MainWindow() : m_pcCurrentSubWindow( NULL ), m_pcCurrentVideoSubWindow( NULL ), m_pcAboutDialog( NULL ) { setWindowModality( Qt::ApplicationModal ); setWindowModality( Qt::NonModal ); @@ -690,19 +689,19 @@ void MainWindow::createActions() m_arrayActions[FORMAT_ACT] = new QAction( tr( "&Format" ), this ); m_arrayActions[FORMAT_ACT]->setIcon( QIcon::fromTheme( "transform-scale" ) ); - m_arrayActions[FORMAT_ACT]->setShortcut( Qt::CTRL + Qt::Key_F ); + m_arrayActions[FORMAT_ACT]->setShortcut( Qt::CTRL | Qt::Key_F ); m_arrayActions[FORMAT_ACT]->setStatusTip( tr( "Open format dialog" ) ); connect( m_arrayActions[FORMAT_ACT], SIGNAL( triggered() ), this, SLOT( format() ) ); m_arrayActions[RELOAD_ACT] = new QAction( tr( "&Reload" ), this ); m_arrayActions[RELOAD_ACT]->setIcon( style()->standardIcon( QStyle::SP_BrowserReload ) ); - m_arrayActions[RELOAD_ACT]->setShortcut( Qt::CTRL + Qt::Key_R ); + m_arrayActions[RELOAD_ACT]->setShortcut( Qt::CTRL | Qt::Key_R ); m_arrayActions[RELOAD_ACT]->setShortcut( Qt::Key_F5 ); m_arrayActions[RELOAD_ACT]->setStatusTip( tr( "Reload current sequence" ) ); connect( m_arrayActions[RELOAD_ACT], SIGNAL( triggered() ), this, SLOT( reload() ) ); m_arrayActions[RELOAD_ALL_ACT] = new QAction( tr( "Reload All" ), this ); - m_arrayActions[RELOAD_ALL_ACT]->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_R ); + m_arrayActions[RELOAD_ALL_ACT]->setShortcut( Qt::CTRL | Qt::SHIFT | Qt::Key_R ); m_arrayActions[RELOAD_ALL_ACT]->setStatusTip( tr( "Reload all sequences" ) ); connect( m_arrayActions[RELOAD_ALL_ACT], SIGNAL( triggered() ), this, SLOT( reloadAll() ) ); @@ -982,7 +981,7 @@ void MainWindow::writeSettings() appSettings.setValue( "MainWindow/LastOpenPath", m_cLastOpenPath ); QVariant var; - var.setValue( m_aRecentFileStreamInfo ); + var.setValue( m_aRecentFileStreamInfo ); appSettings.setValue( "MainWindow/RecentFileList", var ); m_appModuleVideo->writeSettings(); diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index ca6fb59..e8593fd 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 70c6b42..b64ee32 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -52,8 +52,7 @@ VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager ) m_pcPlayingTimer = new QTimer( this ); m_pcFrameRateFeedbackTimer = std::make_unique(); m_pcPlayingTimer->setTimerType( Qt::PreciseTimer ); - connect( m_pcPlayingTimer, &QTimer::timeout, - this, &VideoHandle::playEvent ); + connect( m_pcPlayingTimer, &QTimer::timeout, this, &VideoHandle::playEvent ); m_acPlayingSubWindows.clear(); } @@ -153,7 +152,7 @@ void VideoHandle::createActions() m_arrayActions[NAVIGATION_TOOL_ACT] = new QAction( tr( "Navigation Tool" ), this ); m_arrayActions[NAVIGATION_TOOL_ACT]->setCheckable( true ); m_arrayActions[NAVIGATION_TOOL_ACT]->setChecked( true ); - m_arrayActions[NAVIGATION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_1 ); + m_arrayActions[NAVIGATION_TOOL_ACT]->setShortcut( Qt::CTRL | Qt::Key_1 ); m_actionGroupTools->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); connect( m_arrayActions[NAVIGATION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) ); m_mapperTools->setMapping( m_arrayActions[NAVIGATION_TOOL_ACT], ViewArea::NavigationView ); @@ -161,7 +160,7 @@ void VideoHandle::createActions() m_arrayActions[SELECTION_TOOL_ACT] = new QAction( "Selection Tool", this ); m_arrayActions[SELECTION_TOOL_ACT]->setCheckable( true ); m_arrayActions[SELECTION_TOOL_ACT]->setChecked( false ); - m_arrayActions[SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_2 ); + m_arrayActions[SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL | Qt::Key_2 ); m_actionGroupTools->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); connect( m_arrayActions[SELECTION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) ); m_mapperTools->setMapping( m_arrayActions[SELECTION_TOOL_ACT], ViewArea::NormalSelectionView ); @@ -169,7 +168,7 @@ void VideoHandle::createActions() m_arrayActions[BLOCK_SELECTION_TOOL_ACT] = new QAction( "Block Selection Tool", this ); m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setCheckable( true ); m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setChecked( false ); - m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_3 ); + m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL | Qt::Key_3 ); m_actionGroupTools->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] ); connect( m_arrayActions[BLOCK_SELECTION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) ); m_mapperTools->setMapping( m_arrayActions[BLOCK_SELECTION_TOOL_ACT], ViewArea::BlockSelectionView ); @@ -507,14 +506,11 @@ void VideoHandle::addSubWindow( VideoSubWindow* window ) window->getViewArea()->setTool( m_uiViewTool ); window->getViewArea()->setGridVisible( m_arrayActions[SHOW_GRID_ACT]->isChecked() ); - connect( window, &SubWindowAbstract::aboutToClose, - this, &VideoHandle::closeSubWindow ); + connect( window, &SubWindowAbstract::aboutToClose, this, &VideoHandle::closeSubWindow ); - connect( window, &SubWindowAbstract::zoomFactorChanged, - this, &VideoHandle::zoomToFactorAll ); + connect( window, &SubWindowAbstract::zoomFactorChanged, this, &VideoHandle::zoomToFactorAll ); - connect( window, &SubWindowAbstract::scrollBarMoved, - this, &VideoHandle::moveAllScrollBars ); + connect( window, &SubWindowAbstract::scrollBarMoved, this, &VideoHandle::moveAllScrollBars ); connect( window->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectionArea( QRect ) ) ); } @@ -606,7 +602,8 @@ void VideoHandle::moveAllScrollBars( const double& horRatio, const double& verRa if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() && m_pcCurrentVideoSubWindow ) { VideoSubWindow* videoSubWindow; - QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); + QList subWindowList = + m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); for( int i = 0; i < subWindowList.size(); i++ ) { @@ -752,7 +749,9 @@ void VideoHandle::calculateRealFrameRate() { double average_time_between_frames_ms = m_uiNumberPlayedFrames > 0 ? 1000.0 / m_uiRealAverageFrameRate : 0; double time_elapsed_since_last_frame_ms = m_pcFrameRateFeedbackTimer->elapsed(); - average_time_between_frames_ms = double( average_time_between_frames_ms * m_uiNumberPlayedFrames + time_elapsed_since_last_frame_ms ) / double( m_uiNumberPlayedFrames + 1 ); + average_time_between_frames_ms = + double( average_time_between_frames_ms * m_uiNumberPlayedFrames + time_elapsed_since_last_frame_ms ) / + double( m_uiNumberPlayedFrames + 1 ); m_uiRealAverageFrameRate = 1000.0 / average_time_between_frames_ms; m_uiNumberPlayedFrames++; m_pcFrameRateFeedbackTimer->restart(); @@ -796,7 +795,8 @@ void VideoHandle::playEvent() } catch( const char* msg ) { - QString warningMsg = "Error while playing " + m_pcCurrentVideoSubWindow->getWindowName() + " with the following error: \n" + msg; + QString warningMsg = + "Error while playing " + m_pcCurrentVideoSubWindow->getWindowName() + " with the following error: \n" + msg; QMessageBox::warning( m_pcParent, QApplication::applicationName(), warningMsg ); qDebug() << warningMsg; stop(); diff --git a/app/VideoStreamSubWindow.cpp b/app/VideoStreamSubWindow.cpp index 271a8af..7ad5675 100644 --- a/app/VideoStreamSubWindow.cpp +++ b/app/VideoStreamSubWindow.cpp @@ -229,11 +229,11 @@ bool VideoStreamSubWindow::loadFile( QString cFilename, bool bForceDialog ) m_sStreamInfo.m_bForceRaw = forceRaw; QVariant var; - var.setValue( Width ); + var.setValue( Width ); appSettings.setValue( "VideoStreamSubWindow/LastWidth", var ); - var.setValue( Height ); + var.setValue( Height ); appSettings.setValue( "VideoStreamSubWindow/LastHeight", var ); - var.setValue( BitsPel ); + var.setValue( BitsPel ); appSettings.setValue( "VideoStreamSubWindow/LastBitsPerPixel", var ); #ifdef CALYP_MANAGED_RESOURCES diff --git a/app/dialog/ConfigureFormatDialog.cpp b/app/dialog/ConfigureFormatDialog.cpp index 818d367..4f052ed 100644 --- a/app/dialog/ConfigureFormatDialog.cpp +++ b/app/dialog/ConfigureFormatDialog.cpp @@ -73,8 +73,7 @@ QDataStream& operator>>( QDataStream& in, CalypStandardResolutionVector& array ) class AddCustomFormat : public QDialog { public: - AddCustomFormat( QWidget* parent = NULL ) - : QDialog( parent, Qt::Dialog | Qt::WindowTitleHint ) + AddCustomFormat( QWidget* parent = NULL ) : QDialog( parent, Qt::Dialog | Qt::WindowTitleHint ) { setWindowModality( Qt::ApplicationModal ); setWindowTitle( "Add custom resolution" ); @@ -137,8 +136,7 @@ private: QSpinBox* m_spinHeight; }; -ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent ) - : QDialog( parent ) +ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent ) : QDialog( parent ) { QString Name; unsigned int uiWidth, uiHeight; @@ -175,12 +173,18 @@ ConfigureFormatDialog::ConfigureFormatDialog( QWidget* parent ) QFont titleFont, menusFont, normalFont; +#if QT_VERSION > QT_VERSION_CHECK( 6, 0, 0 ) + auto fontWeight = QFont::Weight::Bold; +#else + auto fontWeight = 75; +#endif + titleFont.setPointSize( 12 ); titleFont.setBold( true ); - titleFont.setWeight( 75 ); + titleFont.setWeight( fontWeight ); menusFont.setBold( true ); - titleFont.setWeight( 75 ); + titleFont.setWeight( fontWeight ); normalFont.setBold( false ); // menusFont.setPointSize( 12 ); @@ -402,8 +406,9 @@ auto findPelFormatColorSpace( ClpPixelFormats rInputFormat ) -> std::pair( aRCustomFileFormats ); + var.setValue( aRCustomFileFormats ); appSettings.setValue( "ConfigureFormatDialog/CustomFormats", var ); } diff --git a/app/dialog/ProgressBar.cpp b/app/dialog/ProgressBar.cpp index 72aa535..4e6fbdf 100644 --- a/app/dialog/ProgressBar.cpp +++ b/app/dialog/ProgressBar.cpp @@ -25,7 +25,6 @@ #include "ProgressBar.h" #include -#include #include #include #include diff --git a/app/external/qcustomplot/CMakeLists.txt b/app/external/qcustomplot/CMakeLists.txt index d71910a..64c27f3 100644 --- a/app/external/qcustomplot/CMakeLists.txt +++ b/app/external/qcustomplot/CMakeLists.txt @@ -2,7 +2,14 @@ # CMakeLists for qcustomplot # +if(${USE_QT6}) +FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Core Gui Widgets PrintSupport) +IF (NOT Qt6_FOUND) FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport) +ENDIF() +ELSE() +FIND_PACKAGE(Qt5 REQUIRED COMPONENTS Core Gui Widgets PrintSupport) +ENDIF() SET(qcustomplot_SRCS qcustomplot.cpp qcustomplot.h) @@ -13,5 +20,5 @@ IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") ENDIF() ADD_LIBRARY(QCustomPlotLib STATIC ${qcustomplot_SRCS}) -TARGET_LINK_LIBRARIES(QCustomPlotLib Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport) +TARGET_LINK_LIBRARIES(QCustomPlotLib Qt::Core Qt::Gui Qt::Widgets Qt::PrintSupport) TARGET_INCLUDE_DIRECTORIES(QCustomPlotLib PUBLIC .) diff --git a/app/external/qcustomplot/changelog.txt b/app/external/qcustomplot/changelog.txt old mode 100644 new mode 100755 index cc0fede..de330e7 --- a/app/external/qcustomplot/changelog.txt +++ b/app/external/qcustomplot/changelog.txt @@ -1,3 +1,21 @@ +#### Version 2.1.1 released on 06.11.22 #### + +Added features: + - Qt6.4 Compatibility + +Bugfixes: + - dynamically changing device pixel ratios (e.g. when moving between different DPI screens) is handled properly + - bugfix Colormap autoscaling: recalculateDataBounds() if (0, 0) data point is NaN. + - minor bugfix in getMantissa for certain values due to rounding errors + - Graphs with line style lsImpulse properly ignore NaN data points + - fixed issue where QCP wasn't greyed out together with the rest of the UI on embedded systems when a modal dialog is shown + (QCustomPlot no longer has the Qt::WA_OpaquePaintEvent attribute enabled by default) + +Other: + - in QCPAxisPainterPrivate::getTickLabelData, don't use fixed 'e', but locale aware character of parent plot locale + - Axis rescaling now ignores +/- Inf in data values + - slight performance improvements of QCPColorMap colorization and fills. + #### Version 2.1.0 released on 29.03.21 #### Added features: diff --git a/app/external/qcustomplot/qcustomplot.cpp b/app/external/qcustomplot/qcustomplot.cpp index eda3163..72b5bfb 100644 --- a/app/external/qcustomplot/qcustomplot.cpp +++ b/app/external/qcustomplot/qcustomplot.cpp @@ -1,7 +1,7 @@ /*************************************************************************** ** ** ** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2021 Emanuel Eichhammer ** +** Copyright (C) 2011-2022 Emanuel Eichhammer ** ** ** ** This program is free software: you can redistribute it and/or modify ** ** it under the terms of the GNU General Public License as published by ** @@ -18,15 +18,16 @@ ** ** **************************************************************************** ** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 29.03.21 ** -** Version: 2.1.0 ** +** Website/Contact: https://www.qcustomplot.com/ ** +** Date: 06.11.22 ** +** Version: 2.1.1 ** ****************************************************************************/ #include "qcustomplot.h" + /* including file 'src/vector2d.cpp' */ -/* modified 2021-03-29T02:30:44, size 7973 */ +/* modified 2022-11-06T12:45:56, size 7973 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPVector2D @@ -114,8 +115,9 @@ /*! 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) { } @@ -123,8 +125,9 @@ 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) { } @@ -132,8 +135,9 @@ 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()) { } @@ -141,8 +145,9 @@ 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()) { } @@ -155,9 +160,8 @@ QCPVector2D::QCPVector2D( const QPointF& point ) */ void QCPVector2D::normalize() { - if( mX == 0.0 && mY == 0.0 ) - return; - const double lenInv = 1.0 / length(); + if (mX == 0.0 && mY == 0.0) return; + const double lenInv = 1.0/length(); mX *= lenInv; mY *= lenInv; } @@ -171,10 +175,9 @@ void QCPVector2D::normalize() */ QCPVector2D QCPVector2D::normalized() const { - if( mX == 0.0 && mY == 0.0 ) - return *this; - const double lenInv = 1.0 / length(); - return QCPVector2D( mX * lenInv, mY * lenInv ); + if (mX == 0.0 && mY == 0.0) return *this; + const double lenInv = 1.0/length(); + return QCPVector2D(mX*lenInv, mY*lenInv); } /*! \overload @@ -184,22 +187,21 @@ 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 { - const QCPVector2D v( end - start ); + const QCPVector2D v(end-start); const double vLengthSqr = v.lengthSquared(); - if( !qFuzzyIsNull( vLengthSqr ) ) + if (!qFuzzyIsNull(vLengthSqr)) { - const double mu = v.dot( *this - start ) / vLengthSqr; - if( mu < 0 ) - return ( *this - start ).lengthSquared(); - else if( mu > 1 ) - return ( *this - end ).lengthSquared(); + const 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 @@ -209,9 +211,9 @@ double QCPVector2D::distanceSquaredToLine( const QCPVector2D& start, const QCPVe \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())); } /*! @@ -220,16 +222,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; @@ -240,7 +242,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; @@ -250,7 +252,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; @@ -260,7 +262,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; @@ -268,8 +270,9 @@ QCPVector2D& QCPVector2D::operator-=( const QCPVector2D& vector ) } /* end of 'src/vector2d.cpp' */ + /* including file 'src/painter.cpp' */ -/* modified 2021-03-29T02:30:44, size 8656 */ +/* modified 2022-11-06T12:45:56, size 8656 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPainter @@ -291,8 +294,9 @@ QCPVector2D& QCPVector2D::operator-=( const QCPVector2D& vector ) /*! Creates a new QCPPainter instance and sets default values */ -QCPPainter::QCPPainter() - : mModes( pmDefault ), mIsAntialiasing( false ) +QCPPainter::QCPPainter() : + mModes(pmDefault), + mIsAntialiasing(false) { // don't setRenderHint(QPainter::NonCosmeticDefautPen) here, because painter isn't active yet and // a call to begin() will follow @@ -304,12 +308,14 @@ 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 } @@ -319,10 +325,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(); } @@ -333,10 +339,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(); } @@ -347,10 +353,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(); } @@ -362,12 +368,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()); } /*! @@ -376,18 +382,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); } } } @@ -396,7 +402,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; } @@ -412,12 +418,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; } @@ -427,11 +433,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; } @@ -445,7 +451,7 @@ void QCPPainter::setMode( QCPPainter::PainterMode mode, bool enabled ) */ void QCPPainter::save() { - mAntialiasingStack.push( mIsAntialiasing ); + mAntialiasingStack.push(mIsAntialiasing); QPainter::save(); } @@ -459,7 +465,7 @@ void QCPPainter::save() */ void QCPPainter::restore() { - if( !mAntialiasingStack.isEmpty() ) + if (!mAntialiasingStack.isEmpty()) mIsAntialiasing = mAntialiasingStack.pop(); else qDebug() << Q_FUNC_INFO << "Unbalanced save/restore"; @@ -472,17 +478,18 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 18915 */ +/* modified 2022-11-06T12:45:56, size 18915 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractPaintBuffer @@ -571,8 +578,10 @@ 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) { } @@ -588,9 +597,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(); @@ -612,7 +621,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; } @@ -626,9 +635,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; @@ -655,8 +664,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(); } @@ -666,51 +675,51 @@ QCPPaintBufferPixmap::~QCPPaintBufferPixmap() } /* inherits documentation from base class */ -QCPPainter* QCPPaintBufferPixmap::startPainting() +QCPPainter *QCPPaintBufferPixmap::startPainting() { - QCPPainter* result = new QCPPainter( &mBuffer ); -#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) - result->setRenderHint( QPainter::HighQualityAntialiasing ); + QCPPainter *result = new QCPPainter(&mBuffer); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + result->setRenderHint(QPainter::HighQualityAntialiasing); #endif 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 @@ -735,74 +744,76 @@ 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 ); + format.setAlpha(true); + format.setSamples(mMultisamples); + mGlPBuffer = new QGLPixelBuffer(mSize, format); } -#endif // QCP_OPENGL_PBUFFER +#endif // QCP_OPENGL_PBUFFER + #ifdef QCP_OPENGL_FBO //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -829,45 +840,48 @@ 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() { QSharedPointer paintDevice = mGlPaintDevice.toStrongRef(); QSharedPointer context = mGlContext.toStrongRef(); - if( !paintDevice ) + if (!paintDevice) { qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; return 0; } - if( !context ) + if (!context) { qDebug() << Q_FUNC_INFO << "OpenGL context 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() != context.data() ) - context->makeCurrent( context->surface() ); + + if (QOpenGLContext::currentContext() != context.data()) + context->makeCurrent(context->surface()); mGlFrameBuffer->bind(); - QCPPainter* result = new QCPPainter( paintDevice.data() ); -#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) - result->setRenderHint( QPainter::HighQualityAntialiasing ); + QCPPainter *result = new QCPPainter(paintDevice.data()); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + result->setRenderHint(QPainter::HighQualityAntialiasing); #endif return result; } @@ -875,48 +889,48 @@ QCPPainter* QCPPaintBufferGlFbo::startPainting() /* 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) { QSharedPointer context = mGlContext.toStrongRef(); - if( !context ) + if (!context) { 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() != context.data() ) - context->makeCurrent( context->surface() ); + + if (QOpenGLContext::currentContext() != context.data()) + context->makeCurrent(context->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(); } @@ -924,44 +938,45 @@ 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; } - + QSharedPointer paintDevice = mGlPaintDevice.toStrongRef(); QSharedPointer context = mGlContext.toStrongRef(); - if( !paintDevice ) + if (!paintDevice) { qDebug() << Q_FUNC_INFO << "OpenGL paint device doesn't exist"; return; } - if( !context ) + if (!context) { qDebug() << Q_FUNC_INFO << "OpenGL context doesn't exist"; return; } - + // create new fbo with appropriate size: - context->makeCurrent( context->surface() ); + context->makeCurrent(context->surface()); QOpenGLFramebufferObjectFormat frameBufferFormat; - frameBufferFormat.setSamples( context->format().samples() ); - frameBufferFormat.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil ); - mGlFrameBuffer = new QOpenGLFramebufferObject( mSize * mDevicePixelRatio, frameBufferFormat ); - if( paintDevice->size() != mSize * mDevicePixelRatio ) - paintDevice->setSize( mSize * mDevicePixelRatio ); + frameBufferFormat.setSamples(context->format().samples()); + frameBufferFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + mGlFrameBuffer = new QOpenGLFramebufferObject(mSize*mDevicePixelRatio, frameBufferFormat); + if (paintDevice->size() != mSize*mDevicePixelRatio) + paintDevice->setSize(mSize*mDevicePixelRatio); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED - paintDevice->setDevicePixelRatio( mDevicePixelRatio ); + paintDevice->setDevicePixelRatio(mDevicePixelRatio); #endif } -#endif // QCP_OPENGL_FBO +#endif // QCP_OPENGL_FBO /* end of 'src/paintbuffer.cpp' */ + /* including file 'src/layer.cpp' */ -/* modified 2021-03-29T02:30:44, size 37615 */ +/* modified 2022-11-06T12:45:56, size 37615 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayer @@ -1049,10 +1064,13 @@ 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. @@ -1064,11 +1082,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( nullptr ); // removes itself from mChildren via removeChild() - - if( mParentPlot->currentLayer() == this ) + + while (!mChildren.isEmpty()) + mChildren.last()->setLayer(nullptr); // 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 nullptr beforehand."; } @@ -1080,7 +1098,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; } @@ -1106,12 +1124,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( QSharedPointer pb = mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = mPaintBuffer.toStrongRef()) pb->setInvalidated(); } } @@ -1122,16 +1140,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(); } } @@ -1147,21 +1165,19 @@ void QCPLayer::draw( QCPPainter* painter ) */ void QCPLayer::drawToPaintBuffer() { - if( QSharedPointer pb = mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = mPaintBuffer.toStrongRef()) { - if( QCPPainter* painter = pb->startPainting() ) + if (QCPPainter *painter = pb->startPainting()) { - if( painter->isActive() ) - draw( painter ); + if (painter->isActive()) + draw(painter); else qDebug() << Q_FUNC_INFO << "paint buffer returned inactive painter"; delete painter; pb->donePainting(); - } - else + } else qDebug() << Q_FUNC_INFO << "paint buffer returned nullptr painter"; - } - else + } else qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; } @@ -1181,19 +1197,17 @@ void QCPLayer::drawToPaintBuffer() */ void QCPLayer::replot() { - if( mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers() ) + if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()) { - if( QSharedPointer pb = mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = mPaintBuffer.toStrongRef()) { - pb->clear( Qt::transparent ); + pb->clear(Qt::transparent); drawToPaintBuffer(); - pb->setInvalidated( false ); // since layer is lmBuffered, we know only this layer is on buffer and we can reset invalidated flag + pb->setInvalidated(false); // since layer is lmBuffered, we know only this layer is on buffer and we can reset invalidated flag mParentPlot->update(); - } - else + } else qDebug() << Q_FUNC_INFO << "no valid paint buffer associated with this layer"; - } - else + } else mParentPlot->replot(); } @@ -1207,19 +1221,18 @@ 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( QSharedPointer pb = mPaintBuffer.toStrongRef() ) + mChildren.append(layerable); + if (QSharedPointer pb = mPaintBuffer.toStrongRef()) pb->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 @@ -1231,17 +1244,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( QSharedPointer pb = mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = mPaintBuffer.toStrongRef()) pb->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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1350,23 +1363,28 @@ 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( nullptr ), mAntialiased( true ) +QCPLayerable::QCPLayerable(QCustomPlot *plot, QString targetLayer, QCPLayerable *parentLayerable) : + QObject(plot), + mVisible(true), + mParentPlot(plot), + mParentLayerable(parentLayerable), + mLayer(nullptr), + 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 = nullptr; } } @@ -1376,7 +1394,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; } @@ -1390,9 +1408,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 @@ -1400,18 +1418,17 @@ 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; @@ -1424,7 +1441,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; } @@ -1441,7 +1458,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()); } /*! @@ -1483,11 +1500,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; } @@ -1508,19 +1525,19 @@ double QCPLayerable::selectTest( const QPointF& pos, bool onlySelectable, QVaria 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 @@ -1534,7 +1551,7 @@ void QCPLayerable::initializeParentPlot( QCustomPlot* parentPlot ) \see realVisibility */ -void QCPLayerable::setParentLayerable( QCPLayerable* parentLayerable ) +void QCPLayerable::setParentLayerable(QCPLayerable *parentLayerable) { mParentLayerable = parentLayerable; } @@ -1547,27 +1564,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; } @@ -1578,14 +1595,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 @@ -1604,9 +1621,9 @@ void QCPLayerable::applyAntialiasingHint( QCPPainter* painter, bool localAntiali \see initializeParentPlot */ -void QCPLayerable::parentPlotInitialized( QCustomPlot* parentPlot ) +void QCPLayerable::parentPlotInitialized(QCustomPlot *parentPlot) { - Q_UNUSED( parentPlot ) + Q_UNUSED(parentPlot) } /*! \internal @@ -1636,7 +1653,7 @@ QCP::Interaction QCPLayerable::selectionCategory() const */ QRect QCPLayerable::clipRect() const { - if( mParentPlot ) + if (mParentPlot) return mParentPlot->viewport(); else return {}; @@ -1670,12 +1687,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 @@ -1690,9 +1707,9 @@ void QCPLayerable::selectEvent( QMouseEvent* event, bool additive, const QVarian \see selectTest, selectEvent */ -void QCPLayerable::deselectEvent( bool* selectionStateChanged ) +void QCPLayerable::deselectEvent(bool *selectionStateChanged) { - Q_UNUSED( selectionStateChanged ) + Q_UNUSED(selectionStateChanged) } /*! @@ -1720,9 +1737,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(); } @@ -1738,9 +1755,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(); } @@ -1756,9 +1773,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(); } @@ -1788,9 +1805,9 @@ void QCPLayerable::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPo \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(); } @@ -1811,14 +1828,15 @@ void QCPLayerable::mouseDoubleClickEvent( QMouseEvent* event, const QVariant& de \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' */ -/* modified 2021-03-29T02:30:44, size 12221 */ +/* modified 2022-11-06T12:45:56, size 12221 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPRange @@ -1906,8 +1924,9 @@ 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) { } @@ -1918,8 +1937,9 @@ 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(); } @@ -1936,11 +1956,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; } @@ -1956,14 +1976,15 @@ 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 @@ -1974,10 +1995,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; } @@ -1991,10 +2012,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; } @@ -2006,27 +2027,26 @@ 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; } @@ -2045,44 +2065,42 @@ 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))); } /*! @@ -2127,19 +2145,20 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 21837 */ +/* modified 2022-11-06T12:45:56, size 21837 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPDataRange @@ -2235,8 +2254,9 @@ 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) { } @@ -2245,8 +2265,9 @@ 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) { } @@ -2259,15 +2280,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; } @@ -2275,9 +2296,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 { qMin( mBegin, other.mBegin ), qMax( mEnd, other.mEnd ) }; + return {qMin(mBegin, other.mBegin), qMax(mEnd, other.mEnd)}; } /*! @@ -2290,10 +2311,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 {}; @@ -2304,10 +2325,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) ); } /*! @@ -2315,11 +2336,13 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2396,9 +2419,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); } /*! @@ -2408,13 +2431,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 < mDataRanges.size(); ++i ) + 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; } @@ -2508,7 +2528,7 @@ QCPDataSelection& QCPDataSelection::operator-=( const QCPDataRange& other ) int QCPDataSelection::dataPointCount() const { int result = 0; - foreach( QCPDataRange dataRange, mDataRanges ) + foreach (QCPDataRange dataRange, mDataRanges) result += dataRange.length(); return result; } @@ -2521,13 +2541,12 @@ int QCPDataSelection::dataPointCount() const \see dataRangeCount */ -QCPDataRange QCPDataSelection::dataRange( int index ) const +QCPDataRange QCPDataSelection::dataRange(int index) const { - if( index >= 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 {}; @@ -2540,10 +2559,10 @@ QCPDataRange QCPDataSelection::dataRange( int index ) const */ QCPDataRange QCPDataSelection::span() const { - if( isEmpty() ) + if (isEmpty()) return {}; else - return { mDataRanges.first().begin(), mDataRanges.last().end() }; + return {mDataRanges.first().begin(), mDataRanges.last().end()}; } /*! @@ -2552,10 +2571,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(); } @@ -2581,27 +2600,26 @@ 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; } } @@ -2616,39 +2634,44 @@ 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: { - 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() ) + case QCP::stNone: { - if( mDataRanges.size() > 1 ) - mDataRanges = QList() << mDataRanges.first(); - if( mDataRanges.first().length() > 1 ) - mDataRanges.first().setEnd( mDataRanges.first().begin() + 1 ); + 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; } - 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; - } } } @@ -2658,21 +2681,20 @@ 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 } /*! @@ -2683,11 +2705,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; - foreach( QCPDataRange dataRange, mDataRanges ) - result.addDataRange( dataRange.intersection( other ), false ); + foreach (QCPDataRange dataRange, mDataRanges) + result.addDataRange(dataRange.intersection(other), false); result.simplify(); return result; } @@ -2696,11 +2718,11 @@ QCPDataSelection QCPDataSelection::intersection( const QCPDataRange& other ) con Returns a data selection containing the points which are both in this data selection and in the data selection \a other. */ -QCPDataSelection QCPDataSelection::intersection( const QCPDataSelection& other ) const +QCPDataSelection QCPDataSelection::intersection(const QCPDataSelection &other) const { QCPDataSelection result; - for( int i = 0; i < other.dataRangeCount(); ++i ) - result += intersection( other.dataRange( i ) ); + for (int i=0; iorientation() == Qt::Horizontal ) - return { axis->pixelToCoord( mRect.left() ), axis->pixelToCoord( mRect.left() + mRect.width() ) }; + if (axis->orientation() == Qt::Horizontal) + return {axis->pixelToCoord(mRect.left()), axis->pixelToCoord(mRect.left()+mRect.width())}; else - return { axis->pixelToCoord( mRect.top() + mRect.height() ), axis->pixelToCoord( mRect.top() ) }; - } - else + return {axis->pixelToCoord(mRect.top()+mRect.height()), axis->pixelToCoord(mRect.top())}; + } else { qDebug() << Q_FUNC_INFO << "called with axis zero"; return {}; @@ -2855,7 +2880,7 @@ QCPRange QCPSelectionRect::range( const QCPAxis* axis ) const \see setBrush */ -void QCPSelectionRect::setPen( const QPen& pen ) +void QCPSelectionRect::setPen(const QPen &pen) { mPen = pen; } @@ -2866,7 +2891,7 @@ void QCPSelectionRect::setPen( const QPen& pen ) \see setPen */ -void QCPSelectionRect::setBrush( const QBrush& brush ) +void QCPSelectionRect::setBrush(const QBrush &brush) { mBrush = brush; } @@ -2877,10 +2902,10 @@ void QCPSelectionRect::setBrush( const QBrush& brush ) */ void QCPSelectionRect::cancel() { - if( mActive ) + if (mActive) { mActive = false; - emit canceled( mRect, nullptr ); + emit canceled(mRect, nullptr); } } @@ -2890,11 +2915,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 @@ -2903,10 +2928,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(); } @@ -2916,11 +2941,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 @@ -2929,19 +2954,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 @@ -2950,19 +2975,20 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 78863 */ +/* modified 2022-11-06T12:45:56, size 78863 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPMarginGroup @@ -3012,13 +3038,14 @@ 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 +3059,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 +3076,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(), nullptr ); // removes itself from mChildren via removeChild + for (int i=elements.size()-1; i>=0; --i) + elements.at(i)->setMarginGroup(it.key(), nullptr); // removes itself from mChildren via removeChild } } @@ -3069,16 +3096,16 @@ 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; - foreach( QCPLayoutElement* el, mChildren.value( side ) ) + foreach (QCPLayoutElement *el, mChildren.value(side)) { - if( !el->autoMargins().testFlag( side ) ) + if (!el->autoMargins().testFlag(side)) continue; - int m = qMax( el->calculateAutoMargin( side ), QCP::getMarginValue( el->minimumMargins(), side ) ); - if( m > result ) + int m = qMax(el->calculateAutoMargin(side), QCP::getMarginValue(el->minimumMargins(), side)); + if (m > result) result = m; } return result; @@ -3090,12 +3117,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 @@ -3104,12 +3131,13 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3176,26 +3204,26 @@ void QCPMarginGroup::removeChild( QCP::MarginSide side, QCPLayoutElement* elemen /*! 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( nullptr ) - , 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(nullptr), + 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, nullptr ); // unregister at margin groups, if there are any + setMarginGroup(QCP::msAll, nullptr); // 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); } /*! @@ -3209,12 +3237,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()); } } @@ -3229,12 +3257,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()); } } @@ -3247,9 +3275,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; } @@ -3265,7 +3293,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; } @@ -3282,12 +3310,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(); } } @@ -3299,9 +3327,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)); } /*! @@ -3311,12 +3339,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(); } } @@ -3328,9 +3356,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)); } /*! @@ -3342,12 +3370,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(); } } @@ -3365,34 +3393,29 @@ 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 ); - - foreach( QCP::MarginSide side, 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); + + foreach (QCP::MarginSide side, sideVector) { - if( marginGroup( side ) != group ) + if (marginGroup(side) != group) { - 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 + 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); } } } @@ -3410,29 +3433,29 @@ void QCPLayoutElement::setMarginGroup( QCP::MarginSides sides, QCPMarginGroup* g 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; const 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); } } } @@ -3453,7 +3476,7 @@ void QCPLayoutElement::update( UpdatePhase phase ) */ QSize QCPLayoutElement::minimumOuterSizeHint() const { - return { mMargins.left() + mMargins.right(), mMargins.top() + mMargins.bottom() }; + return {mMargins.left()+mMargins.right(), mMargins.top()+mMargins.bottom()}; } /*! @@ -3472,7 +3495,7 @@ QSize QCPLayoutElement::minimumOuterSizeHint() const */ QSize QCPLayoutElement::maximumOuterSizeHint() const { - return { QWIDGETSIZE_MAX, QWIDGETSIZE_MAX }; + return {QWIDGETSIZE_MAX, QWIDGETSIZE_MAX}; } /*! @@ -3482,9 +3505,9 @@ QSize QCPLayoutElement::maximumOuterSizeHint() const \warning There may be \c nullptr entries in the returned list. For example, QCPLayoutGrid may have empty cells which yield \c nullptr at the respective index. */ -QList QCPLayoutElement::elements( bool recursive ) const +QList QCPLayoutElement::elements(bool recursive) const { - Q_UNUSED( recursive ) + Q_UNUSED(recursive) return QList(); } @@ -3499,24 +3522,23 @@ 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; } @@ -3525,12 +3547,12 @@ double QCPLayoutElement::selectTest( const QPointF& pos, bool onlySelectable, QV 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); } } @@ -3543,9 +3565,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 @@ -3654,39 +3676,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; i < elCount; ++i ) + 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; i < c; ++i ) - result.append( elementAt( i ) ); - if( recursive ) + for (int i=0; ielements( recursive ); + if (result.at(i)) + result << result.at(i)->elements(recursive); } } return result; @@ -3714,14 +3736,13 @@ 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; } @@ -3736,14 +3757,13 @@ 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; } @@ -3755,10 +3775,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(); } @@ -3773,9 +3793,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(); } @@ -3795,6 +3815,7 @@ void QCPLayout::updateLayout() { } + /*! \internal Associates \a el with this layout. This is done by setting the \ref QCPLayoutElement::layout, the @@ -3807,18 +3828,17 @@ 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"; } @@ -3832,16 +3852,15 @@ 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 = nullptr; - el->setParentLayerable( nullptr ); - el->setParent( mParentPlot ); + el->setParentLayerable(nullptr); + 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"; } @@ -3874,52 +3893,52 @@ 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 < sectionCount; ++i ) - minSizeSum += minSizes.at( i ); - if( totalSize < minSizeSum ) + for (int i=0; i minimumLockedSections; QList unfinishedSections; - for( int i = 0; i < sectionCount; ++i ) - unfinishedSections.append( i ); + for (int i=0; i QCPLayout::getSectionSizes( QVector maxSizes, QVector min // 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; - foreach( int secId, unfinishedSections ) - stretchFactorSum += stretchFactors.at( secId ); - double nextMaxLimit = freeSize / stretchFactorSum; - if( nextMax < nextMaxLimit ) // next maximum is actually hit, move forward to that point and fix the size of that section + foreach (int secId, unfinishedSections) + stretchFactorSum += stretchFactors.at(secId); + double nextMaxLimit = freeSize/stretchFactorSum; + if (nextMax < nextMaxLimit) // next maximum is actually hit, move forward to that point and fix the size of that section { - foreach( int secId, unfinishedSections ) + foreach (int secId, unfinishedSections) { - sectionSizes[secId] += nextMax * stretchFactors.at( secId ); // increment all sections - freeSize -= nextMax * stretchFactors.at( secId ); + sectionSizes[secId] += nextMax*stretchFactors.at(secId); // increment all sections + freeSize -= nextMax*stretchFactors.at(secId); } - unfinishedSections.removeOne( nextId ); // exclude the section that is now at maximum from further changes - } - else // next maximum isn't hit, just distribute rest of free space on remaining sections + unfinishedSections.removeOne(nextId); // exclude the section that is now at maximum from further changes + } else // next maximum isn't hit, just distribute rest of free space on remaining sections { - foreach( int secId, unfinishedSections ) - sectionSizes[secId] += nextMaxLimit * stretchFactors.at( secId ); // increment all sections + foreach (int secId, unfinishedSections) + sectionSizes[secId] += nextMaxLimit*stretchFactors.at(secId); // increment all sections unfinishedSections.clear(); } } - if( innerIterations == sectionCount * 2 ) + if (innerIterations == sectionCount*2) qDebug() << Q_FUNC_INFO << "Exceeded maximum expected inner iteration count, layouting aborted. Input was:" << maxSizes << minSizes << stretchFactors << totalSize; - + // now check whether the resulting section sizes violate minimum restrictions: bool foundMinimumViolation = false; - for( int i = 0; i < sectionSizes.size(); ++i ) + for (int i=0; i result( sectionCount ); - for( int i = 0; i < sectionCount; ++i ) - result[i] = qRound( sectionSizes.at( i ) ); + + QVector result(sectionCount); + for (int i=0; i QCPLayout::getSectionSizes( QVector maxSizes, QVector min 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 { minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), - minOuter.height() > 0 ? minOuter.height() : minOuterHint.height() }; + + return {minOuter.width() > 0 ? minOuter.width() : minOuterHint.width(), + minOuter.height() > 0 ? minOuter.height() : minOuterHint.height()}; } /*! \internal @@ -4024,19 +4042,20 @@ 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 { maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), - maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height() }; + + return {maxOuter.width() < QWIDGETSIZE_MAX ? maxOuter.width() : maxOuterHint.width(), + maxOuter.height() < QWIDGETSIZE_MAX ? maxOuter.height() : maxOuterHint.height()}; } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLayoutGrid //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4082,8 +4101,11 @@ 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) { } @@ -4102,25 +4124,24 @@ 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 nullptr; } + /*! \overload Adds the \a element to cell with \a row and \a column. If \a element is already in a layout, it @@ -4135,19 +4156,18 @@ 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; } @@ -4162,35 +4182,34 @@ 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); } /*! @@ -4199,10 +4218,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; } @@ -4219,16 +4238,15 @@ 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; } @@ -4244,21 +4262,20 @@ 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 < mColumnStretchFactors.size(); ++i ) + 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; } @@ -4299,21 +4315,20 @@ 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 < mRowStretchFactors.size(); ++i ) + for (int i=0; i& factors ) \see setRowSpacing */ -void QCPLayoutGrid::setColumnSpacing( int pixels ) +void QCPLayoutGrid::setColumnSpacing(int pixels) { mColumnSpacing = pixels; } @@ -4332,7 +4347,7 @@ void QCPLayoutGrid::setColumnSpacing( int pixels ) \see setColumnSpacing */ -void QCPLayoutGrid::setRowSpacing( int pixels ) +void QCPLayoutGrid::setRowSpacing(int pixels) { mRowSpacing = pixels; } @@ -4354,9 +4369,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); } /*! @@ -4384,28 +4399,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 < elCount; ++i ) + 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(); ++i ) + 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(); ++col ) - newRow.append( nullptr ); - mElements.insert( newIndex, newRow ); + for (int col=0; col columnCount() ) + if (newIndex > columnCount()) newIndex = columnCount(); - - mColumnStretchFactors.insert( newIndex, 1 ); - for( int row = 0; row < rowCount(); ++row ) - mElements[row].insert( newIndex, nullptr ); + + 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; } @@ -4543,32 +4554,34 @@ 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; + } } } @@ -4576,27 +4589,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 < rowCount(); ++row ) + 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 < columnCount(); ++col ) + 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))); } } } @@ -4609,15 +4622,14 @@ 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 nullptr; } @@ -4629,17 +4641,16 @@ 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] = nullptr; return el; - } - else + } else { qDebug() << Q_FUNC_INFO << "Attempt to take invalid index:" << index; return nullptr; @@ -4647,41 +4658,40 @@ 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 < elementCount(); ++i ) + 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; i < elCount; ++i ) - result.append( elementAt( i ) ); - if( recursive ) + for (int i=0; ielements( recursive ); + if (result.at(i)) + result << result.at(i)->elements(recursive); } } return result; @@ -4693,43 +4703,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 < columnCount(); ++col ) + for (int col=0; col= 0; --col ) + for (int col=columnCount()-1; col>=0; --col) { bool hasElements = false; - for( int row = 0; row < rowCount(); ++row ) + for (int row=0; row minColWidths, minRowHeights; - getMinimumRowColSizes( &minColWidths, &minRowHeights ); - QSize result( 0, 0 ); - foreach( int w, minColWidths ) + getMinimumRowColSizes(&minColWidths, &minRowHeights); + QSize result(0, 0); + foreach (int w, minColWidths) result.rwidth() += w; - foreach( int h, minRowHeights ) + foreach (int h, minRowHeights) result.rheight() += h; - 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(); + 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(); return result; } @@ -4755,21 +4765,21 @@ QSize QCPLayoutGrid::minimumOuterSizeHint() const QSize QCPLayoutGrid::maximumOuterSizeHint() const { QVector maxColWidths, maxRowHeights; - getMaximumRowColSizes( &maxColWidths, &maxRowHeights ); - - QSize result( 0, 0 ); - foreach( int w, maxColWidths ) - result.setWidth( qMin( result.width() + w, QWIDGETSIZE_MAX ) ); - foreach( int h, maxRowHeights ) - result.setHeight( qMin( result.height() + h, 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 ); + getMaximumRowColSizes(&maxColWidths, &maxRowHeights); + + QSize result(0, 0); + foreach (int w, maxColWidths) + result.setWidth(qMin(result.width()+w, QWIDGETSIZE_MAX)); + foreach (int h, maxRowHeights) + result.setHeight(qMin(result.height()+h, 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; } @@ -4786,21 +4796,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 < rowCount(); ++row ) + *minColWidths = QVector(columnCount(), 0); + *minRowHeights = QVector(rowCount(), 0); + for (int row=0; rowat( 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(); } } } @@ -4819,26 +4829,27 @@ 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 < rowCount(); ++row ) + *maxColWidths = QVector(columnCount(), QWIDGETSIZE_MAX); + *maxRowHeights = QVector(rowCount(), QWIDGETSIZE_MAX); + for (int row=0; rowat( 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4887,10 +4898,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; @@ -4902,14 +4913,14 @@ 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; -#if QT_VERSION < QT_VERSION_CHECK( 5, 2, 0 ) +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) return nullptr; #else return {}; @@ -4921,10 +4932,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; @@ -4937,9 +4948,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; @@ -4953,9 +4964,9 @@ void QCPLayoutInset::setInsetPlacement( int index, QCPLayoutInset::InsetPlacemen 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; @@ -4972,9 +4983,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; @@ -4983,45 +4994,38 @@ void QCPLayoutInset::setInsetRect( int index, const QRectF& rect ) /* inherits documentation from base class */ void QCPLayoutInset::updateLayout() { - for( int i = 0; i < mElements.size(); ++i ) + 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 = QRect(int( rect().x()+rect().width()*mInsetRect.at(i).x() ), + int( rect().y()+rect().height()*mInsetRect.at(i).y() ), + int( rect().width()*mInsetRect.at(i).width() ), + int( 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()); + } 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( int( 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( int( rect().y() + rect().height() * 0.5 - finalMinSize.height() * 0.5 ) ); // default to Qt::AlignVCenter + 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(int( 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(int( rect().y()+rect().height()*0.5-finalMinSize.height()*0.5 )); // default to Qt::AlignVCenter } - mElements.at( i )->setOuterRect( insetRect ); + mElements.at(i)->setOuterRect(insetRect); } } @@ -5032,27 +5036,26 @@ 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 nullptr; } /* 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 nullptr; @@ -5060,21 +5063,20 @@ 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; i < elementCount(); ++i ) + for (int i=0; irealVisibility() && el->selectTest( pos, onlySelectable ) >= 0 ) - return mParentPlot->selectionTolerance() * 0.99; + if (el->realVisibility() && el->selectTest(pos, onlySelectable) >= 0) + return mParentPlot->selectionTolerance()*0.99; } return -1; } @@ -5115,19 +5117,18 @@ double QCPLayoutInset::selectTest( const QPointF& pos, bool onlySelectable, QVar \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 nullptr element"; } @@ -5142,25 +5143,25 @@ void QCPLayoutInset::addElement( QCPLayoutElement* element, Qt::Alignment alignm \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 nullptr element"; } /* end of 'src/layout.cpp' */ + /* including file 'src/lineending.cpp' */ -/* modified 2021-03-29T02:30:44, size 11189 */ +/* modified 2022-11-06T12:45:56, size 11189 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLineEnding @@ -5189,23 +5190,29 @@ 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; } @@ -5216,7 +5223,7 @@ void QCPLineEnding::setStyle( QCPLineEnding::EndingStyle style ) \see setLength */ -void QCPLineEnding::setWidth( double width ) +void QCPLineEnding::setWidth(double width) { mWidth = width; } @@ -5227,7 +5234,7 @@ void QCPLineEnding::setWidth( double width ) \see setWidth */ -void QCPLineEnding::setLength( double length ) +void QCPLineEnding::setLength(double length) { mLength = length; } @@ -5240,7 +5247,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; } @@ -5256,23 +5263,24 @@ void QCPLineEnding::setInverted( bool inverted ) */ double QCPLineEnding::boundingDistance() const { - switch( mStyle ) + switch (mStyle) { - case esNone: - return 0; + 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 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; } @@ -5290,25 +5298,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; } @@ -5318,106 +5326,119 @@ 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: { - 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: { - QCPVector2D shift; - if( !qFuzzyIsNull( painter->pen().widthF() ) || painter->modes().testFlag( QCPPainter::pmNonCosmetic ) ) - shift = dir.normalized() * qMax( qreal( 1.0 ), painter->pen().widthF() ) * qreal( 0.5 ); - // 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 ) + shift ).toPointF(), - ( pos - widthVec - lengthVec * 0.2 * ( mInverted ? -1 : 1 ) + shift ).toPointF() ); - break; - } + 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: + { + QCPVector2D shift; + if (!qFuzzyIsNull(painter->pen().widthF()) || painter->modes().testFlag(QCPPainter::pmNonCosmetic)) + shift = dir.normalized()*qMax(qreal(1.0), painter->pen().widthF())*qreal(0.5); + // 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)+shift).toPointF(), + (pos-widthVec-lengthVec*0.2*(mInverted?-1:1)+shift).toPointF()); + break; + } } } @@ -5426,14 +5447,16 @@ void QCPLineEnding::draw( QCPPainter* painter, const QCPVector2D& pos, const QCP 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/labelpainter.cpp' */ -/* modified 2021-03-29T02:30:44, size 27296 */ +/* modified 2022-11-06T12:45:56, size 27519 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPLabelPainterPrivate @@ -5448,8 +5471,8 @@ void QCPLineEnding::draw( QCPPainter* painter, const QCPVector2D& pos, double an */ -const QChar QCPLabelPainterPrivate::SymbolDot( 183 ); -const QChar QCPLabelPainterPrivate::SymbolCross( 215 ); +const QChar QCPLabelPainterPrivate::SymbolDot(183); +const QChar QCPLabelPainterPrivate::SymbolCross(215); /*! Constructs a QCPLabelPainterPrivate instance. Make sure to not create a new @@ -5458,8 +5481,18 @@ const QChar QCPLabelPainterPrivate::SymbolCross( 215 ); the \a parentPlot does not take ownership of the label painter. Make sure to delete it appropriately. */ -QCPLabelPainterPrivate::QCPLabelPainterPrivate( QCustomPlot* parentPlot ) - : mAnchorMode( amRectangular ), mAnchorSide( asLeft ), mAnchorReferenceType( artNormal ), mColor( Qt::black ), mPadding( 0 ), mRotation( 0 ), mSubstituteExponent( true ), mMultiplicationSymbol( QChar( 215 ) ), mAbbreviateDecimalPowers( false ), mParentPlot( parentPlot ), mLabelCache( 16 ) +QCPLabelPainterPrivate::QCPLabelPainterPrivate(QCustomPlot *parentPlot) : + mAnchorMode(amRectangular), + mAnchorSide(asLeft), + mAnchorReferenceType(artNormal), + mColor(Qt::black), + mPadding(0), + mRotation(0), + mSubstituteExponent(true), + mMultiplicationSymbol(QChar(215)), + mAbbreviateDecimalPowers(false), + mParentPlot(parentPlot), + mLabelCache(16) { analyzeFontMetrics(); } @@ -5468,68 +5501,68 @@ QCPLabelPainterPrivate::~QCPLabelPainterPrivate() { } -void QCPLabelPainterPrivate::setAnchorSide( AnchorSide side ) +void QCPLabelPainterPrivate::setAnchorSide(AnchorSide side) { mAnchorSide = side; } -void QCPLabelPainterPrivate::setAnchorMode( AnchorMode mode ) +void QCPLabelPainterPrivate::setAnchorMode(AnchorMode mode) { mAnchorMode = mode; } -void QCPLabelPainterPrivate::setAnchorReference( const QPointF& pixelPoint ) +void QCPLabelPainterPrivate::setAnchorReference(const QPointF &pixelPoint) { mAnchorReference = pixelPoint; } -void QCPLabelPainterPrivate::setAnchorReferenceType( AnchorReferenceType type ) +void QCPLabelPainterPrivate::setAnchorReferenceType(AnchorReferenceType type) { mAnchorReferenceType = type; } -void QCPLabelPainterPrivate::setFont( const QFont& font ) +void QCPLabelPainterPrivate::setFont(const QFont &font) { - if( mFont != font ) + if (mFont != font) { mFont = font; analyzeFontMetrics(); } } -void QCPLabelPainterPrivate::setColor( const QColor& color ) +void QCPLabelPainterPrivate::setColor(const QColor &color) { mColor = color; } -void QCPLabelPainterPrivate::setPadding( int padding ) +void QCPLabelPainterPrivate::setPadding(int padding) { mPadding = padding; } -void QCPLabelPainterPrivate::setRotation( double rotation ) +void QCPLabelPainterPrivate::setRotation(double rotation) { - mRotation = qBound( -90.0, rotation, 90.0 ); + mRotation = qBound(-90.0, rotation, 90.0); } -void QCPLabelPainterPrivate::setSubstituteExponent( bool enabled ) +void QCPLabelPainterPrivate::setSubstituteExponent(bool enabled) { mSubstituteExponent = enabled; } -void QCPLabelPainterPrivate::setMultiplicationSymbol( QChar symbol ) +void QCPLabelPainterPrivate::setMultiplicationSymbol(QChar symbol) { mMultiplicationSymbol = symbol; } -void QCPLabelPainterPrivate::setAbbreviateDecimalPowers( bool enabled ) +void QCPLabelPainterPrivate::setAbbreviateDecimalPowers(bool enabled) { mAbbreviateDecimalPowers = enabled; } -void QCPLabelPainterPrivate::setCacheSize( int labelCount ) +void QCPLabelPainterPrivate::setCacheSize(int labelCount) { - mLabelCache.setMaxCost( labelCount ); + mLabelCache.setMaxCost(labelCount); } int QCPLabelPainterPrivate::cacheSize() const @@ -5537,28 +5570,25 @@ int QCPLabelPainterPrivate::cacheSize() const return mLabelCache.maxCost(); } -void QCPLabelPainterPrivate::drawTickLabel( QCPPainter* painter, const QPointF& tickPos, const QString& text ) +void QCPLabelPainterPrivate::drawTickLabel(QCPPainter *painter, const QPointF &tickPos, const QString &text) { double realRotation = mRotation; - + AnchorSide realSide = mAnchorSide; // for circular axes, the anchor side is determined depending on the quadrant of tickPos with respect to mCircularReference - if( mAnchorMode == amSkewedUpright ) + if (mAnchorMode == amSkewedUpright) { - realSide = skewedAnchorSide( tickPos, 0.2, 0.3 ); - } - else if( mAnchorMode == amSkewedRotated ) // in this mode every label is individually rotated to match circle tangent + realSide = skewedAnchorSide(tickPos, 0.2, 0.3); + } else if (mAnchorMode == amSkewedRotated) // in this mode every label is individually rotated to match circle tangent { - realSide = skewedAnchorSide( tickPos, 0, 0 ); - realRotation += QCPVector2D( tickPos - mAnchorReference ).angle() / M_PI * 180.0; - if( realRotation > 90 ) - realRotation -= 180; - else if( realRotation < -90 ) - realRotation += 180; + realSide = skewedAnchorSide(tickPos, 0, 0); + realRotation += QCPVector2D(tickPos-mAnchorReference).angle()/M_PI*180.0; + if (realRotation > 90) realRotation -= 180; + else if (realRotation < -90) realRotation += 180; } - - realSide = rotationCorrectedSide( realSide, realRotation ); // rotation angles may change the true anchor side of the label - drawLabelMaybeCached( painter, mFont, mColor, getAnchorPos( tickPos ), realSide, realRotation, text ); + + realSide = rotationCorrectedSide(realSide, realRotation); // rotation angles may change the true anchor side of the label + drawLabelMaybeCached(painter, mFont, mColor, getAnchorPos(tickPos), realSide, realRotation, text); } /*! \internal @@ -5621,13 +5651,13 @@ void QCPLabelPainterPrivate::clearCache() QByteArray QCPLabelPainterPrivate::generateLabelParameterHash() const { QByteArray result; - result.append( QByteArray::number( mParentPlot->bufferDevicePixelRatio() ) ); - result.append( QByteArray::number( mRotation ) ); - //result.append(QByteArray::number((int)tickLabelSide)); TODO: check whether this is really a cache-invalidating property - result.append( QByteArray::number( (int)mSubstituteExponent ) ); - result.append( QString( mMultiplicationSymbol ).toUtf8() ); - result.append( mColor.name().toLatin1() + QByteArray::number( mColor.alpha(), 16 ) ); - result.append( mFont.toString().toLatin1() ); + result.append(QByteArray::number(mParentPlot->bufferDevicePixelRatio())); + result.append(QByteArray::number(mRotation)); + //result.append(QByteArray::number(int(tickLabelSide))); TODO: check whether this is really a cache-invalidating property + result.append(QByteArray::number(int(mSubstituteExponent))); + result.append(QString(mMultiplicationSymbol).toUtf8()); + result.append(mColor.name().toLatin1()+QByteArray::number(mColor.alpha(), 16)); + result.append(mFont.toString().toLatin1()); return result; } @@ -5650,21 +5680,20 @@ QByteArray QCPLabelPainterPrivate::generateLabelParameterHash() const superscripted powers, the font is temporarily made smaller by a fixed factor (see \ref getTickLabelData). */ -void QCPLabelPainterPrivate::drawLabelMaybeCached( QCPPainter* painter, const QFont& font, const QColor& color, const QPointF& pos, AnchorSide side, double rotation, const QString& text ) +void QCPLabelPainterPrivate::drawLabelMaybeCached(QCPPainter *painter, const QFont &font, const QColor &color, const QPointF &pos, AnchorSide side, double rotation, const QString &text) { // warning: if you change anything here, also adapt getMaxTickLabelSize() accordingly! - if( text.isEmpty() ) - return; + if (text.isEmpty()) return; QSize finalSize; - 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 { - QByteArray key = cacheKey( text, color, rotation, side ); - CachedLabel* cachedLabel = mLabelCache.take( QString::fromUtf8( key ) ); // attempt to take label from cache (don't use object() because we want ownership/prevent deletion during our operations, we re-insert it afterwards) - if( !cachedLabel ) // no cached label existed, create it + QByteArray key = cacheKey(text, color, rotation, side); + CachedLabel *cachedLabel = mLabelCache.take(QString::fromUtf8(key)); // attempt to take label from cache (don't use object() because we want ownership/prevent deletion during our operations, we re-insert it afterwards) + if (!cachedLabel) // no cached label existed, create it { - LabelData labelData = getTickLabelData( font, color, rotation, side, text ); - cachedLabel = createCachedLabel( labelData ); + LabelData labelData = getTickLabelData(font, color, rotation, side, text); + cachedLabel = createCachedLabel(labelData); } // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): bool labelClippedByBorder = false; @@ -5677,19 +5706,18 @@ void QCPLabelPainterPrivate::drawLabelMaybeCached( QCPPainter* painter, const QF 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( pos + cachedLabel->offset, cachedLabel->pixmap ); - finalSize = cachedLabel->pixmap.size() / mParentPlot->bufferDevicePixelRatio(); // TODO: collect this in a member rect list? + painter->drawPixmap(pos+cachedLabel->offset, cachedLabel->pixmap); + finalSize = cachedLabel->pixmap.size()/mParentPlot->bufferDevicePixelRatio(); // TODO: collect this in a member rect list? } - mLabelCache.insert( QString::fromUtf8( key ), cachedLabel ); - } - else // label caching disabled, draw text directly on surface: + mLabelCache.insert(QString::fromUtf8(key), cachedLabel); + } else // label caching disabled, draw text directly on surface: { - LabelData labelData = getTickLabelData( font, color, rotation, side, text ); + LabelData labelData = getTickLabelData(font, color, rotation, side, text); // if label would be partly clipped by widget border on sides, don't draw it (only for outside tick labels): - bool labelClippedByBorder = false; - /* + bool labelClippedByBorder = false; + /* if (tickLabelSide == QCPAxis::lsOutside) { if (QCPAxis::orientation(type) == Qt::Horizontal) @@ -5698,9 +5726,9 @@ void QCPLabelPainterPrivate::drawLabelMaybeCached( QCPPainter* painter, const QF labelClippedByBorder = finalPosition.y()+(labelData.rotatedTotalBounds.height()+labelData.rotatedTotalBounds.top()) > viewportRect.bottom() || finalPosition.y()+labelData.rotatedTotalBounds.top() < viewportRect.top(); } */ - if( !labelClippedByBorder ) + if (!labelClippedByBorder) { - drawText( painter, pos, labelData ); + drawText(painter, pos, labelData); finalSize = labelData.rotatedTotalBounds.size(); } } @@ -5713,39 +5741,37 @@ void QCPLabelPainterPrivate::drawLabelMaybeCached( QCPPainter* painter, const QF */ } -QPointF QCPLabelPainterPrivate::getAnchorPos( const QPointF& tickPos ) +QPointF QCPLabelPainterPrivate::getAnchorPos(const QPointF &tickPos) { - switch( mAnchorMode ) + switch (mAnchorMode) { - case amRectangular: { - switch( mAnchorSide ) + case amRectangular: { - case asLeft: - return tickPos + QPointF( mPadding, 0 ); - case asRight: - return tickPos + QPointF( -mPadding, 0 ); - case asTop: - return tickPos + QPointF( 0, mPadding ); - case asBottom: - return tickPos + QPointF( 0, -mPadding ); - case asTopLeft: - return tickPos + QPointF( mPadding * M_SQRT1_2, mPadding * M_SQRT1_2 ); - case asTopRight: - return tickPos + QPointF( -mPadding * M_SQRT1_2, mPadding * M_SQRT1_2 ); - case asBottomRight: - return tickPos + QPointF( -mPadding * M_SQRT1_2, -mPadding * M_SQRT1_2 ); - case asBottomLeft: - return tickPos + QPointF( mPadding * M_SQRT1_2, -mPadding * M_SQRT1_2 ); + switch (mAnchorSide) + { + case asLeft: return tickPos+QPointF(mPadding, 0); + case asRight: return tickPos+QPointF(-mPadding, 0); + case asTop: return tickPos+QPointF(0, mPadding); + case asBottom: return tickPos+QPointF(0, -mPadding); + case asTopLeft: return tickPos+QPointF(mPadding*M_SQRT1_2, mPadding*M_SQRT1_2); + case asTopRight: return tickPos+QPointF(-mPadding*M_SQRT1_2, mPadding*M_SQRT1_2); + case asBottomRight: return tickPos+QPointF(-mPadding*M_SQRT1_2, -mPadding*M_SQRT1_2); + case asBottomLeft: return tickPos+QPointF(mPadding*M_SQRT1_2, -mPadding*M_SQRT1_2); + default: qDebug() << Q_FUNC_INFO << "invalid mode for anchor side: " << mAnchorSide; break; + } + break; } - } - case amSkewedUpright: - case amSkewedRotated: { - QCPVector2D anchorNormal( tickPos - mAnchorReference ); - if( mAnchorReferenceType == artTangent ) - anchorNormal = anchorNormal.perpendicular(); - anchorNormal.normalize(); - return tickPos + ( anchorNormal * mPadding ).toPointF(); - } + case amSkewedUpright: + // fall through + case amSkewedRotated: + { + QCPVector2D anchorNormal(tickPos-mAnchorReference); + if (mAnchorReferenceType == artTangent) + anchorNormal = anchorNormal.perpendicular(); + anchorNormal.normalize(); + return tickPos+(anchorNormal*mPadding).toPointF(); + } + default: qDebug() << Q_FUNC_INFO << "invalid mode for anchor mode: " << mAnchorMode; break; } return tickPos; } @@ -5759,33 +5785,32 @@ QPointF QCPLabelPainterPrivate::getAnchorPos( const QPointF& tickPos ) directly draw the labels on the QCustomPlot surface when label caching is disabled, i.e. when QCP::phCacheLabels plotting hint is not set. */ -void QCPLabelPainterPrivate::drawText( QCPPainter* painter, const QPointF& pos, const LabelData& labelData ) const +void QCPLabelPainterPrivate::drawText(QCPPainter *painter, const QPointF &pos, const LabelData &labelData) const { // backup painter settings that we're about to change: QTransform oldTransform = painter->transform(); QFont oldFont = painter->font(); QPen oldPen = painter->pen(); - + // transform painter to position/rotation: - painter->translate( pos ); - painter->setTransform( labelData.transform, true ); - + painter->translate(pos); + painter->setTransform(labelData.transform, true); + // draw text: - painter->setFont( labelData.baseFont ); - painter->setPen( QPen( labelData.color ) ); - if( !labelData.expPart.isEmpty() ) // use superscripted exponent typesetting + painter->setFont(labelData.baseFont); + painter->setPen(QPen(labelData.color)); + if (!labelData.expPart.isEmpty()) // use superscripted exponent typesetting { - 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->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->drawText( 0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart ); + painter->drawText(0, 0, labelData.totalBounds.width(), labelData.totalBounds.height(), Qt::TextDontClip | Qt::AlignHCenter, labelData.basePart); } - + /* Debug code to draw label bounding boxes, baseline, and capheight painter->save(); painter->setPen(QPen(QColor(0, 0, 0, 150))); @@ -5797,11 +5822,11 @@ void QCPLabelPainterPrivate::drawText( QCPPainter* painter, const QPointF& pos, painter->drawLine(QLineF(0, baseline-mLetterCapHeight, labelData.totalBounds.width(), baseline-mLetterCapHeight)); painter->restore(); */ - + // reset painter settings to what it was before: - painter->setTransform( oldTransform ); - painter->setFont( oldFont ); - painter->setPen( oldPen ); + painter->setTransform(oldTransform); + painter->setFont(oldFont); + painter->setPen(oldPen); } /*! \internal @@ -5812,95 +5837,94 @@ void QCPLabelPainterPrivate::drawText( QCPPainter* painter, const QPointF& pos, processed by \ref getTickLabelDrawOffset and \ref drawTickLabel. It splits the text into base and exponent if necessary (member substituteExponent) and calculates appropriate bounding boxes. */ -QCPLabelPainterPrivate::LabelData QCPLabelPainterPrivate::getTickLabelData( const QFont& font, const QColor& color, double rotation, AnchorSide side, const QString& text ) const +QCPLabelPainterPrivate::LabelData QCPLabelPainterPrivate::getTickLabelData(const QFont &font, const QColor &color, double rotation, AnchorSide side, const QString &text) const { LabelData result; result.rotation = rotation; result.side = side; result.color = color; - + // 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( mSubstituteExponent ) + 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 (mSubstituteExponent) { - 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 - - QFontMetrics baseFontMetrics( result.baseFont ); - 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 + + QFontMetrics baseFontMetrics(result.baseFont); + 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( mAbbreviateDecimalPowers && result.basePart == QLatin1String( "1" ) ) - result.basePart = QLatin1String( "10" ); + if (mAbbreviateDecimalPowers && result.basePart == QLatin1String("1")) + result.basePart = QLatin1String("10"); else - result.basePart += QString( mMultiplicationSymbol ) + QLatin1String( "10" ); - result.expPart = text.mid( ePos + 1, eLast - ePos ); + result.basePart += QString(mMultiplicationSymbol) + 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 = baseFontMetrics.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 = baseFontMetrics.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 = baseFontMetrics.boundingRect( 0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart ); + result.totalBounds = baseFontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter, result.basePart); } - result.totalBounds.moveTopLeft( QPoint( 0, 0 ) ); - applyAnchorTransform( result ); - result.rotatedTotalBounds = result.transform.mapRect( result.totalBounds ); - + result.totalBounds.moveTopLeft(QPoint(0, 0)); + applyAnchorTransform(result); + result.rotatedTotalBounds = result.transform.mapRect(result.totalBounds); + return result; } -void QCPLabelPainterPrivate::applyAnchorTransform( LabelData& labelData ) const +void QCPLabelPainterPrivate::applyAnchorTransform(LabelData &labelData) const { - if( !qFuzzyIsNull( labelData.rotation ) ) - labelData.transform.rotate( labelData.rotation ); // rotates effectively clockwise (due to flipped y axis of painter vs widget coordinate system) - + if (!qFuzzyIsNull(labelData.rotation)) + labelData.transform.rotate(labelData.rotation); // rotates effectively clockwise (due to flipped y axis of painter vs widget coordinate system) + // from now on we translate in rotated label-local coordinate system. // shift origin of coordinate system to appropriate point on label: - labelData.transform.translate( 0, -labelData.totalBounds.height() + mLetterDescent + mLetterCapHeight ); // shifts origin to true top of capital (or number) characters - - if( labelData.side == asLeft || labelData.side == asRight ) // anchor is centered vertically - labelData.transform.translate( 0, -mLetterCapHeight / 2.0 ); - else if( labelData.side == asTop || labelData.side == asBottom ) // anchor is centered horizontally - labelData.transform.translate( -labelData.totalBounds.width() / 2.0, 0 ); - - if( labelData.side == asTopRight || labelData.side == asRight || labelData.side == asBottomRight ) // anchor is at right - labelData.transform.translate( -labelData.totalBounds.width(), 0 ); - if( labelData.side == asBottomLeft || labelData.side == asBottom || labelData.side == asBottomRight ) // anchor is at bottom (no elseif!) - labelData.transform.translate( 0, -mLetterCapHeight ); + labelData.transform.translate(0, -labelData.totalBounds.height()+mLetterDescent+mLetterCapHeight); // shifts origin to true top of capital (or number) characters + + if (labelData.side == asLeft || labelData.side == asRight) // anchor is centered vertically + labelData.transform.translate(0, -mLetterCapHeight/2.0); + else if (labelData.side == asTop || labelData.side == asBottom) // anchor is centered horizontally + labelData.transform.translate(-labelData.totalBounds.width()/2.0, 0); + + if (labelData.side == asTopRight || labelData.side == asRight || labelData.side == asBottomRight) // anchor is at right + labelData.transform.translate(-labelData.totalBounds.width(), 0); + if (labelData.side == asBottomLeft || labelData.side == asBottom || labelData.side == asBottomRight) // anchor is at bottom (no elseif!) + labelData.transform.translate(0, -mLetterCapHeight); } /*! \internal @@ -5933,118 +5957,92 @@ void QCPLabelPainterPrivate::getMaxTickLabelSize(const QFont &font, const QStrin } */ -QCPLabelPainterPrivate::CachedLabel* QCPLabelPainterPrivate::createCachedLabel( const LabelData& labelData ) const +QCPLabelPainterPrivate::CachedLabel *QCPLabelPainterPrivate::createCachedLabel(const LabelData &labelData) const { - CachedLabel* result = new CachedLabel; - + CachedLabel *result = new CachedLabel; + // allocate pixmap with the correct size and pixel ratio: - if( !qFuzzyCompare( 1.0, mParentPlot->bufferDevicePixelRatio() ) ) + if (!qFuzzyCompare(1.0, mParentPlot->bufferDevicePixelRatio())) { - result->pixmap = QPixmap( labelData.rotatedTotalBounds.size() * mParentPlot->bufferDevicePixelRatio() ); + result->pixmap = QPixmap(labelData.rotatedTotalBounds.size()*mParentPlot->bufferDevicePixelRatio()); #ifdef QCP_DEVICEPIXELRATIO_SUPPORTED -#ifdef QCP_DEVICEPIXELRATIO_FLOAT - result->pixmap.setDevicePixelRatio( mParentPlot->devicePixelRatioF() ); -#else - result->pixmap.setDevicePixelRatio( mParentPlot->devicePixelRatio() ); +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + result->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + result->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif #endif -#endif - } - else - result->pixmap = QPixmap( labelData.rotatedTotalBounds.size() ); - result->pixmap.fill( Qt::transparent ); - + } else + result->pixmap = QPixmap(labelData.rotatedTotalBounds.size()); + result->pixmap.fill(Qt::transparent); + // draw the label into the pixmap // offset is between label anchor and topleft of cache pixmap, so pixmap can be drawn at pos+offset to make the label anchor appear at pos. // We use rotatedTotalBounds.topLeft() because rotatedTotalBounds is in a coordinate system where the label anchor is at (0, 0) result->offset = labelData.rotatedTotalBounds.topLeft(); - QCPPainter cachePainter( &result->pixmap ); - drawText( &cachePainter, -result->offset, labelData ); + QCPPainter cachePainter(&result->pixmap); + drawText(&cachePainter, -result->offset, labelData); return result; } -QByteArray QCPLabelPainterPrivate::cacheKey( const QString& text, const QColor& color, double rotation, AnchorSide side ) const +QByteArray QCPLabelPainterPrivate::cacheKey(const QString &text, const QColor &color, double rotation, AnchorSide side) const { - return text.toUtf8() + - QByteArray::number( color.red() + 256 * color.green() + 65536 * color.blue(), 36 ) + - QByteArray::number( color.alpha() + 256 * (int)side, 36 ) + - QByteArray::number( (int)( rotation * 100 ) % 36000, 36 ); + return text.toUtf8()+ + QByteArray::number(color.red()+256*color.green()+65536*color.blue(), 36)+ + QByteArray::number(color.alpha()+256*int(side), 36)+ + QByteArray::number(int(rotation*100), 36); } -QCPLabelPainterPrivate::AnchorSide QCPLabelPainterPrivate::skewedAnchorSide( const QPointF& tickPos, double sideExpandHorz, double sideExpandVert ) const +QCPLabelPainterPrivate::AnchorSide QCPLabelPainterPrivate::skewedAnchorSide(const QPointF &tickPos, double sideExpandHorz, double sideExpandVert) const { - QCPVector2D anchorNormal = QCPVector2D( tickPos - mAnchorReference ); - if( mAnchorReferenceType == artTangent ) + QCPVector2D anchorNormal = QCPVector2D(tickPos-mAnchorReference); + if (mAnchorReferenceType == artTangent) anchorNormal = anchorNormal.perpendicular(); const double radius = anchorNormal.length(); - const double sideHorz = sideExpandHorz * radius; - const double sideVert = sideExpandVert * radius; - if( anchorNormal.x() > sideHorz ) + const double sideHorz = sideExpandHorz*radius; + const double sideVert = sideExpandVert*radius; + if (anchorNormal.x() > sideHorz) { - if( anchorNormal.y() > sideVert ) - return asTopLeft; - else if( anchorNormal.y() < -sideVert ) - return asBottomLeft; - else - return asLeft; - } - else if( anchorNormal.x() < -sideHorz ) + if (anchorNormal.y() > sideVert) return asTopLeft; + else if (anchorNormal.y() < -sideVert) return asBottomLeft; + else return asLeft; + } else if (anchorNormal.x() < -sideHorz) { - if( anchorNormal.y() > sideVert ) - return asTopRight; - else if( anchorNormal.y() < -sideVert ) - return asBottomRight; - else - return asRight; - } - else + if (anchorNormal.y() > sideVert) return asTopRight; + else if (anchorNormal.y() < -sideVert) return asBottomRight; + else return asRight; + } else { - if( anchorNormal.y() > 0 ) - return asTop; - else - return asBottom; + if (anchorNormal.y() > 0) return asTop; + else return asBottom; } - return asBottom; // should never be reached + return asBottom; // should never be reached } -QCPLabelPainterPrivate::AnchorSide QCPLabelPainterPrivate::rotationCorrectedSide( AnchorSide side, double rotation ) const +QCPLabelPainterPrivate::AnchorSide QCPLabelPainterPrivate::rotationCorrectedSide(AnchorSide side, double rotation) const { AnchorSide result = side; const bool rotateClockwise = rotation > 0; - if( !qFuzzyIsNull( rotation ) ) + if (!qFuzzyIsNull(rotation)) { - if( !qFuzzyCompare( qAbs( rotation ), 90 ) ) // avoid graphical collision with anchor tangent (e.g. axis line) when rotating, so change anchor side appropriately: + if (!qFuzzyCompare(qAbs(rotation), 90)) // avoid graphical collision with anchor tangent (e.g. axis line) when rotating, so change anchor side appropriately: { - if( side == asTop ) - result = rotateClockwise ? asLeft : asRight; - else if( side == asBottom ) - result = rotateClockwise ? asRight : asLeft; - else if( side == asTopLeft ) - result = rotateClockwise ? asLeft : asTop; - else if( side == asTopRight ) - result = rotateClockwise ? asTop : asRight; - else if( side == asBottomLeft ) - result = rotateClockwise ? asBottom : asLeft; - else if( side == asBottomRight ) - result = rotateClockwise ? asRight : asBottom; - } - else // for full rotation by +/-90 degrees, other sides are more appropriate for centering on anchor: + if (side == asTop) result = rotateClockwise ? asLeft : asRight; + else if (side == asBottom) result = rotateClockwise ? asRight : asLeft; + else if (side == asTopLeft) result = rotateClockwise ? asLeft : asTop; + else if (side == asTopRight) result = rotateClockwise ? asTop : asRight; + else if (side == asBottomLeft) result = rotateClockwise ? asBottom : asLeft; + else if (side == asBottomRight) result = rotateClockwise ? asRight : asBottom; + } else // for full rotation by +/-90 degrees, other sides are more appropriate for centering on anchor: { - if( side == asLeft ) - result = rotateClockwise ? asBottom : asTop; - else if( side == asRight ) - result = rotateClockwise ? asTop : asBottom; - else if( side == asTop ) - result = rotateClockwise ? asLeft : asRight; - else if( side == asBottom ) - result = rotateClockwise ? asRight : asLeft; - else if( side == asTopLeft ) - result = rotateClockwise ? asBottomLeft : asTopRight; - else if( side == asTopRight ) - result = rotateClockwise ? asTopLeft : asBottomRight; - else if( side == asBottomLeft ) - result = rotateClockwise ? asBottomRight : asTopLeft; - else if( side == asBottomRight ) - result = rotateClockwise ? asTopRight : asBottomLeft; + if (side == asLeft) result = rotateClockwise ? asBottom : asTop; + else if (side == asRight) result = rotateClockwise ? asTop : asBottom; + else if (side == asTop) result = rotateClockwise ? asLeft : asRight; + else if (side == asBottom) result = rotateClockwise ? asRight : asLeft; + else if (side == asTopLeft) result = rotateClockwise ? asBottomLeft : asTopRight; + else if (side == asTopRight) result = rotateClockwise ? asTopLeft : asBottomRight; + else if (side == asBottomLeft) result = rotateClockwise ? asBottomRight : asTopLeft; + else if (side == asBottomRight) result = rotateClockwise ? asTopRight : asBottomLeft; } } return result; @@ -6052,14 +6050,15 @@ QCPLabelPainterPrivate::AnchorSide QCPLabelPainterPrivate::rotationCorrectedSide void QCPLabelPainterPrivate::analyzeFontMetrics() { - const QFontMetrics fm( mFont ); - mLetterCapHeight = fm.tightBoundingRect( QLatin1String( "8" ) ).height(); // this method is slow, that's why we query it only upon font change + const QFontMetrics fm(mFont); + mLetterCapHeight = fm.tightBoundingRect(QLatin1String("8")).height(); // this method is slow, that's why we query it only upon font change mLetterDescent = fm.descent(); } /* end of 'src/axis/labelpainter.cpp' */ + /* including file 'src/axis/axisticker.cpp' */ -/* modified 2021-03-29T02:30:44, size 18688 */ +/* modified 2022-11-06T12:45:56, size 18693 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTicker @@ -6121,20 +6120,23 @@ void QCPLabelPainterPrivate::analyzeFontMetrics() 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; } @@ -6147,9 +6149,9 @@ void QCPAxisTicker::setTickStepStrategy( QCPAxisTicker::TickStepStrategy strateg 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; @@ -6163,7 +6165,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; } @@ -6181,30 +6183,29 @@ void QCPAxisTicker::setTickOrigin( double origin ) needed) 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.isEmpty() ) + if (!ticks.isEmpty()) { - *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 @@ -6217,10 +6218,10 @@ void QCPAxisTicker::generate( const QCPRange& range, const QLocale& locale, QCha 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 @@ -6230,92 +6231,55 @@ 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 ); - intPart = int( intPartf ); - + double fracPart = modf(getMantissa(tickStep), &intPartf); + intPart = int(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; } @@ -6330,9 +6294,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 @@ -6344,18 +6308,18 @@ QString QCPAxisTicker::getTickLabel( double tick, const QLocale& locale, QChar f 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 < ticks.size(); ++i ) + + result.reserve((ticks.size()-1)*subTickCount); + for (int i=1; i QCPAxisTicker::createSubTickVector( int subTickCount, const QVec 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 = qint64( floor( ( range.lower - mTickOrigin ) / tickStep ) ); // do not use qFloor here, or we'll lose 64 bit precision - qint64 lastStep = qint64( ceil( ( range.upper - mTickOrigin ) / tickStep ) ); // do not use qCeil here, or we'll lose 64 bit precision - int tickcount = int( lastStep - firstStep + 1 ); - if( tickcount < 0 ) - tickcount = 0; - result.resize( tickcount ); - for( int i = 0; i < tickcount; ++i ) - result[i] = mTickOrigin + ( firstStep + i ) * tickStep; + qint64 firstStep = qint64(floor((range.lower-mTickOrigin)/tickStep)); // do not use qFloor here, or we'll lose 64 bit precision + qint64 lastStep = qint64(ceil((range.upper-mTickOrigin)/tickStep)); // do not use qCeil here, or we'll lose 64 bit precision + int tickcount = int(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() ); - foreach( double tickCoord, ticks ) - result.append( getTickLabel( tickCoord, locale, formatChar, precision ) ); + result.reserve(ticks.size()); + foreach (double tickCoord, ticks) + result.append(getTickLabel(tickCoord, locale, formatChar, precision)); return result; } @@ -6415,40 +6378,39 @@ QVector 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(); } @@ -6458,17 +6420,17 @@ void QCPAxisTicker::trimTicks( const QCPRange& range, QVector& ticks, bo 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 @@ -6478,12 +6440,11 @@ double QCPAxisTicker::pickClosest( double target, const QVector& candida 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 = std::pow(10.0, std::floor(std::log10(input))); + if (magnitude) *magnitude = mag; + return input/mag; } /*! \internal @@ -6492,29 +6453,32 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 18829 */ +/* modified 2022-11-06T12:45:56, size 18829 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerDateTime @@ -6560,10 +6524,12 @@ 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); } /*! @@ -6603,7 +6569,7 @@ QCPAxisTickerDateTime::QCPAxisTickerDateTime() \see setDateTimeSpec, setTimeZone */ -void QCPAxisTickerDateTime::setDateTimeFormat( const QString& format ) +void QCPAxisTickerDateTime::setDateTimeFormat(const QString &format) { mDateTimeFormat = format; } @@ -6621,19 +6587,19 @@ void QCPAxisTickerDateTime::setDateTimeFormat( const QString& format ) \see setDateTimeFormat, setTimeZone */ -void QCPAxisTickerDateTime::setDateTimeSpec( Qt::TimeSpec spec ) +void QCPAxisTickerDateTime::setDateTimeSpec(Qt::TimeSpec spec) { mDateTimeSpec = spec; } -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) /*! Sets the time zone that is used for creating the tick labels from corresponding dates/times. The time spec (\ref setDateTimeSpec) is set to \c Qt::TimeZone. \see setDateTimeFormat, setTimeZone */ -void QCPAxisTickerDateTime::setTimeZone( const QTimeZone& zone ) +void QCPAxisTickerDateTime::setTimeZone(const QTimeZone &zone) { mTimeZone = zone; mDateTimeSpec = Qt::TimeZone; @@ -6649,9 +6615,9 @@ void QCPAxisTickerDateTime::setTimeZone( const QTimeZone& zone ) 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); } /*! @@ -6661,9 +6627,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 @@ -6679,30 +6645,28 @@ 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 - - mDateStrategy = dsNone; // leaving it at dsNone means tick coordinates will not be tuned in any special way in createTickVector - 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 + + mDateStrategy = dsNone; // leaving it at dsNone means tick coordinates will not be tuned in any special way in createTickVector + 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; @@ -6715,68 +6679,30 @@ 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; } @@ -6789,18 +6715,18 @@ 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 ) -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) - if( mDateTimeSpec == Qt::TimeZone ) - return locale.toString( keyToDateTime( tick ).toTimeZone( mTimeZone ), mDateTimeFormat ); + Q_UNUSED(precision) + Q_UNUSED(formatChar) +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + if (mDateTimeSpec == Qt::TimeZone) + return locale.toString(keyToDateTime(tick).toTimeZone(mTimeZone), mDateTimeFormat); else - return locale.toString( keyToDateTime( tick ).toTimeSpec( mDateTimeSpec ), mDateTimeFormat ); -#else - return locale.toString( keyToDateTime( tick ).toTimeSpec( mDateTimeSpec ), mDateTimeFormat ); -#endif + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +# else + return locale.toString(keyToDateTime(tick).toTimeSpec(mDateTimeSpec), mDateTimeFormat); +# endif } /*! \internal @@ -6810,37 +6736,36 @@ 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 < result.size(); ++i ) + 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); } } } @@ -6856,13 +6781,13 @@ QVector QCPAxisTickerDateTime::createTickVector( double tickStep, const \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( qint64( 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(qint64(key*1000.0)); +# endif } /*! \overload @@ -6876,13 +6801,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 @@ -6896,20 +6821,21 @@ double QCPAxisTickerDateTime::dateTimeToKey( const QDateTime& dateTime ) \see keyToDateTime */ -double QCPAxisTickerDateTime::dateTimeToKey( const QDate& date, Qt::TimeSpec timeSpec ) +double QCPAxisTickerDateTime::dateTimeToKey(const QDate &date, Qt::TimeSpec timeSpec) { -#if QT_VERSION < QT_VERSION_CHECK( 4, 7, 0 ) - return QDateTime( date, QTime( 0, 0 ), timeSpec ).toTime_t(); -#elif QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 ) - return QDateTime( date, QTime( 0, 0 ), timeSpec ).toMSecsSinceEpoch() / 1000.0; -#else - return date.startOfDay( timeSpec ).toMSecsSinceEpoch() / 1000.0; -#endif +# if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) + return QDateTime(date, QTime(0, 0), timeSpec).toTime_t(); +# elif QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + return QDateTime(date, QTime(0, 0), timeSpec).toMSecsSinceEpoch()/1000.0; +# else + return date.startOfDay(timeSpec).toMSecsSinceEpoch()/1000.0; +# endif } /* end of 'src/axis/axistickerdatetime.cpp' */ + /* including file 'src/axis/axistickertime.cpp' */ -/* modified 2021-03-29T02:30:44, size 11745 */ +/* modified 2022-11-06T12:45:56, size 11745 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerTime @@ -6954,21 +6880,23 @@ double QCPAxisTickerDateTime::dateTimeToKey( const QDate& date, Qt::TimeSpec tim 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"); } /*! @@ -6989,21 +6917,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; @@ -7020,9 +6948,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 @@ -7034,49 +6962,47 @@ void QCPAxisTickerTime::setFieldWidth( QCPAxisTickerTime::TimeUnit unit, int wid \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; } @@ -7087,41 +7013,21 @@ 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; } @@ -7133,32 +7039,31 @@ 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; } @@ -7167,18 +7072,19 @@ QString QCPAxisTickerTime::getTickLabel( double tick, const QLocale& locale, QCh 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' */ -/* modified 2021-03-29T02:30:44, size 5575 */ +/* modified 2022-11-06T12:45:56, size 5575 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerFixed @@ -7207,8 +7113,9 @@ void QCPAxisTickerTime::replaceUnit( QString& text, QCPAxisTickerTime::TimeUnit 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) { } @@ -7221,9 +7128,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; @@ -7236,7 +7143,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; } @@ -7251,31 +7158,35 @@ void QCPAxisTickerFixed::setScaleStrategy( QCPAxisTickerFixed::ScaleStrategy str \seebaseclassmethod */ -double QCPAxisTickerFixed::getTickStep( const QCPRange& range ) +double QCPAxisTickerFixed::getTickStep(const QCPRange &range) { - switch( mScaleStrategy ) + switch (mScaleStrategy) { - 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 ) + case ssNone: + { 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 ) ); - } + } + 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)); + } } return mTickStep; } /* end of 'src/axis/axistickerfixed.cpp' */ + /* including file 'src/axis/axistickertext.cpp' */ -/* modified 2021-03-29T02:30:44, size 8742 */ +/* modified 2022-11-06T12:45:56, size 8742 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerText @@ -7317,8 +7228,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) { } @@ -7332,7 +7243,7 @@ QCPAxisTickerText::QCPAxisTickerText() \see addTicks, addTick, clear */ -void QCPAxisTickerText::setTicks( const QMap& ticks ) +void QCPAxisTickerText::setTicks(const QMap &ticks) { mTicks = ticks; } @@ -7345,10 +7256,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); } /*! @@ -7356,9 +7267,9 @@ void QCPAxisTickerText::setTicks( const QVector& positions, const QVecto 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; @@ -7383,9 +7294,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 @@ -7398,12 +7309,12 @@ void QCPAxisTickerText::addTick( double position, const QString& label ) \see addTick, setTicks, clear */ -void QCPAxisTickerText::addTicks( const QMap& ticks ) +void QCPAxisTickerText::addTicks(const QMap &ticks) { -#if QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ) - mTicks.unite( ticks ); +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + mTicks.unite(ticks); #else - mTicks.insert( ticks ); + mTicks.insert(ticks); #endif } @@ -7418,13 +7329,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 < n; ++i ) - mTicks.insert( positions.at( i ), labels.at( i ) ); + int n = qMin(positions.size(), labels.size()); + for (int i=0; i& positions, const QVecto \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; } @@ -7444,9 +7355,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; } @@ -7456,12 +7367,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); } /*! @@ -7471,29 +7382,28 @@ QString QCPAxisTickerText::getTickLabel( double tick, const QLocale& locale, QCh \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' */ -/* modified 2021-03-29T02:30:44, size 11177 */ +/* modified 2022-11-06T12:45:56, size 11177 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerPi @@ -7518,10 +7428,14 @@ QVector QCPAxisTickerText::createTickVector( double tickStep, const QCPR 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); } /*! @@ -7531,7 +7445,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; } @@ -7542,7 +7456,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; } @@ -7555,16 +7469,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; } @@ -7577,11 +7491,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 @@ -7592,9 +7506,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 @@ -7605,33 +7519,32 @@ 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; } } @@ -7641,14 +7554,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; @@ -7668,50 +7581,47 @@ 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( " " ) : QString( 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(" ") : QString(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)); } } } @@ -7727,9 +7637,9 @@ QString QCPAxisTickerPi::fractionToString( int numerator, int denominator ) cons 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 @@ -7737,33 +7647,21 @@ 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; } @@ -7775,23 +7673,24 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7890 */ +/* modified 2022-11-06T12:45:56, size 7890 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisTickerLog @@ -7826,9 +7725,10 @@ 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)) { } @@ -7836,14 +7736,13 @@ 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; } @@ -7857,9 +7756,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; @@ -7872,9 +7771,9 @@ void QCPAxisTickerLog::setSubTickCount( int subTicks ) \seebaseclassmethod */ -int QCPAxisTickerLog::getSubTickCount( double tickStep ) +int QCPAxisTickerLog::getSubTickCount(double tickStep) { - Q_UNUSED( tickStep ) + Q_UNUSED(tickStep) return mSubTickCount; } @@ -7890,50 +7789,50 @@ int QCPAxisTickerLog::getSubTickCount( double tickStep ) \seebaseclassmethod */ -QVector QCPAxisTickerLog::createTickVector( double tickStep, const QCPRange& range ) +QVector QCPAxisTickerLog::createTickVector(double tickStep, const QCPRange &range) { QVector result; - if( range.lower > 0 && range.upper > 0 ) // positive range + if (range.lower > 0 && range.upper > 0) // positive range { - const double baseTickCount = qLn( range.upper / range.lower ) * mLogBaseLnInv; - if( baseTickCount < 1.6 ) // if too few log ticks would be visible in axis range, fall back to regular tick vector generation - return QCPAxisTicker::createTickVector( tickStep, range ); - const double exactPowerStep = baseTickCount / double( mTickCount + 1e-10 ); - const 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 + const double baseTickCount = qLn(range.upper/range.lower)*mLogBaseLnInv; + if (baseTickCount < 1.6) // if too few log ticks would be visible in axis range, fall back to regular tick vector generation + return QCPAxisTicker::createTickVector(tickStep, range); + const double exactPowerStep = baseTickCount/double(mTickCount+1e-10); + const 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 { - const double baseTickCount = qLn( range.lower / range.upper ) * mLogBaseLnInv; - if( baseTickCount < 1.6 ) // if too few log ticks would be visible in axis range, fall back to regular tick vector generation - return QCPAxisTicker::createTickVector( tickStep, range ); - const double exactPowerStep = baseTickCount / double( mTickCount + 1e-10 ); - const 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 + const double baseTickCount = qLn(range.lower/range.upper)*mLogBaseLnInv; + if (baseTickCount < 1.6) // if too few log ticks would be visible in axis range, fall back to regular tick vector generation + return QCPAxisTicker::createTickVector(tickStep, range); + const double exactPowerStep = baseTickCount/double(mTickCount+1e-10); + const 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' */ -/* modified 2021-03-29T02:30:44, size 99883 */ +/* modified 2022-11-06T12:45:56, size 99911 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPGrid @@ -7957,18 +7856,22 @@ QVector QCPAxisTickerLog::createTickVector( double tickStep, const QCPRa You shouldn't instantiate grids on their own, since every QCPAxis brings its own QCPGrid. */ -QCPGrid::QCPGrid( QCPAxis* parentAxis ) - : QCPLayerable( parentAxis->parentPlot(), QString(), parentAxis ), mSubGridVisible{}, mAntialiasedSubGrid{}, mAntialiasedZeroLine{}, mParentAxis( parentAxis ) +QCPGrid::QCPGrid(QCPAxis *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mSubGridVisible{}, + mAntialiasedSubGrid{}, + mAntialiasedZeroLine{}, + 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); } /*! @@ -7976,7 +7879,7 @@ QCPGrid::QCPGrid( QCPAxis* parentAxis ) \see setSubGridPen */ -void QCPGrid::setSubGridVisible( bool visible ) +void QCPGrid::setSubGridVisible(bool visible) { mSubGridVisible = visible; } @@ -7984,7 +7887,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; } @@ -7992,7 +7895,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; } @@ -8000,7 +7903,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; } @@ -8008,7 +7911,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; } @@ -8019,7 +7922,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; } @@ -8037,9 +7940,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 @@ -8047,17 +7950,13 @@ 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 @@ -8066,76 +7965,69 @@ 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; i < tickCount; ++i ) + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->range().size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.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; i < tickCount; ++i ) + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel( 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; i < tickCount; ++i ) + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(mZeroLinePen); + double epsilon = mParentAxis->mRange.size()*1E-6; // for comparing double to zero + for (int i=0; imTickVector.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; i < tickCount; ++i ) + applyDefaultAntialiasingHint(painter); + painter->setPen(mPen); + for (int i=0; icoordToPixel( 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)); } } } @@ -8146,35 +8038,31 @@ 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 ) + 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) { - 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 ) - { - foreach( double tickCoord, mParentAxis->mSubTickVector ) + foreach (double tickCoord, mParentAxis->mSubTickVector) { - t = mParentAxis->coordToPixel( tickCoord ); // x - painter->drawLine( QLineF( t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top() ) ); + t = mParentAxis->coordToPixel(tickCoord); // x + painter->drawLine(QLineF(t, mParentAxis->mAxisRect->bottom(), t, mParentAxis->mAxisRect->top())); } - } - else + } else { - foreach( double tickCoord, mParentAxis->mSubTickVector ) + foreach (double tickCoord, mParentAxis->mSubTickVector) { - t = mParentAxis->coordToPixel( tickCoord ); // y - painter->drawLine( QLineF( mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t ) ); + t = mParentAxis->coordToPixel(tickCoord); // y + painter->drawLine(QLineF(mParentAxis->mAxisRect->left(), t, mParentAxis->mAxisRect->right(), t)); } } } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxis //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -8309,87 +8197,79 @@ 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 ) - , mDragging( false ) +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), + mDragging(false) { - 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 */ @@ -8414,12 +8294,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; } @@ -8486,15 +8366,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); } } @@ -8506,24 +8386,22 @@ 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 ) - return; - - if( !QCPRange::validRange( range ) ) + if (range.lower == mRange.lower && range.upper == mRange.upper) 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); } /*! @@ -8536,12 +8414,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); } } @@ -8560,12 +8438,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); } } @@ -8578,26 +8456,24 @@ 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 ) - return; - - if( !QCPRange::validRange( lower, upper ) ) + if (lower == mRange.lower && upper == mRange.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); } /*! @@ -8611,60 +8487,58 @@ 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); } /*! @@ -8676,7 +8550,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; } @@ -8694,9 +8568,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 nullptr as axis ticker"; @@ -8711,9 +8585,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; @@ -8723,13 +8597,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(); } } @@ -8738,9 +8612,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; @@ -8752,9 +8626,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; @@ -8766,7 +8640,7 @@ void QCPAxis::setTickLabelFont( const QFont& font ) \see setTickLabels, setTickLabelFont */ -void QCPAxis::setTickLabelColor( const QColor& color ) +void QCPAxis::setTickLabelColor(const QColor &color) { mTickLabelColor = color; } @@ -8780,11 +8654,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; } } @@ -8796,7 +8670,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; @@ -8837,59 +8711,55 @@ 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; @@ -8901,9 +8771,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; @@ -8918,10 +8788,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); } /*! @@ -8930,9 +8800,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; } @@ -8945,12 +8815,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 } } @@ -8961,9 +8831,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; @@ -8978,10 +8848,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); } /*! @@ -8990,9 +8860,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; } @@ -9005,12 +8875,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 } } @@ -9019,7 +8889,7 @@ void QCPAxis::setSubTickLengthOut( int outside ) \see setTickPen, setSubTickPen */ -void QCPAxis::setBasePen( const QPen& pen ) +void QCPAxis::setBasePen(const QPen &pen) { mBasePen = pen; } @@ -9029,7 +8899,7 @@ void QCPAxis::setBasePen( const QPen& pen ) \see setTickLength, setBasePen */ -void QCPAxis::setTickPen( const QPen& pen ) +void QCPAxis::setTickPen(const QPen &pen) { mTickPen = pen; } @@ -9039,7 +8909,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; } @@ -9049,9 +8919,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; @@ -9063,7 +8933,7 @@ void QCPAxis::setLabelFont( const QFont& font ) \see setLabelFont */ -void QCPAxis::setLabelColor( const QColor& color ) +void QCPAxis::setLabelColor(const QColor &color) { mLabelColor = color; } @@ -9072,9 +8942,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; @@ -9086,9 +8956,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; @@ -9105,9 +8975,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; @@ -9122,7 +8992,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; } @@ -9132,9 +9002,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 @@ -9146,7 +9016,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 @@ -9157,9 +9027,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; } @@ -9170,7 +9040,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; } @@ -9180,7 +9050,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; } @@ -9190,7 +9060,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; } @@ -9200,7 +9070,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; } @@ -9215,7 +9085,7 @@ void QCPAxis::setSelectedSubTickPen( const QPen& pen ) \see setUpperEnding */ -void QCPAxis::setLowerEnding( const QCPLineEnding& ending ) +void QCPAxis::setLowerEnding(const QCPLineEnding &ending) { mAxisPainter->lowerEnding = ending; } @@ -9230,7 +9100,7 @@ void QCPAxis::setLowerEnding( const QCPLineEnding& ending ) \see setLowerEnding */ -void QCPAxis::setUpperEnding( const QCPLineEnding& ending ) +void QCPAxis::setUpperEnding(const QCPLineEnding &ending) { mAxisPainter->upperEnding = ending; } @@ -9242,21 +9112,20 @@ 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); } /*! @@ -9268,9 +9137,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 @@ -9282,32 +9151,30 @@ 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); } /*! @@ -9323,22 +9190,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); } /*! @@ -9347,89 +9214,85 @@ void QCPAxis::setScaleRatio( const QCPAxis* otherAxis, double ratio ) \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */ -void QCPAxis::rescale( bool onlyVisiblePlottables ) +void QCPAxis::rescale(bool onlyVisiblePlottables) { QCPRange newRange; bool haveRange = false; - foreach( QCPAbstractPlottable* plottable, plottables() ) + foreach (QCPAbstractPlottable *plottable, plottables()) { - if( !plottable->realVisibility() && onlyVisiblePlottables ) + if (!plottable->realVisibility() && onlyVisiblePlottables) continue; QCPRange plottableRange; bool currentFoundRange; QCP::SignDomain signDomain = QCP::sdBoth; - if( mScaleType == stLogarithmic ) - signDomain = ( mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive ); - if( plottable->keyAxis() == this ) - plottableRange = plottable->getKeyRange( currentFoundRange, signDomain ); + if (mScaleType == stLogarithmic) + signDomain = (mRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + if (plottable->keyAxis() == this) + plottableRange = plottable->getKeyRange(currentFoundRange, signDomain); else - plottableRange = plottable->getValueRange( currentFoundRange, signDomain ); - if( currentFoundRange ) + plottableRange = plottable->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 + 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; + 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 qPow(mRange.upper/mRange.lower, (mAxisRect->left()-value)/double(mAxisRect->width()))*mRange.upper; } - } - else // orientation() == Qt::Vertical + } 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; } } } @@ -9437,53 +9300,50 @@ 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(); } } } @@ -9498,33 +9358,32 @@ 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 ) + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) return -1; - SelectablePart part = getPartAt( pos ); - if( ( onlySelectable && !mSelectableParts.testFlag( part ) ) || part == spNone ) - return -1; - - if( details ) - details->setValue( part ); - return mParentPlot->selectionTolerance() * 0.99; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; } /*! @@ -9537,13 +9396,12 @@ double QCPAxis::selectTest( const QPointF& pos, bool onlySelectable, QVariant* d QList QCPAxis::plottables() const { QList result; - if( !mParentPlot ) - return result; - - foreach( QCPAbstractPlottable* plottable, mParentPlot->mPlottables ) + if (!mParentPlot) return result; + + foreach (QCPAbstractPlottable *plottable, mParentPlot->mPlottables) { - if( plottable->keyAxis() == this || plottable->valueAxis() == this ) - result.append( plottable ); + if (plottable->keyAxis() == this || plottable->valueAxis() == this) + result.append(plottable); } return result; } @@ -9556,13 +9414,12 @@ QList QCPAxis::plottables() const QList QCPAxis::graphs() const { QList result; - if( !mParentPlot ) - return result; - - foreach( QCPGraph* graph, mParentPlot->mGraphs ) + if (!mParentPlot) return result; + + foreach (QCPGraph *graph, mParentPlot->mGraphs) { - if( graph->keyAxis() == this || graph->valueAxis() == this ) - result.append( graph ); + if (graph->keyAxis() == this || graph->valueAxis() == this) + result.append(graph); } return result; } @@ -9576,16 +9433,15 @@ QList QCPAxis::graphs() const QList QCPAxis::items() const { QList result; - if( !mParentPlot ) - return result; - - foreach( QCPAbstractItem* item, mParentPlot->mItems ) + if (!mParentPlot) return result; + + foreach (QCPAbstractItem *item, mParentPlot->mItems) { - foreach( QCPItemPosition* position, item->positions() ) + foreach (QCPItemPosition *position, item->positions()) { - if( position->keyAxis() == this || position->valueAxis() == this ) + if (position->keyAxis() == this || position->valueAxis() == this) { - result.append( item ); + result.append(item); break; } } @@ -9597,65 +9453,56 @@ 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:" << static_cast( side ); + qDebug() << Q_FUNC_INFO << "Invalid margin side passed:" << static_cast(side); return atLeft; } /*! 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; - case atRight: - return atLeft; - case atBottom: - return atTop; - case atTop: - return atBottom; + case atLeft: return atRight; + case atRight: return atLeft; + case atBottom: return atTop; + case atTop: return atBottom; } qDebug() << Q_FUNC_INFO << "invalid axis type"; return atLeft; } /* 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; } @@ -9674,28 +9521,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; } } @@ -9712,26 +9559,25 @@ 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); + } 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 ); + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); } } @@ -9747,15 +9593,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); } } @@ -9774,32 +9620,32 @@ 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; } - -#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) const double delta = event->delta(); #else const double delta = event->angleDelta().y(); #endif - -#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 ) + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QPointF pos = event->pos(); #else const QPointF pos = event->position(); #endif - - const double wheelSteps = delta / 120.0; // a single step delta is +/-120 usually - const double factor = qPow( mAxisRect->rangeZoomFactor( orientation() ), wheelSteps ); - scaleRange( factor, pixelToCoord( orientation() == Qt::Horizontal ? pos.x() : pos.y() ) ); + + const double wheelSteps = delta/120.0; // a single step delta is +/-120 usually + const double factor = qPow(mAxisRect->rangeZoomFactor(orientation()), wheelSteps); + scaleRange(factor, pixelToCoord(orientation() == Qt::Horizontal ? pos.x() : pos.y())); mParentPlot->replot(); } @@ -9818,9 +9664,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 @@ -9829,32 +9675,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; i < mTickVector.size(); ++i ) + for (int i=0; itype = mAxisType; @@ -9874,7 +9720,7 @@ void QCPAxis::draw( QCPPainter* painter ) mAxisPainter->tickPositions = tickPositions; mAxisPainter->tickLabels = tickLabels; mAxisPainter->subTickPositions = subTickPositions; - mAxisPainter->draw( painter ); + mAxisPainter->draw(painter); } /*! \internal @@ -9887,14 +9733,12 @@ 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 : nullptr, mTickLabels ? &mTickVectorLabels : nullptr ); - mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : nullptr, mTickLabels ? &mTickVectorLabels : nullptr); + mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too } /*! \internal @@ -9904,7 +9748,7 @@ void QCPAxis::setupTickVectors() */ QPen QCPAxis::getBasePen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedBasePen : mBasePen; + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; } /*! \internal @@ -9914,7 +9758,7 @@ QPen QCPAxis::getBasePen() const */ QPen QCPAxis::getTickPen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedTickPen : mTickPen; + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; } /*! \internal @@ -9924,7 +9768,7 @@ QPen QCPAxis::getTickPen() const */ QPen QCPAxis::getSubTickPen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedSubTickPen : mSubTickPen; + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; } /*! \internal @@ -9934,7 +9778,7 @@ QPen QCPAxis::getSubTickPen() const */ QFont QCPAxis::getTickLabelFont() const { - return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelFont : mTickLabelFont; + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; } /*! \internal @@ -9944,7 +9788,7 @@ QFont QCPAxis::getTickLabelFont() const */ QFont QCPAxis::getLabelFont() const { - return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelFont : mLabelFont; + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; } /*! \internal @@ -9954,7 +9798,7 @@ QFont QCPAxis::getLabelFont() const */ QColor QCPAxis::getTickLabelColor() const { - return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelColor : mTickLabelColor; + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; } /*! \internal @@ -9964,7 +9808,7 @@ QColor QCPAxis::getTickLabelColor() const */ QColor QCPAxis::getLabelColor() const { - return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelColor : mLabelColor; + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; } /*! \internal @@ -9983,27 +9827,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; i < mTickVector.size(); ++i ) + 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) { - foreach( double tickPos, tickPositions ) - painter->drawLine( QLineF( tickPos + xCor, origin.y() - tickLengthOut * tickDir + yCor, tickPos + xCor, origin.y() + tickLengthIn * tickDir + yCor ) ); - } - else + foreach (double tickPos, tickPositions) + painter->drawLine(QLineF(tickPos+xCor, origin.y()-tickLengthOut*tickDir+yCor, tickPos+xCor, origin.y()+tickLengthIn*tickDir+yCor)); + } else { - foreach( double tickPos, tickPositions ) - painter->drawLine( QLineF( origin.x() - tickLengthOut * tickDir + xCor, tickPos + yCor, origin.x() + tickLengthIn * tickDir + xCor, tickPos + yCor ) ); + foreach (double tickPos, tickPositions) + painter->drawLine(QLineF(origin.x()-tickLengthOut*tickDir+xCor, tickPos+yCor, origin.x()+tickLengthIn*tickDir+xCor, tickPos+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) { - foreach( double subTickPos, subTickPositions ) - painter->drawLine( QLineF( subTickPos + xCor, origin.y() - subTickLengthOut * tickDir + yCor, subTickPos + xCor, origin.y() + subTickLengthIn * tickDir + yCor ) ); - } - else + foreach (double subTickPos, subTickPositions) + painter->drawLine(QLineF(subTickPos+xCor, origin.y()-subTickLengthOut*tickDir+yCor, subTickPos+xCor, origin.y()+subTickLengthIn*tickDir+yCor)); + } else { - foreach( double subTickPos, subTickPositions ) - painter->drawLine( QLineF( origin.x() - subTickLengthOut * tickDir + xCor, subTickPos + yCor, origin.x() + subTickLengthIn * tickDir + xCor, subTickPos + yCor ) ); + foreach (double subTickPos, subTickPositions) + painter->drawLine(QLineF(origin.x()-subTickLengthOut*tickDir+xCor, subTickPos+yCor, origin.x()+subTickLengthIn*tickDir+xCor, subTickPos+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; i < maxLabelIndex; ++i ) - placeTickLabel( painter, tickPositions.at( i ), distanceToAxis, tickLabels.at( i ), &tickLabelsSize ); - if( tickLabelSide == QCPAxis::lsOutside ) - margin += ( QCPAxis::orientation( type ) == Qt::Horizontal ) ? tickLabelsSize.height() : tickLabelsSize.width(); + 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(); @@ -10283,35 +10129,35 @@ int QCPAxisPainterPrivate::size() int result = 0; QByteArray newHash = generateLabelParameterHash(); - if( newHash != mLabelParameterHash ) + if (newHash != mLabelParameterHash) { mLabelCache.clear(); mLabelParameterHash = newHash; } - + // 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()) { - foreach( const QString& tickLabel, tickLabels ) - getMaxTickLabelSize( tickLabelFont, tickLabel, &tickLabelsSize ); - result += QCPAxis::orientation( type ) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width(); - result += tickLabelPadding; + foreach (const QString &tickLabel, tickLabels) + getMaxTickLabelSize(tickLabelFont, tickLabel, &tickLabelsSize); + result += QCPAxis::orientation(type) == Qt::Horizontal ? tickLabelsSize.height() : tickLabelsSize.width(); + result += tickLabelPadding; } } - + // calculate size of axis label (only height needed, because left/right labels are rotated by 90 degrees): - if( !label.isEmpty() ) + if (!label.isEmpty()) { - QFontMetrics fontMetrics( labelFont ); + QFontMetrics fontMetrics(labelFont); QRect bounds; - bounds = fontMetrics.boundingRect( 0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, label ); + bounds = fontMetrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip | Qt::AlignHCenter | Qt::AlignVCenter, label); result += bounds.height() + labelPadding; } @@ -10339,13 +10185,13 @@ void QCPAxisPainterPrivate::clearCache() QByteArray QCPAxisPainterPrivate::generateLabelParameterHash() const { QByteArray result; - 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() ); + 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; } @@ -10368,95 +10214,84 @@ 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() ); +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatioF()); +# else + cachedLabel->pixmap.setDevicePixelRatio(mParentPlot->devicePixelRatio()); +# endif #endif -#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 ); + } 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 @@ -10468,36 +10303,35 @@ 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, 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, 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 @@ -10508,76 +10342,75 @@ 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(QString(mParentPlot->locale().exponential())); + 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( int( result.expFont.pointSize() * 0.75 ) ); + if (result.expFont.pointSize() > 0) + result.expFont.setPointSize(int(result.expFont.pointSize()*0.75)); else - result.expFont.setPixelSize( int( result.expFont.pixelSize() * 0.75 ) ); + result.expFont.setPixelSize(int(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; } @@ -10591,7 +10424,7 @@ QCPAxisPainterPrivate::TickLabelData QCPAxisPainterPrivate::getTickLabelData( co 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 @@ -10603,97 +10436,86 @@ QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset( const TickLabelData& labe 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; + 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; double x = 0; double y = 0; - if( ( type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside ) || ( type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside ) ) // Anchor at right side of tick label + 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(); + 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()-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 + } 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 = -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 = -qSin(-radians)*labelData.totalBounds.height()/2.0; + y = -qCos(-radians)*labelData.totalBounds.height(); } - } - else + } 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 + } else { - x = -qCos( -radians ) * labelData.totalBounds.width() - qSin( -radians ) * labelData.totalBounds.height() / 2.0; - y = +qSin( -radians ) * labelData.totalBounds.width(); + x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height()/2.0; + y = +qSin(-radians)*labelData.totalBounds.width(); } - } - else + } else { - x = -labelData.totalBounds.width() / 2.0; + x = -labelData.totalBounds.width()/2.0; y = 0; } } - - return { x, y }; + + return {x, y}; } /*! \internal @@ -10703,31 +10525,31 @@ QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset( const TickLabelData& labe 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' */ -/* modified 2021-03-29T02:30:44, size 17466 */ +/* modified 2022-11-06T12:45:56, size 17466 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPScatterStyle @@ -10814,8 +10636,12 @@ void QCPAxisPainterPrivate::getMaxTickLabelSize( const QFont& font, const QStrin 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) { } @@ -10826,8 +10652,12 @@ 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) { } @@ -10835,8 +10665,12 @@ 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) { } @@ -10844,8 +10678,12 @@ QCPScatterStyle::QCPScatterStyle( ScatterShape shape, const QColor& color, doubl 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) { } @@ -10864,8 +10702,12 @@ 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) { } @@ -10873,8 +10715,13 @@ QCPScatterStyle::QCPScatterStyle( ScatterShape shape, const QPen& pen, const QBr 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) { } @@ -10887,33 +10734,38 @@ 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()); } } @@ -10922,7 +10774,7 @@ void QCPScatterStyle::setFromOther( const QCPScatterStyle& other, ScatterPropert \see setShape */ -void QCPScatterStyle::setSize( double size ) +void QCPScatterStyle::setSize(double size) { mSize = size; } @@ -10935,7 +10787,7 @@ void QCPScatterStyle::setSize( double size ) \see setSize */ -void QCPScatterStyle::setShape( QCPScatterStyle::ScatterShape shape ) +void QCPScatterStyle::setShape(QCPScatterStyle::ScatterShape shape) { mShape = shape; } @@ -10949,7 +10801,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; @@ -10961,7 +10813,7 @@ void QCPScatterStyle::setPen( const QPen& pen ) \see setPen */ -void QCPScatterStyle::setBrush( const QBrush& brush ) +void QCPScatterStyle::setBrush(const QBrush &brush) { mBrush = brush; } @@ -10973,9 +10825,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; } @@ -10984,9 +10836,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; } @@ -11010,10 +10862,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); } /*! @@ -11024,136 +10876,153 @@ void QCPScatterStyle::applyTo( QCPPainter* painter, const QPen& defaultPen ) con \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( qRound( x - widthHalf ), qRound( 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(qRound(x-widthHalf), qRound(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' */ + /* including file 'src/plottable.cpp' */ -/* modified 2021-03-29T02:30:44, size 38818 */ +/* modified 2022-11-06T12:45:56, size 38818 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPSelectionDecorator @@ -11188,8 +11057,11 @@ 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 ), mUsedScatterProperties( QCPScatterStyle::spNone ), mPlottable( nullptr ) +QCPSelectionDecorator::QCPSelectionDecorator() : + mPen(QColor(80, 80, 255), 2.5), + mBrush(Qt::NoBrush), + mUsedScatterProperties(QCPScatterStyle::spNone), + mPlottable(nullptr) { } @@ -11200,7 +11072,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; } @@ -11208,7 +11080,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; } @@ -11220,10 +11092,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); } /*! @@ -11233,7 +11105,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; } @@ -11243,9 +11115,9 @@ void QCPSelectionDecorator::setUsedScatterProperties( const QCPScatterStyle::Sca \see applyBrush, getFinalScatterStyle */ -void QCPSelectionDecorator::applyPen( QCPPainter* painter ) const +void QCPSelectionDecorator::applyPen(QCPPainter *painter) const { - painter->setPen( mPen ); + painter->setPen(mPen); } /*! @@ -11253,9 +11125,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); } /*! @@ -11266,17 +11138,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; } @@ -11284,11 +11156,11 @@ QCPScatterStyle QCPSelectionDecorator::getFinalScatterStyle( const QCPScatterSty 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()); } /*! @@ -11299,10 +11171,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 @@ -11314,20 +11186,20 @@ void QCPSelectionDecorator::drawDecoration( QCPPainter* painter, QCPDataSelectio 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -11543,21 +11415,30 @@ bool QCPSelectionDecorator::registerWithPlottable( QCPAbstractPlottable* plottab 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( nullptr ) +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(nullptr) { - 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 = nullptr; @@ -11568,7 +11449,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; } @@ -11579,7 +11460,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; } @@ -11590,7 +11471,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; } @@ -11603,7 +11484,7 @@ void QCPAbstractPlottable::setAntialiasedScatters( bool enabled ) \see setBrush */ -void QCPAbstractPlottable::setPen( const QPen& pen ) +void QCPAbstractPlottable::setPen(const QPen &pen) { mPen = pen; } @@ -11617,7 +11498,7 @@ void QCPAbstractPlottable::setPen( const QPen& pen ) \see setPen */ -void QCPAbstractPlottable::setBrush( const QBrush& brush ) +void QCPAbstractPlottable::setBrush(const QBrush &brush) { mBrush = brush; } @@ -11633,7 +11514,7 @@ void QCPAbstractPlottable::setBrush( const QBrush& brush ) \see setValueAxis */ -void QCPAbstractPlottable::setKeyAxis( QCPAxis* axis ) +void QCPAbstractPlottable::setKeyAxis(QCPAxis *axis) { mKeyAxis = axis; } @@ -11649,11 +11530,12 @@ 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 @@ -11672,14 +11554,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); } } @@ -11692,17 +11574,16 @@ 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)) { - delete mSelectionDecorator; // delete old decorator if necessary + delete mSelectionDecorator; // delete old decorator if necessary mSelectionDecorator = decorator; } - } - else if( mSelectionDecorator ) // just clear decorator + } else if (mSelectionDecorator) // just clear decorator { delete mSelectionDecorator; mSelectionDecorator = nullptr; @@ -11719,22 +11600,23 @@ void QCPAbstractPlottable::setSelectionDecorator( QCPSelectionDecorator* decorat \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 @@ -11744,25 +11626,20 @@ 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 ) + 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) { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - - if( keyAxis->orientation() == Qt::Horizontal ) + x = keyAxis->coordToPixel(key); + y = valueAxis->coordToPixel(value); + } else { - x = keyAxis->coordToPixel( key ); - y = valueAxis->coordToPixel( value ); - } - else - { - y = keyAxis->coordToPixel( key ); - x = valueAxis->coordToPixel( value ); + y = keyAxis->coordToPixel(key); + x = valueAxis->coordToPixel(value); } } @@ -11770,20 +11647,16 @@ void QCPAbstractPlottable::coordsToPixels( double key, double value, double& x, 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)); } /*! @@ -11795,25 +11668,20 @@ const QPointF QCPAbstractPlottable::coordsToPixels( double key, double value ) c \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 ) + 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) { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - - if( keyAxis->orientation() == Qt::Horizontal ) + key = keyAxis->pixelToCoord(x); + value = valueAxis->pixelToCoord(y); + } else { - key = keyAxis->pixelToCoord( x ); - value = valueAxis->pixelToCoord( y ); - } - else - { - key = keyAxis->pixelToCoord( y ); - value = valueAxis->pixelToCoord( x ); + key = keyAxis->pixelToCoord(y); + value = valueAxis->pixelToCoord(x); } } @@ -11821,9 +11689,9 @@ void QCPAbstractPlottable::pixelsToCoords( double x, double y, double& key, doub 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); } /*! @@ -11839,10 +11707,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); } /*! @@ -11850,40 +11718,35 @@ 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; - } - + 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 ); - + if (keyAxis->scaleType() == QCPAxis::stLogarithmic) + signDomain = (keyAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + bool foundRange; - QCPRange newRange = getKeyRange( foundRange, signDomain ); - if( 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 + 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); } } @@ -11897,41 +11760,36 @@ 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; - } - + 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 ); - + 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 ) + 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 + 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); } } @@ -11949,25 +11807,24 @@ void QCPAbstractPlottable::rescaleValueAxis( bool onlyEnlarge, bool inKeyRange ) \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; } @@ -11979,10 +11836,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 @@ -11995,16 +11852,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; } @@ -12017,16 +11874,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 {}; @@ -12053,9 +11910,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 @@ -12069,9 +11926,9 @@ void QCPAbstractPlottable::applyDefaultAntialiasingHint( QCPPainter* painter ) c \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 @@ -12085,59 +11942,58 @@ void QCPAbstractPlottable::applyFillAntialiasingHint( QCPPainter* painter ) cons \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 + 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 ); + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); else - setSelection( mSelection + newSelection ); + setSelection(mSelection+newSelection); } - } - else - setSelection( newSelection ); - if( selectionStateChanged ) + } 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' */ -/* modified 2021-03-29T02:30:44, size 49486 */ +/* modified 2022-11-06T12:45:56, size 49486 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemAnchor @@ -12183,23 +12039,26 @@ 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.values() ) + foreach (QCPItemPosition *child, mChildrenX.values()) { - if( child->parentAnchorX() == this ) - child->setParentAnchorX( nullptr ); // this acts back on this anchor and child removes itself from mChildrenX + if (child->parentAnchorX() == this) + child->setParentAnchorX(nullptr); // this acts back on this anchor and child removes itself from mChildrenX } - foreach( QCPItemPosition* child, mChildrenY.values() ) + foreach (QCPItemPosition *child, mChildrenY.values()) { - if( child->parentAnchorY() == this ) - child->setParentAnchorY( nullptr ); // this acts back on this anchor and child removes itself from mChildrenY + if (child->parentAnchorY() == this) + child->setParentAnchorY(nullptr); // this acts back on this anchor and child removes itself from mChildrenY } } @@ -12211,19 +12070,17 @@ 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 {}; } - } - else + } else { qDebug() << Q_FUNC_INFO << "no parent item set"; return {}; @@ -12238,12 +12095,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 @@ -12252,10 +12109,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 @@ -12266,12 +12123,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 @@ -12280,12 +12137,13 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -12355,8 +12213,14 @@ 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( nullptr ), mParentAnchorY( nullptr ) +QCPItemPosition::QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString &name) : + QCPItemAnchor(parentPlot, parentItem, name), + mPositionTypeX(ptAbsolute), + mPositionTypeY(ptAbsolute), + mKey(0), + mValue(0), + mParentAnchorX(nullptr), + mParentAnchorY(nullptr) { } @@ -12365,25 +12229,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.values() ) + foreach (QCPItemPosition *child, mChildrenX.values()) { - if( child->parentAnchorX() == this ) - child->setParentAnchorX( nullptr ); // this acts back on this anchor and child removes itself from mChildrenX + if (child->parentAnchorX() == this) + child->setParentAnchorX(nullptr); // this acts back on this anchor and child removes itself from mChildrenX } - foreach( QCPItemPosition* child, mChildrenY.values() ) + foreach (QCPItemPosition *child, mChildrenY.values()) { - if( child->parentAnchorY() == this ) - child->setParentAnchorY( nullptr ); // this acts back on this anchor and child removes itself from mChildrenY + if (child->parentAnchorY() == this) + child->setParentAnchorY(nullptr); // 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(); } @@ -12413,10 +12277,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); } /*! @@ -12426,26 +12290,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); } } @@ -12456,26 +12320,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); } } @@ -12497,10 +12361,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; } @@ -12511,62 +12375,61 @@ bool QCPItemPosition::setParentAnchor( QCPItemAnchor* parentAnchor, bool keepPix \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; } @@ -12577,62 +12440,61 @@ bool QCPItemPosition::setParentAnchorX( QCPItemAnchor* parentAnchor, bool keepPi \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; } @@ -12653,7 +12515,7 @@ bool QCPItemPosition::setParentAnchorY( QCPItemAnchor* parentAnchor, bool keepPi \see setPixelPosition */ -void QCPItemPosition::setCoords( double key, double value ) +void QCPItemPosition::setCoords(double key, double value) { mKey = key; mValue = value; @@ -12664,9 +12526,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()); } /*! @@ -12678,89 +12540,95 @@ 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 ) + case ptAbsolute: { - result.rx() = mKey * mAxisRect.data()->width(); - if( mParentAnchorX ) + 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() += mAxisRect.data()->left(); + result.rx() += mParentPlot->viewport().left(); + break; } - 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 ) - { - 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 ) + case ptAxisRectRatio: { - result.ry() = mValue * mAxisRect.data()->height(); - if( mParentAnchorY ) + 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) + { + 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() += mAxisRect.data()->top(); + 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; } - 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; } @@ -12769,7 +12637,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; @@ -12780,7 +12648,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; } @@ -12795,92 +12663,99 @@ 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 ) + + 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 ) + case ptAbsolute: { - if( mParentAnchorX ) + if (mParentAnchorX) + x -= mParentAnchorX->pixelPosition().x(); + break; + } + case ptViewportRatio: + { + if (mParentAnchorX) x -= mParentAnchorX->pixelPosition().x(); else - x -= mAxisRect.data()->left(); - x /= double( mAxisRect.data()->width() ); + x -= mParentPlot->viewport().left(); + x /= double(mParentPlot->viewport().width()); + break; } - 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 ) + case ptAxisRectRatio: { - if( mParentAnchorY ) + 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 -= mAxisRect.data()->top(); - y /= double( mAxisRect.data()->height() ); + 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; } - 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 ); + + setCoords(x, y); } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractItem //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -13053,27 +12928,30 @@ 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.isEmpty() ) + if (!rects.isEmpty()) { - 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(); } @@ -13084,11 +12962,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()); } /*! @@ -13097,11 +12975,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()); } /*! @@ -13113,12 +12991,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); } } @@ -13136,12 +13014,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); } } @@ -13155,11 +13033,11 @@ void QCPAbstractItem::setSelected( bool selected ) \see positions, anchor */ -QCPItemPosition* QCPAbstractItem::position( const QString& name ) const +QCPItemPosition *QCPAbstractItem::position(const QString &name) const { - foreach( QCPItemPosition* position, mPositions ) + foreach (QCPItemPosition *position, mPositions) { - if( position->name() == name ) + if (position->name() == name) return position; } qDebug() << Q_FUNC_INFO << "position with name not found:" << name; @@ -13176,11 +13054,11 @@ QCPItemPosition* QCPAbstractItem::position( const QString& name ) const \see anchors, position */ -QCPItemAnchor* QCPAbstractItem::anchor( const QString& name ) const +QCPItemAnchor *QCPAbstractItem::anchor(const QString &name) const { - foreach( QCPItemAnchor* anchor, mAnchors ) + foreach (QCPItemAnchor *anchor, mAnchors) { - if( anchor->name() == name ) + if (anchor->name() == name) return anchor; } qDebug() << Q_FUNC_INFO << "anchor with name not found:" << name; @@ -13195,11 +13073,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 { - foreach( QCPItemAnchor* anchor, mAnchors ) + foreach (QCPItemAnchor *anchor, mAnchors) { - if( anchor->name() == name ) + if (anchor->name() == name) return true; } return false; @@ -13216,7 +13094,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(); @@ -13235,9 +13113,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 @@ -13253,28 +13131,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: - const QList lines = QList() << QLineF( rect.topLeft(), rect.topRight() ) << QLineF( rect.bottomLeft(), rect.bottomRight() ) - << QLineF( rect.topLeft(), rect.bottomLeft() ) << QLineF( rect.topRight(), rect.bottomRight() ); - const QCPVector2D posVec( pos ); + const QList lines = QList() << QLineF(rect.topLeft(), rect.topRight()) << QLineF(rect.bottomLeft(), rect.bottomRight()) + << QLineF(rect.topLeft(), rect.bottomLeft()) << QLineF(rect.topRight(), rect.bottomRight()); + const QCPVector2D posVec(pos); double minDistSqr = (std::numeric_limits::max)(); - foreach( const QLineF& line, lines ) + foreach (const QLineF &line, lines) { - double distSqr = posVec.distanceSquaredToLine( line.p1(), line.p2() ); - if( distSqr < minDistSqr ) + double distSqr = posVec.distanceSquaredToLine(line.p1(), line.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; } @@ -13289,7 +13167,7 @@ double QCPAbstractItem::rectDistance( const QRectF& rect, const QPointF& pos, bo \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 {}; @@ -13309,18 +13187,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; } @@ -13343,37 +13221,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; } } @@ -13385,8 +13263,9 @@ QCP::Interaction QCPAbstractItem::selectionCategory() const } /* end of 'src/item.cpp' */ + /* including file 'src/core.cpp' */ -/* modified 2021-03-29T02:30:44, size 127198 */ +/* modified 2022-11-06T12:45:56, size 127625 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCustomPlot @@ -13398,7 +13277,7 @@ QCP::Interaction QCPAbstractItem::selectionCategory() const interacts with the user. For tutorials on how to use QCustomPlot, see the website\n - http://www.qcustomplot.com/ + https://www.qcustomplot.com/ */ /* start of documentation of inline functions */ @@ -13715,97 +13594,102 @@ QCP::Interaction QCPAbstractItem::selectionCategory() const /*! Constructs a QCustomPlot and sets reasonable default values. */ -QCustomPlot::QCustomPlot( QWidget* parent ) - : QWidget( parent ), xAxis( nullptr ), yAxis( nullptr ), xAxis2( nullptr ), yAxis2( nullptr ), legend( nullptr ), mBufferDevicePixelRatio( 1.0 ), // will be adapted to primary screen below - mPlotLayout( nullptr ) - , mAutoAddPlottableToLegend( true ) - , mAntialiasedElements( QCP::aeNone ) - , mNotAntialiasedElements( QCP::aeNone ) - , mInteractions( QCP::iNone ) - , mSelectionTolerance( 8 ) - , mNoAntialiasingOnDrag( false ) - , mBackgroundBrush( Qt::white, Qt::SolidPattern ) - , mBackgroundScaled( true ) - , mBackgroundScaledMode( Qt::KeepAspectRatioByExpanding ) - , mCurrentLayer( nullptr ) - , mPlottingHints( QCP::phCacheLabels | QCP::phImmediateRefresh ) - , mMultiSelectModifier( Qt::ControlModifier ) - , mSelectionRectMode( QCP::srmNone ) - , mSelectionRect( nullptr ) - , mOpenGl( false ) - , mMouseHasMoved( false ) - , mMouseEventLayerable( nullptr ) - , mMouseSignalLayerable( nullptr ) - , mReplotting( false ) - , mReplotQueued( false ) - , mReplotTime( 0 ) - , mReplotTimeAverage( 0 ) - , mOpenGlMultisamples( 16 ) - , mOpenGlAntialiasedElementsBackup( QCP::aeNone ) - , mOpenGlCacheLabelsBackup( true ) +QCustomPlot::QCustomPlot(QWidget *parent) : + QWidget(parent), + xAxis(nullptr), + yAxis(nullptr), + xAxis2(nullptr), + yAxis2(nullptr), + legend(nullptr), + mBufferDevicePixelRatio(1.0), // will be adapted to true value below + mPlotLayout(nullptr), + mAutoAddPlottableToLegend(true), + mAntialiasedElements(QCP::aeNone), + mNotAntialiasedElements(QCP::aeNone), + mInteractions(QCP::iNone), + mSelectionTolerance(8), + mNoAntialiasingOnDrag(false), + mBackgroundBrush(Qt::white, Qt::SolidPattern), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mCurrentLayer(nullptr), + mPlottingHints(QCP::phCacheLabels|QCP::phImmediateRefresh), + mMultiSelectModifier(Qt::ControlModifier), + mSelectionRectMode(QCP::srmNone), + mSelectionRect(nullptr), + mOpenGl(false), + mMouseHasMoved(false), + mMouseEventLayerable(nullptr), + mMouseSignalLayerable(nullptr), + mReplotting(false), + mReplotQueued(false), + mReplotTime(0), + mReplotTimeAverage(0), + mOpenGlMultisamples(16), + mOpenGlAntialiasedElementsBackup(QCP::aeNone), + mOpenGlCacheLabelsBackup(true) { - setAttribute( Qt::WA_NoMousePropagation ); - setAttribute( Qt::WA_OpaquePaintEvent ); - setFocusPolicy( Qt::ClickFocus ); - setMouseTracking( true ); + setAttribute(Qt::WA_NoMousePropagation); + 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() ); +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + setBufferDevicePixelRatio(QWidget::devicePixelRatioF()); +# else + setBufferDevicePixelRatio(QWidget::devicePixelRatio()); +# endif #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() @@ -13813,14 +13697,14 @@ QCustomPlot::~QCustomPlot() clearPlottables(); clearItems(); - if( mPlotLayout ) + if (mPlotLayout) { delete mPlotLayout; mPlotLayout = nullptr; } - + mCurrentLayer = nullptr; - 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(); } @@ -13841,12 +13725,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; } @@ -13857,15 +13741,15 @@ void QCustomPlot::setAntialiasedElements( const QCP::AntialiasedElements& antial \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; } @@ -13887,12 +13771,12 @@ void QCustomPlot::setAntialiasedElement( QCP::AntialiasedElement antialiasedElem \see setAntialiasedElements */ -void QCustomPlot::setNotAntialiasedElements( const QCP::AntialiasedElements& notAntialiasedElements ) +void QCustomPlot::setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements) { mNotAntialiasedElements = notAntialiasedElements; - + // make sure elements aren't in mNotAntialiasedElements and mAntialiasedElements simultaneously: - if( ( mNotAntialiasedElements & mAntialiasedElements ) != 0 ) + if ((mNotAntialiasedElements & mAntialiasedElements) != 0) mAntialiasedElements |= ~mNotAntialiasedElements; } @@ -13903,15 +13787,15 @@ void QCustomPlot::setNotAntialiasedElements( const QCP::AntialiasedElements& not \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; } @@ -13921,7 +13805,7 @@ void QCustomPlot::setNotAntialiasedElement( QCP::AntialiasedElement notAntialias \see addGraph, QCPLegend::addItem */ -void QCustomPlot::setAutoAddPlottableToLegend( bool on ) +void QCustomPlot::setAutoAddPlottableToLegend(bool on) { mAutoAddPlottableToLegend = on; } @@ -13980,7 +13864,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; } @@ -13992,11 +13876,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; } @@ -14013,7 +13897,7 @@ void QCustomPlot::setInteraction( const QCP::Interaction& interaction, bool enab \see setInteractions, QCPLayerable::selectTest */ -void QCustomPlot::setSelectionTolerance( int pixels ) +void QCustomPlot::setSelectionTolerance(int pixels) { mSelectionTolerance = pixels; } @@ -14027,7 +13911,7 @@ void QCustomPlot::setSelectionTolerance( int pixels ) \see setAntialiasedElements, setNotAntialiasedElements */ -void QCustomPlot::setNoAntialiasingOnDrag( bool enabled ) +void QCustomPlot::setNoAntialiasingOnDrag(bool enabled) { mNoAntialiasingOnDrag = enabled; } @@ -14037,7 +13921,7 @@ void QCustomPlot::setNoAntialiasingOnDrag( bool enabled ) \see setPlottingHint */ -void QCustomPlot::setPlottingHints( const QCP::PlottingHints& hints ) +void QCustomPlot::setPlottingHints(const QCP::PlottingHints &hints) { mPlottingHints = hints; } @@ -14047,16 +13931,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); } /*! @@ -14069,7 +13953,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; } @@ -14094,26 +13978,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; } @@ -14127,19 +14011,19 @@ void QCustomPlot::setSelectionRectMode( QCP::SelectionRectMode mode ) \see setSelectionRectMode */ -void QCustomPlot::setSelectionRect( QCPSelectionRect* selectionRect ) +void QCustomPlot::setSelectionRect(QCPSelectionRect *selectionRect) { 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*))); } } @@ -14179,42 +14063,40 @@ 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 } @@ -14235,11 +14117,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); } /*! @@ -14253,15 +14135,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; - foreach( QSharedPointer buffer, mPaintBuffers ) - buffer->setDevicePixelRatio( mBufferDevicePixelRatio ); - // Note: axis label cache has devicePixelRatio as part of cache hash, so no need to manually clear cache here + foreach (QSharedPointer buffer, mPaintBuffers) + buffer->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; @@ -14284,7 +14166,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(); @@ -14303,7 +14185,7 @@ void QCustomPlot::setBackground( const QPixmap& pm ) \see setBackgroundScaled, setBackgroundScaledMode */ -void QCustomPlot::setBackground( const QBrush& brush ) +void QCustomPlot::setBackground(const QBrush &brush) { mBackgroundBrush = brush; } @@ -14315,7 +14197,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(); @@ -14333,7 +14215,7 @@ void QCustomPlot::setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatio \see setBackground, setBackgroundScaledMode */ -void QCustomPlot::setBackgroundScaled( bool scaled ) +void QCustomPlot::setBackgroundScaled(bool scaled) { mBackgroundScaled = scaled; } @@ -14344,7 +14226,7 @@ void QCustomPlot::setBackgroundScaled( bool scaled ) \see setBackground, setBackgroundScaled */ -void QCustomPlot::setBackgroundScaledMode( Qt::AspectRatioMode mode ) +void QCustomPlot::setBackgroundScaledMode(Qt::AspectRatioMode mode) { mBackgroundScaledMode = mode; } @@ -14357,13 +14239,12 @@ 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 nullptr; @@ -14377,13 +14258,12 @@ 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 nullptr; } @@ -14395,22 +14275,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; } @@ -14418,10 +14298,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; @@ -14440,8 +14320,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; } @@ -14465,10 +14345,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; } @@ -14482,17 +14362,17 @@ QList QCustomPlot::selectedPlottables() const \see plottableAt(), itemAt, layoutElementAt */ -QCPAbstractPlottable* QCustomPlot::plottableAt( const QPointF& pos, bool onlySelectable, int* dataIndex ) const +QCPAbstractPlottable *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable, int *dataIndex) const { - return plottableAt( pos, onlySelectable, dataIndex ); + return plottableAt(pos, onlySelectable, dataIndex); } /*! 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); } /*! @@ -14503,13 +14383,12 @@ 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 nullptr; @@ -14523,13 +14402,12 @@ 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 nullptr; } @@ -14545,25 +14423,23 @@ 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 nullptr; } - 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 nullptr; } - - 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; } @@ -14577,19 +14453,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; } @@ -14605,8 +14481,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; } @@ -14631,10 +14507,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; } @@ -14647,13 +14523,12 @@ 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 nullptr; @@ -14667,13 +14542,12 @@ 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 nullptr; } @@ -14684,17 +14558,16 @@ 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; } } @@ -14703,10 +14576,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; @@ -14724,8 +14597,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; } @@ -14747,10 +14620,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; } @@ -14764,9 +14637,9 @@ QList QCustomPlot::selectedItems() const \see itemAt(), plottableAt, layoutElementAt */ -QCPAbstractItem* QCustomPlot::itemAt( const QPointF& pos, bool onlySelectable ) const +QCPAbstractItem *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const { - return itemAt( pos, onlySelectable ); + return itemAt(pos, onlySelectable); } /*! @@ -14774,9 +14647,9 @@ QCPAbstractItem* QCustomPlot::itemAt( const QPointF& pos, bool onlySelectable ) \see item */ -bool QCustomPlot::hasItem( QCPAbstractItem* item ) const +bool QCustomPlot::hasItem(QCPAbstractItem *item) const { - return mItems.contains( item ); + return mItems.contains(item); } /*! @@ -14787,11 +14660,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 nullptr; @@ -14803,13 +14676,12 @@ 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 nullptr; @@ -14819,7 +14691,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; } @@ -14834,13 +14706,12 @@ 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; @@ -14855,14 +14726,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; } @@ -14890,25 +14761,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; } @@ -14926,40 +14797,40 @@ bool QCustomPlot::addLayer( const QString& name, QCPLayer* otherLayer, QCustomPl \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 (such that relative order stays the same) - std::reverse( children.begin(), children.end() ); - foreach( QCPLayerable* child, children ) - child->moveToLayer( targetLayer, isFirstLayer ); // prepend if isFirstLayer, otherwise append - + if (isFirstLayer) // prepend in reverse order (such that relative order stays the same) + std::reverse(children.begin(), children.end()); + foreach (QCPLayerable *child, children) + child->moveToLayer(targetLayer, isFirstLayer); // prepend if isFirstLayer, otherwise append + // 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( QSharedPointer pb = layer->mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = layer->mPaintBuffer.toStrongRef()) pb->setInvalidated(); - + // remove layer: delete layer; - mLayers.removeOne( layer ); + mLayers.removeOne(layer); updateLayerIndices(); return true; } @@ -14973,30 +14844,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( QSharedPointer pb = layer->mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = layer->mPaintBuffer.toStrongRef()) pb->setInvalidated(); - if( QSharedPointer pb = otherLayer->mPaintBuffer.toStrongRef() ) + if (QSharedPointer pb = otherLayer->mPaintBuffer.toStrongRef()) pb->setInvalidated(); - + updateLayerIndices(); return true; } @@ -15034,14 +14905,13 @@ 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 nullptr; @@ -15063,22 +14933,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; } @@ -15091,16 +14961,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; @@ -15121,21 +14991,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 = nullptr; - QCPLayoutElement* currentElement = mPlotLayout; + QCPAxisRect *result = nullptr; + 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; } @@ -15154,15 +15024,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; } @@ -15176,27 +15046,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; } @@ -15211,10 +15081,10 @@ QList QCustomPlot::selectedLegends() const */ void QCustomPlot::deselectAll() { - foreach( QCPLayer* layer, mLayers ) + foreach (QCPLayer *layer, mLayers) { - foreach( QCPLayerable* layerable, layer->children() ) - layerable->deselectEvent( nullptr ); + foreach (QCPLayerable *layerable, layer->children()) + layerable->deselectEvent(nullptr); } } @@ -15245,55 +15115,55 @@ void QCustomPlot::deselectAll() \see replotTime */ -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(); - -#if QT_VERSION < QT_VERSION_CHECK( 4, 8, 0 ) + +# if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) QTime replotTimer; replotTimer.start(); -#else +# else QElapsedTimer replotTimer; replotTimer.start(); -#endif - +# endif + updateLayout(); // draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers: setupPaintBuffers(); - foreach( QCPLayer* layer, mLayers ) + foreach (QCPLayer *layer, mLayers) layer->drawToPaintBuffer(); - foreach( QSharedPointer buffer, mPaintBuffers ) - buffer->setInvalidated( false ); - - if( ( refreshPriority == rpRefreshHint && mPlottingHints.testFlag( QCP::phImmediateRefresh ) ) || refreshPriority == rpImmediateRefresh ) + foreach (QSharedPointer buffer, mPaintBuffers) + buffer->setInvalidated(false); + + if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority==rpImmediateRefresh) repaint(); else update(); - -#if QT_VERSION < QT_VERSION_CHECK( 4, 8, 0 ) + +# if QT_VERSION < QT_VERSION_CHECK(4, 8, 0) mReplotTime = replotTimer.elapsed(); -#else - mReplotTime = replotTimer.nsecsElapsed() * 1e-6; -#endif - if( !qFuzzyIsNull( mReplotTimeAverage ) ) - mReplotTimeAverage = mReplotTimeAverage * 0.9 + mReplotTime * 0.1; // exponential moving average with a time constant of 10 last replots +# else + mReplotTime = replotTimer.nsecsElapsed()*1e-6; +# endif + if (!qFuzzyIsNull(mReplotTimeAverage)) + mReplotTimeAverage = mReplotTimeAverage*0.9 + mReplotTime*0.1; // exponential moving average with a time constant of 10 last replots else - mReplotTimeAverage = mReplotTime; // no previous replots to average with, so initialize with replot time - + mReplotTimeAverage = mReplotTime; // no previous replots to average with, so initialize with replot time + emit afterReplot(); mReplotting = false; } @@ -15304,7 +15174,7 @@ void QCustomPlot::replot( QCustomPlot::RefreshPriority refreshPriority ) \see replot */ -double QCustomPlot::replotTime( bool average ) const +double QCustomPlot::replotTime(bool average) const { return average ? mReplotTimeAverage : mReplotTime; } @@ -15317,14 +15187,14 @@ double QCustomPlot::replotTime( bool average ) const \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); } /*! @@ -15364,67 +15234,66 @@ 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; } @@ -15473,9 +15342,9 @@ bool QCustomPlot::savePdf( const QString& fileName, int width, int height, QCP:: \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); } /*! @@ -15520,9 +15389,9 @@ bool QCustomPlot::savePng( const QString& fileName, int width, int height, doubl \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); } /*! @@ -15564,9 +15433,9 @@ bool QCustomPlot::saveJpg( const QString& fileName, int width, int height, doubl \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 @@ -15597,20 +15466,36 @@ 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) + + // detect if the device pixel ratio has changed (e.g. moving window between different DPI screens), and adapt buffers if necessary: +#ifdef QCP_DEVICEPIXELRATIO_SUPPORTED +# ifdef QCP_DEVICEPIXELRATIO_FLOAT + double newDpr = devicePixelRatioF(); +# else + double newDpr = devicePixelRatio(); +# endif + if (!qFuzzyCompare(mBufferDevicePixelRatio, newDpr)) { -#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) - painter.setRenderHint( QPainter::HighQualityAntialiasing ); // to make Antialiasing look good if using the OpenGL graphicssystem + setBufferDevicePixelRatio(newDpr); + replot(QCustomPlot::rpQueuedRefresh); + return; + } #endif - if( mBackgroundBrush.style() != Qt::NoBrush ) - painter.fillRect( mViewport, mBackgroundBrush ); - drawBackground( &painter ); - foreach( QSharedPointer buffer, mPaintBuffers ) - buffer->draw( &painter ); + + QCPPainter painter(this); + if (painter.isActive()) + { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystem +#endif + if (mBackgroundBrush.style() != Qt::NoBrush) + painter.fillRect(mViewport, mBackgroundBrush); + drawBackground(&painter); + foreach (QSharedPointer buffer, mPaintBuffers) + buffer->draw(&painter); } } @@ -15619,12 +15504,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 @@ -15636,48 +15521,47 @@ 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.size(); ++i ) + QList candidates = layerableListAt(mMousePressPos, false, &details); + for (int i=0; iaccept(); // 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, nullptr, 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, nullptr, 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 @@ -15689,43 +15573,42 @@ 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; i < candidates.size(); ++i ) + 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 @@ -15740,19 +15623,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 @@ -15769,55 +15652,53 @@ 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, nullptr, 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, nullptr, event); + else if (QCPAbstractLegendItem *li = qobject_cast(mMouseSignalLayerable)) + emit legendClick(li->parentLegend(), li, event); mMouseSignalLayerable = nullptr; } - - 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 = nullptr; } } - - 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 @@ -15825,25 +15706,25 @@ 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 ); - -#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 ) + emit mouseWheel(event); + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QPointF pos = event->pos(); #else const QPointF pos = event->position(); #endif - + // forward event to layerable under cursor: - foreach( QCPLayerable* candidate, layerableListAt( pos, false ) ) + foreach (QCPLayerable *candidate, layerableListAt(pos, false)) { - event->accept(); // default impl of QCPLayerable's mouse events ignore the event, in that case propagate to next candidate in list - candidate->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 + candidate->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 @@ -15856,17 +15737,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()) { @@ -15890,9 +15771,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); emit afterLayout(); } @@ -15914,25 +15795,24 @@ 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())); } } } @@ -15959,38 +15839,37 @@ 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: - foreach( QSharedPointer buffer, mPaintBuffers ) + foreach (QSharedPointer buffer, mPaintBuffers) { - buffer->setSize( viewport().size() ); // won't do anything if already correct size - buffer->clear( Qt::transparent ); + buffer->setSize(viewport().size()); // won't do anything if already correct size + buffer->clear(Qt::transparent); buffer->setInvalidated(); } } @@ -16003,21 +15882,20 @@ 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); } /*! @@ -16033,9 +15911,9 @@ QCPAbstractPaintBuffer* QCustomPlot::createPaintBuffer() */ bool QCustomPlot::hasInvalidatedPaintBuffers() { - foreach( QSharedPointer buffer, mPaintBuffers ) + foreach (QSharedPointer buffer, mPaintBuffers) { - if( buffer->invalidated() ) + if (buffer->invalidated()) return true; } return false; @@ -16059,42 +15937,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; @@ -16126,17 +16004,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 = nullptr; - if( xAxis2 == axis ) + if (xAxis2 == axis) xAxis2 = nullptr; - if( yAxis == axis ) + if (yAxis == axis) yAxis = nullptr; - if( yAxis2 == axis ) + if (yAxis2 == axis) yAxis2 = nullptr; - + // Note: No need to take care of range drag axes and range zoom axes, because they are stored in smart pointers } @@ -16145,9 +16023,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 = nullptr; } @@ -16168,81 +16046,80 @@ void QCustomPlot::legendRemoved( QCPLegend* legend ) \see processRectZoom */ -void QCustomPlot::processRectSelection( QRect rect, QMouseEvent* event ) +void QCustomPlot::processRectSelection(QRect rect, QMouseEvent *event) { typedef QPair SelectionCandidate; - typedef QMultiMap SelectionCandidates; // map key is number of selected data points, so we have selections sorted by size - + typedef QMultiMap SelectionCandidates; // map key is number of selected data points, so we have selections sorted by size + bool selectionStateChanged = false; - - if( mInteractions.testFlag( QCP::iSelectPlottables ) ) + + if (mInteractions.testFlag(QCP::iSelectPlottables)) { SelectionCandidates potentialSelections; - QRectF rectF( rect.normalized() ); - if( QCPAxisRect* affectedAxisRect = axisRectAt( rectF.topLeft() ) ) + 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.insert( dataSel.dataPointCount(), SelectionCandidate( plottable, dataSel ) ); + QCPDataSelection dataSel = plottableInterface->selectTestRect(rectF, true); + if (!dataSel.isEmpty()) + potentialSelections.insert(dataSel.dataPointCount(), SelectionCandidate(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()) { SelectionCandidates::iterator it = potentialSelections.begin(); - while( it != std::prev( potentialSelections.end() ) ) // erase all except last element - it = potentialSelections.erase( it ); + while (it != std::prev(potentialSelections.end())) // 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: SelectionCandidates::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(); } @@ -16257,16 +16134,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( nullptr ) ); - axisRect->zoom( QRectF( rect ), affectedAxes ); + QList affectedAxes = QList() << axisRect->rangeZoomAxes(Qt::Horizontal) << axisRect->rangeZoomAxes(Qt::Vertical); + affectedAxes.removeAll(static_cast(nullptr)); + axisRect->zoom(QRectF(rect), affectedAxes); } - replot( rpQueuedReplot ); // always replot to make selection rect disappear + replot(rpQueuedReplot); // always replot to make selection rect disappear } /*! \internal @@ -16286,39 +16163,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); } } @@ -16333,25 +16210,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; } @@ -16364,23 +16241,24 @@ 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. @@ -16390,22 +16268,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; } @@ -16417,8 +16295,8 @@ bool QCustomPlot::registerItem( QCPAbstractItem* item ) */ void QCustomPlot::updateLayerIndices() const { - for( int i = 0; i < mLayers.size(); ++i ) - mLayers.at( i )->mIndex = i; + for (int i=0; imIndex = i; } /*! \internal @@ -16436,13 +16314,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 : nullptr ); - if( selectionDetails && !details.isEmpty() ) + QList candidates = layerableListAt(pos, onlySelectable, selectionDetails ? &details : nullptr); + if (selectionDetails && !details.isEmpty()) *selectionDetails = details.first(); - if( !candidates.isEmpty() ) + if (!candidates.isEmpty()) return candidates.first(); else return nullptr; @@ -16467,23 +16345,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 : nullptr ); - if( dist >= 0 && dist < selectionTolerance() ) + double dist = layerables.at(i)->selectTest(pos, onlySelectable, selectionDetails ? &details : nullptr); + 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); } } } @@ -16508,27 +16386,21 @@ QList QCustomPlot::layerableListAt( const QPointF& pos, bool only \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 = int( resolution / 0.0254 ); - break; + case QCP::ruDotsPerMeter: dotsPerMeter = resolution; break; + case QCP::ruDotsPerCentimeter: dotsPerMeter = resolution*100; break; + case QCP::ruDotsPerInch: dotsPerMeter = int(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; } @@ -16541,45 +16413,43 @@ bool QCustomPlot::saveRastered( const QString& fileName, int width, int height, \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(); @@ -16599,38 +16469,38 @@ 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' */ + /* including file 'src/colorgradient.cpp' */ -/* modified 2021-03-29T02:30:44, size 25278 */ +/* modified 2022-11-06T12:45:56, size 25408 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorGradient @@ -16672,10 +16542,15 @@ void QCustomPlot::toPainter( QCPPainter* painter, int width, int height ) The color level count is initialized to 350. */ -QCPColorGradient::QCPColorGradient() - : mLevelCount( 350 ), mColorInterpolation( ciRGB ), mNanHandling( nhNone ), mNanColor( Qt::black ), mPeriodic( false ), mColorBufferInvalidated( true ) +QCPColorGradient::QCPColorGradient() : + mLevelCount(350), + mColorInterpolation(ciRGB), + mNanHandling(nhNone), + mNanColor(Qt::black), + mPeriodic(false), + mColorBufferInvalidated(true) { - mColorBuffer.fill( qRgb( 0, 0, 0 ), mLevelCount ); + mColorBuffer.fill(qRgb(0, 0, 0), mLevelCount); } /*! @@ -16684,22 +16559,27 @@ QCPColorGradient::QCPColorGradient() The color level count is initialized to 350. */ -QCPColorGradient::QCPColorGradient( GradientPreset preset ) - : mLevelCount( 350 ), mColorInterpolation( ciRGB ), mNanHandling( nhNone ), mNanColor( Qt::black ), mPeriodic( false ), mColorBufferInvalidated( true ) +QCPColorGradient::QCPColorGradient(GradientPreset preset) : + mLevelCount(350), + mColorInterpolation(ciRGB), + mNanHandling(nhNone), + mNanColor(Qt::black), + 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.mNanHandling == this->mNanHandling ) && - ( other.mNanColor == this->mNanColor ) && - ( other.mPeriodic == this->mPeriodic ) && - ( other.mColorStops == this->mColorStops ) ); + return ((other.mLevelCount == this->mLevelCount) && + (other.mColorInterpolation == this->mColorInterpolation) && + (other.mNanHandling == this ->mNanHandling) && + (other.mNanColor == this->mNanColor) && + (other.mPeriodic == this->mPeriodic) && + (other.mColorStops == this->mColorStops)); } /*! @@ -16708,14 +16588,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; @@ -16733,7 +16613,7 @@ void QCPColorGradient::setLevelCount( int n ) \see clearColorStops */ -void QCPColorGradient::setColorStops( const QMap& colorStops ) +void QCPColorGradient::setColorStops(const QMap &colorStops) { mColorStops = colorStops; mColorBufferInvalidated = true; @@ -16745,9 +16625,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; } @@ -16758,9 +16638,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; @@ -16772,7 +16652,7 @@ void QCPColorGradient::setColorInterpolation( QCPColorGradient::ColorInterpolati \see setNanColor */ -void QCPColorGradient::setNanHandling( QCPColorGradient::NanHandling handling ) +void QCPColorGradient::setNanHandling(QCPColorGradient::NanHandling handling) { mNanHandling = handling; } @@ -16783,7 +16663,7 @@ void QCPColorGradient::setNanHandling( QCPColorGradient::NanHandling handling ) \see setNanHandling */ -void QCPColorGradient::setNanColor( const QColor& color ) +void QCPColorGradient::setNanColor(const QColor &color) { mNanColor = color; } @@ -16803,7 +16683,7 @@ void QCPColorGradient::setNanColor( const QColor& color ) 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; } @@ -16826,60 +16706,49 @@ 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(); - + const bool skipNanCheck = mNanHandling == nhNone; - const double posToIndexFactor = !logarithmic ? ( mLevelCount - 1 ) / range.size() : ( mLevelCount - 1 ) / qLn( range.upper / range.lower ); - for( int i = 0; i < n; ++i ) + const double posToIndexFactor = !logarithmic ? (mLevelCount-1)/range.size() : (mLevelCount-1)/qLn(range.upper/range.lower); + for (int i=0; i::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; } @@ -17161,9 +17012,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; @@ -17176,122 +17027,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 < mLevelCount; ++i ) + 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 = const_cast*>(&mColorStops)->lowerBound(position); // force using the const lowerBound method + if (it == mColorStops.constEnd()) // position is on or after last stop, use color of last stop { - if( useAlpha ) + if (useAlpha) { - const QColor col = std::prev( it ).value(); - const double alphaPremultiplier = col.alpha() / 255.0; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba( int( col.red() * alphaPremultiplier ), - int( col.green() * alphaPremultiplier ), - int( col.blue() * alphaPremultiplier ), - col.alpha() ); - } - else - mColorBuffer[i] = std::prev( it ).value().rgba(); - } - else if( it == mColorStops.constBegin() ) // position is on or before first stop, use color of first stop + const QColor col = std::prev(it).value(); + const double alphaPremultiplier = col.alpha()/255.0; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(int(col.red()*alphaPremultiplier), + int(col.green()*alphaPremultiplier), + int(col.blue()*alphaPremultiplier), + col.alpha()); + } else + mColorBuffer[i] = std::prev(it).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 double alphaPremultiplier = col.alpha() / 255.0; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba( int( col.red() * alphaPremultiplier ), - int( col.green() * alphaPremultiplier ), - int( col.blue() * alphaPremultiplier ), - col.alpha() ); - } - else + const QColor &col = it.value(); + const double alphaPremultiplier = col.alpha()/255.0; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(int(col.red()*alphaPremultiplier), + int(col.green()*alphaPremultiplier), + int(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 = std::prev( it ); - double t = ( position - low.key() ) / ( high.key() - low.key() ); // interpolation factor 0..1 - switch( mColorInterpolation ) + QMap::const_iterator low = std::prev(it); + double t = (position-low.key())/(high.key()-low.key()); // interpolation factor 0..1 + switch (mColorInterpolation) { - case ciRGB: { - if( useAlpha ) + case ciRGB: { - const int alpha = int( ( 1 - t ) * low.value().alpha() + t * high.value().alpha() ); - const double alphaPremultiplier = alpha / 255.0; // since we use QImage::Format_ARGB32_Premultiplied - mColorBuffer[i] = qRgba( int( ( ( 1 - t ) * low.value().red() + t * high.value().red() ) * alphaPremultiplier ), - int( ( ( 1 - t ) * low.value().green() + t * high.value().green() ) * alphaPremultiplier ), - int( ( ( 1 - t ) * low.value().blue() + t * high.value().blue() ) * alphaPremultiplier ), - alpha ); + if (useAlpha) + { + const int alpha = int((1-t)*low.value().alpha() + t*high.value().alpha()); + const double alphaPremultiplier = alpha/255.0; // since we use QImage::Format_ARGB32_Premultiplied + mColorBuffer[i] = qRgba(int( ((1-t)*low.value().red() + t*high.value().red())*alphaPremultiplier ), + int( ((1-t)*low.value().green() + t*high.value().green())*alphaPremultiplier ), + int( ((1-t)*low.value().blue() + t*high.value().blue())*alphaPremultiplier ), + alpha); + } else + { + mColorBuffer[i] = qRgb(int( ((1-t)*low.value().red() + t*high.value().red()) ), + int( ((1-t)*low.value().green() + t*high.value().green()) ), + int( ((1-t)*low.value().blue() + t*high.value().blue())) ); + } + break; } - else + case ciHSV: { - mColorBuffer[i] = qRgb( int( ( ( 1 - t ) * low.value().red() + t * high.value().red() ) ), - int( ( ( 1 - t ) * low.value().green() + t * high.value().green() ) ), - int( ( ( 1 - t ) * low.value().blue() + t * high.value().blue() ) ) ); + 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 double alpha = (1-t)*lowHsv.alphaF() + t*highHsv.alphaF(); + mColorBuffer[i] = qRgba(int(qRed(rgb)*alpha), int(qGreen(rgb)*alpha), int(qBlue(rgb)*alpha), int(255*alpha)); + } + else + { + mColorBuffer[i] = QColor::fromHsvF(hue, + (1-t)*lowHsv.saturationF() + t*highHsv.saturationF(), + (1-t)*lowHsv.valueF() + t*highHsv.valueF()).rgb(); + } + break; } - 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 double alpha = ( 1 - t ) * lowHsv.alphaF() + t * highHsv.alphaF(); - mColorBuffer[i] = qRgba( int( qRed( rgb ) * alpha ), int( qGreen( rgb ) * alpha ), int( qBlue( rgb ) * alpha ), int( 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 double alpha = mColorStops.constBegin().value().alphaF(); - mColorBuffer.fill( qRgba( int( qRed( rgb ) * alpha ), int( qGreen( rgb ) * alpha ), int( qBlue( rgb ) * alpha ), int( 255 * alpha ) ) ); - } - else // mColorStops is empty, fill color buffer with black + mColorBuffer.fill(qRgba(int(qRed(rgb)*alpha), int(qGreen(rgb)*alpha), int(qBlue(rgb)*alpha), int(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' */ -/* modified 2021-03-29T02:30:44, size 12308 */ +/* modified 2022-11-06T12:45:56, size 12308 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPSelectionDecoratorBracket @@ -17316,9 +17159,16 @@ 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() @@ -17329,7 +17179,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; } @@ -17338,7 +17188,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; } @@ -17348,7 +17198,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; } @@ -17358,7 +17208,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; } @@ -17368,7 +17218,7 @@ void QCPSelectionDecoratorBracket::setBracketHeight( int height ) \see setBracketWidth, setBracketHeight */ -void QCPSelectionDecoratorBracket::setBracketStyle( QCPSelectionDecoratorBracket::BracketStyle style ) +void QCPSelectionDecoratorBracket::setBracketStyle(QCPSelectionDecoratorBracket::BracketStyle style) { mBracketStyle = style; } @@ -17380,7 +17230,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; } @@ -17393,10 +17243,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; } @@ -17413,33 +17263,38 @@ 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( QRectF( -mBracketWidth * 0.5, -mBracketHeight * 0.5, mBracketWidth, mBracketHeight ), -90 * 16, -180 * 16 * direction ); - break; - } - case bsEllipse: { - painter->drawEllipse( QRectF( -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(QRectF(-mBracketWidth*0.5, -mBracketHeight*0.5, mBracketWidth, mBracketHeight), -90*16, -180*16*direction); + break; + } + case bsEllipse: + { + painter->drawEllipse(QRectF(-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; + } } } @@ -17451,42 +17306,41 @@ void QCPSelectionDecoratorBracket::drawBracket( QCPPainter* painter, int directi \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); } } } @@ -17504,46 +17358,45 @@ void QCPSelectionDecoratorBracket::drawDecoration( QCPPainter* painter, QCPDataS \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; i < averageCount; ++i ) + for (int i=0; ikeyAxis(); - QCPAxis* valueAxis = mPlottable->valueAxis(); - if( !keyAxis || !valueAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return { 0, 0 }; - } - - if( keyAxis->orientation() == Qt::Horizontal ) - return { 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 {0, 0}; } + + if (keyAxis->orientation() == Qt::Horizontal) + return {keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex)), valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex))}; else - return { valueAxis->coordToPixel( interface1d->dataMainValue( dataIndex ) ), keyAxis->coordToPixel( interface1d->dataMainKey( dataIndex ) ) }; + return {valueAxis->coordToPixel(interface1d->dataMainValue(dataIndex)), keyAxis->coordToPixel(interface1d->dataMainKey(dataIndex))}; } /* end of 'src/selectiondecorator-bracket.cpp' */ + /* including file 'src/layoutelements/layoutelement-axisrect.cpp' */ -/* modified 2021-03-29T02:30:44, size 47193 */ +/* modified 2022-11-06T12:45:56, size 47193 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAxisRect @@ -17701,38 +17552,47 @@ QPointF QCPSelectionDecoratorBracket::getPixelCoordinates( const QCPPlottableInt 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); } } @@ -17740,9 +17600,9 @@ QCPAxisRect::~QCPAxisRect() { delete mInsetLayout; mInsetLayout = nullptr; - - foreach( QCPAxis* axis, axes() ) - removeAxis( axis ); + + foreach (QCPAxis *axis, axes()) + removeAxis(axis); } /*! @@ -17750,9 +17610,9 @@ QCPAxisRect::~QCPAxisRect() \see axis */ -int QCPAxisRect::axisCount( QCPAxis::AxisType type ) const +int QCPAxisRect::axisCount(QCPAxis::AxisType type) const { - return mAxes.value( type ).size(); + return mAxes.value(type).size(); } /*! @@ -17760,14 +17620,13 @@ int QCPAxisRect::axisCount( QCPAxis::AxisType type ) const \see axisCount, axes */ -QCPAxis* QCPAxisRect::axis( QCPAxis::AxisType type, int index ) const +QCPAxis *QCPAxisRect::axis(QCPAxis::AxisType type, int index) const { - QList 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 nullptr; @@ -17782,17 +17641,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; } @@ -17803,8 +17662,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(); @@ -17832,67 +17691,50 @@ 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 nullptr; } - 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 nullptr; } - if( axes().contains( newAxis ) ) + if (axes().contains(newAxis)) { qDebug() << Q_FUNC_INFO << "passed axis is already owned by this axis rect"; return nullptr; } } - if( !mAxes[type].isEmpty() ) // multiple axes on one side, add half-bar axis ending to additional axes with offset + if (!mAxes[type].isEmpty()) // 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; } @@ -17904,17 +17746,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; } @@ -17925,25 +17767,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; } @@ -17955,9 +17797,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 @@ -17968,21 +17810,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)); } } @@ -18005,58 +17847,58 @@ void QCPAxisRect::zoom( const QRectF& pixelRect, const QList& affected 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))); } } @@ -18072,10 +17914,10 @@ QList QCPAxisRect::plottables() const { // Note: don't append all QCPAxis::plottables() into a list, because we might get duplicate entries QList result; - foreach( QCPAbstractPlottable* plottable, mParentPlot->mPlottables ) + foreach (QCPAbstractPlottable *plottable, mParentPlot->mPlottables) { - if( plottable->keyAxis()->axisRect() == this || plottable->valueAxis()->axisRect() == this ) - result.append( plottable ); + if (plottable->keyAxis()->axisRect() == this || plottable->valueAxis()->axisRect() == this) + result.append(plottable); } return result; } @@ -18092,10 +17934,10 @@ QList QCPAxisRect::graphs() const { // Note: don't append all QCPAxis::graphs() into a list, because we might get duplicate entries QList result; - foreach( QCPGraph* graph, mParentPlot->mGraphs ) + foreach (QCPGraph *graph, mParentPlot->mGraphs) { - if( graph->keyAxis()->axisRect() == this || graph->valueAxis()->axisRect() == this ) - result.append( graph ); + if (graph->keyAxis()->axisRect() == this || graph->valueAxis()->axisRect() == this) + result.append(graph); } return result; } @@ -18110,25 +17952,25 @@ 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; - foreach( QCPAbstractItem* item, mParentPlot->mItems ) + foreach (QCPAbstractItem *item, mParentPlot->mItems) { - if( item->clipAxisRect() == this ) + if (item->clipAxisRect() == this) { - result.append( item ); + result.append(item); continue; } - foreach( QCPItemPosition* position, item->positions() ) + foreach (QCPItemPosition *position, item->positions()) { - if( position->axisRect() == this || + if (position->axisRect() == this || position->keyAxis()->axisRect() == this || - position->valueAxis()->axisRect() == this ) + position->valueAxis()->axisRect() == this) { - result.append( item ); + result.append(item); break; } } @@ -18146,52 +17988,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: { - foreach( QCPAxis* axis, axes() ) - axis->setupTickVectors(); - break; + case upPreparation: + { + foreach (QCPAxis *axis, axes()) + axis->setupTickVectors(); + break; + } + case upLayout: + { + mInsetLayout->setOuterRect(rect()); + break; + } + default: 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); } /*! @@ -18209,7 +18052,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(); @@ -18228,7 +18071,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; } @@ -18240,7 +18083,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(); @@ -18258,7 +18101,7 @@ void QCPAxisRect::setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatio \see setBackground, setBackgroundScaledMode */ -void QCPAxisRect::setBackgroundScaled( bool scaled ) +void QCPAxisRect::setBackgroundScaled(bool scaled) { mBackgroundScaled = scaled; } @@ -18268,7 +18111,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; } @@ -18279,9 +18122,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() ? nullptr : mRangeDragHorzAxis.first().data(); else return mRangeDragVertAxis.isEmpty() ? nullptr : mRangeDragVertAxis.first().data(); @@ -18293,9 +18136,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() ? nullptr : mRangeZoomHorzAxis.first().data(); else return mRangeZoomVertAxis.isEmpty() ? nullptr : mRangeZoomVertAxis.first().data(); @@ -18306,23 +18149,22 @@ 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) { - foreach( QPointer axis, mRangeDragHorzAxis ) + foreach (QPointer axis, mRangeDragHorzAxis) { - if( !axis.isNull() ) - result.append( axis.data() ); + if (!axis.isNull()) + result.append(axis.data()); } - } - else + } else { - foreach( QPointer axis, mRangeDragVertAxis ) + foreach (QPointer axis, mRangeDragVertAxis) { - if( !axis.isNull() ) - result.append( axis.data() ); + if (!axis.isNull()) + result.append(axis.data()); } } return result; @@ -18333,23 +18175,22 @@ QList 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) { - foreach( QPointer axis, mRangeZoomHorzAxis ) + foreach (QPointer axis, mRangeZoomHorzAxis) { - if( !axis.isNull() ) - result.append( axis.data() ); + if (!axis.isNull()) + result.append(axis.data()); } - } - else + } else { - foreach( QPointer axis, mRangeZoomVertAxis ) + foreach (QPointer axis, mRangeZoomVertAxis) { - if( !axis.isNull() ) - result.append( axis.data() ); + if (!axis.isNull()) + result.append(axis.data()); } } return result; @@ -18360,9 +18201,9 @@ QList 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); } /*! @@ -18381,7 +18222,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; } @@ -18401,7 +18242,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; } @@ -18417,14 +18258,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 @@ -18436,17 +18277,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 @@ -18455,25 +18296,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); } } @@ -18489,14 +18330,14 @@ void QCPAxisRect::setRangeDragAxes( QList horizontal, QList \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 @@ -18508,17 +18349,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 @@ -18527,25 +18368,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); } } @@ -18559,7 +18400,7 @@ void QCPAxisRect::setRangeZoomAxes( QList horizontal, QList 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; @@ -18569,7 +18410,7 @@ void QCPAxisRect::setRangeZoomFactor( double horizontalFactor, double verticalFa Sets both the horizontal and vertical zoom \a factor. */ -void QCPAxisRect::setRangeZoomFactor( double factor ) +void QCPAxisRect::setRangeZoomFactor(double factor) { mRangeZoomFactorHorz = factor; mRangeZoomFactorVert = factor; @@ -18593,27 +18434,26 @@ 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())); } } } @@ -18628,37 +18468,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; i < axesList.size(); ++i ) + + 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; ioffset() + 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.isEmpty() ) + const QList axesList = mAxes.value(QCPAxis::marginSideToAxisType(side)); + if (!axesList.isEmpty()) return axesList.last()->offset() + axesList.last()->calculateMargin(); else return 0; @@ -18676,16 +18516,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); } } @@ -18700,27 +18540,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(); - foreach( QPointer axis, mRangeDragHorzAxis ) - mDragStartHorzRange.append( axis.isNull() ? QCPRange() : axis->range() ); + foreach (QPointer axis, mRangeDragHorzAxis) + mDragStartHorzRange.append(axis.isNull() ? QCPRange() : axis->range()); mDragStartVertRange.clear(); - foreach( QPointer axis, mRangeDragVertAxis ) - mDragStartVertRange.append( axis.isNull() ? QCPRange() : axis->range() ); + foreach (QPointer axis, mRangeDragVertAxis) + mDragStartVertRange.append(axis.isNull() ? QCPRange() : axis->range()); } } } @@ -18732,75 +18572,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 < mRangeDragHorzAxis.size(); ++i ) + 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 < mRangeDragVertAxis.size(); ++i ) + 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); } } @@ -18818,43 +18658,43 @@ void QCPAxisRect::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos 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) { -#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) const double delta = event->delta(); #else const double delta = event->angleDelta().y(); #endif - -#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 ) + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QPointF pos = event->pos(); #else const QPointF pos = event->position(); #endif - + // 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 = delta / 120.0; // a single step delta is +/-120 usually - if( mRangeZoom.testFlag( Qt::Horizontal ) ) + double wheelSteps = delta/120.0; // a single step delta is +/-120 usually + if (mRangeZoom.testFlag(Qt::Horizontal)) { - factor = qPow( mRangeZoomFactorHorz, wheelSteps ); - foreach( QPointer axis, mRangeZoomHorzAxis ) + factor = qPow(mRangeZoomFactorHorz, wheelSteps); + foreach (QPointer axis, mRangeZoomHorzAxis) { - if( !axis.isNull() ) - axis->scaleRange( factor, axis->pixelToCoord( pos.x() ) ); + if (!axis.isNull()) + axis->scaleRange(factor, axis->pixelToCoord(pos.x())); } } - if( mRangeZoom.testFlag( Qt::Vertical ) ) + if (mRangeZoom.testFlag(Qt::Vertical)) { - factor = qPow( mRangeZoomFactorVert, wheelSteps ); - foreach( QPointer axis, mRangeZoomVertAxis ) + factor = qPow(mRangeZoomFactorVert, wheelSteps); + foreach (QPointer axis, mRangeZoomVertAxis) { - if( !axis.isNull() ) - axis->scaleRange( factor, axis->pixelToCoord( pos.y() ) ); + if (!axis.isNull()) + axis->scaleRange(factor, axis->pixelToCoord(pos.y())); } } mParentPlot->replot(); @@ -18863,8 +18703,9 @@ void QCPAxisRect::wheelEvent( QWheelEvent* event ) } /* end of 'src/layoutelements/layoutelement-axisrect.cpp' */ + /* including file 'src/layoutelements/layoutelement-legend.cpp' */ -/* modified 2021-03-29T02:30:44, size 31762 */ +/* modified 2022-11-06T12:45:56, size 31762 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractLegendItem @@ -18908,11 +18749,18 @@ 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)); } /*! @@ -18920,7 +18768,7 @@ QCPAbstractLegendItem::QCPAbstractLegendItem( QCPLegend* parent ) \see setTextColor, QCPLegend::setFont */ -void QCPAbstractLegendItem::setFont( const QFont& font ) +void QCPAbstractLegendItem::setFont(const QFont &font) { mFont = font; } @@ -18930,7 +18778,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; } @@ -18941,7 +18789,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; } @@ -18952,7 +18800,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; } @@ -18962,12 +18810,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); } } @@ -18979,34 +18827,33 @@ 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 ) + Q_UNUSED(details) + if (!mParentPlot) return -1; + if (onlySelectable && (!mSelectable || !mParentLegend->selectableParts().testFlag(QCPLegend::spItems))) return -1; - if( onlySelectable && ( !mSelectable || !mParentLegend->selectableParts().testFlag( QCPLegend::spItems ) ) ) - return -1; - - if( mRect.contains( pos.toPoint() ) ) - return mParentPlot->selectionTolerance() * 0.99; + + 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 */ @@ -19016,27 +18863,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; } } @@ -19076,10 +18923,11 @@ 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 @@ -19118,30 +18966,29 @@ 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())); QSize iconSize = mParentLegend->iconSize(); - QRect textRect = painter->fontMetrics().boundingRect( 0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name() ); - QRect 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() ); + QRect textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPlottable->name()); + QRect 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); } } @@ -19154,20 +19001,20 @@ void QCPPlottableLegendItem::draw( QCPPainter* painter ) */ QSize QCPPlottableLegendItem::minimumOuterSizeHint() const { - if( !mPlottable ) - return {}; - QSize result( 0, 0 ); + if (!mPlottable) return {}; + 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -19223,38 +19070,38 @@ QSize QCPPlottableLegendItem::minimumOuterSizeHint() const Note that by default, QCustomPlot already contains a legend ready to be used as \ref QCustomPlot::legend */ -QCPLegend::QCPLegend() - : mIconTextPadding{} +QCPLegend::QCPLegend() : + mIconTextPadding{} { - 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 */ @@ -19262,15 +19109,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; i < itemCount(); ++i ) + 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; @@ -19279,7 +19126,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; } @@ -19287,7 +19134,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; } @@ -19301,13 +19148,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; i < itemCount(); ++i ) + for (int i=0; isetFont( mFont ); + if (item(i)) + item(i)->setFont(mFont); } } @@ -19320,13 +19167,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; i < itemCount(); ++i ) + for (int i=0; isetTextColor( color ); + if (item(i)) + item(i)->setTextColor(color); } } @@ -19334,17 +19181,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); } /*! @@ -19352,7 +19199,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; } @@ -19363,7 +19210,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; } @@ -19378,12 +19225,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); } } @@ -19408,28 +19255,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; i < itemCount(); ++i ) + for (int i=0; isetSelected( false ); + if (item(i)) + item(i)->setSelected(false); } } mSelectedParts = newSelected; - emit selectionChanged( mSelectedParts ); + emit selectionChanged(mSelectedParts); } } @@ -19439,7 +19286,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; } @@ -19449,7 +19296,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; } @@ -19460,7 +19307,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; } @@ -19472,13 +19319,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; i < itemCount(); ++i ) + for (int i=0; isetSelectedFont( font ); + if (item(i)) + item(i)->setSelectedFont(font); } } @@ -19489,13 +19336,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; i < itemCount(); ++i ) + for (int i=0; isetSelectedTextColor( color ); + if (item(i)) + item(i)->setSelectedTextColor(color); } } @@ -19507,9 +19354,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)); } /*! @@ -19518,13 +19365,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 < itemCount(); ++i ) + for (int i=0; i( item( i ) ) ) + if (QCPPlottableLegendItem *pli = qobject_cast(item(i))) { - if( pli->plottable() == plottable ) + if (pli->plottable() == plottable) return pli; } } @@ -19551,12 +19398,12 @@ int QCPLegend::itemCount() const \see hasItemWithPlottable */ -bool QCPLegend::hasItem( QCPAbstractLegendItem* item ) const +bool QCPLegend::hasItem(QCPAbstractLegendItem *item) const { - for( int i = 0; i < itemCount(); ++i ) + for (int i=0; iitem( i ) ) - return true; + if (item == this->item(i)) + return true; } return false; } @@ -19567,9 +19414,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); } /*! @@ -19582,9 +19429,9 @@ bool QCPLegend::hasItemWithPlottable( const QCPAbstractPlottable* plottable ) co \see removeItem, item, hasItem */ -bool QCPLegend::addItem( QCPAbstractLegendItem* item ) +bool QCPLegend::addItem(QCPAbstractLegendItem *item) { - return addElement( item ); + return addElement(item); } /*! \overload @@ -19600,16 +19447,15 @@ 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; } @@ -19625,11 +19471,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; } @@ -19638,12 +19484,12 @@ bool QCPLegend::removeItem( QCPAbstractLegendItem* item ) */ void QCPLegend::clearItems() { - for( int i = elementCount() - 1; i >= 0; --i ) + for (int i=elementCount()-1; i>=0; --i) { - if( item( i ) ) - removeAt( i ); // don't use removeItem() because it would unnecessarily reorder the whole legend for each item + if (item(i)) + removeAt(i); // don't use removeItem() because it would unnecessarily reorder the whole legend for each item } - setFillOrder( fillOrder(), true ); // get rid of empty cells by reordering once after all items are removed + setFillOrder(fillOrder(), true); // get rid of empty cells by reordering once after all items are removed } /*! @@ -19652,15 +19498,15 @@ void QCPLegend::clearItems() \see QCPAbstractLegendItem::setSelected, setSelectable */ -QList QCPLegend::selectedItems() const +QList QCPLegend::selectedItems() const { QList result; - for( int i = 0; i < itemCount(); ++i ) + for (int i=0; iselected() ) - result.append( ali ); + if (ali->selected()) + result.append(ali); } } return result; @@ -19681,9 +19527,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 @@ -19693,7 +19539,7 @@ void QCPLegend::applyDefaultAntialiasingHint( QCPPainter* painter ) const */ QPen QCPLegend::getBorderPen() const { - return mSelectedParts.testFlag( spLegendBox ) ? mSelectedBorderPen : mBorderPen; + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBorderPen : mBorderPen; } /*! \internal @@ -19703,7 +19549,7 @@ QPen QCPLegend::getBorderPen() const */ QBrush QCPLegend::getBrush() const { - return mSelectedParts.testFlag( spLegendBox ) ? mSelectedBrush : mBrush; + return mSelectedParts.testFlag(spLegendBox) ? mSelectedBrush : mBrush; } /*! \internal @@ -19711,54 +19557,52 @@ 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 ) + if (!mParentPlot) return -1; + if (onlySelectable && !mSelectableParts.testFlag(spLegendBox)) return -1; - if( onlySelectable && !mSelectableParts.testFlag( spLegendBox ) ) - return -1; - - if( mOuterRect.contains( pos.toPoint() ) ) + + 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; } } @@ -19776,15 +19620,16 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 12925 */ +/* modified 2022-11-06T12:45:56, size 12925 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPTextElement @@ -19831,21 +19676,23 @@ 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 ), 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), + 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 @@ -19854,21 +19701,23 @@ 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 ), 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), + 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 @@ -19877,24 +19726,26 @@ 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 ), mFont( QFont( QLatin1String( "sans serif" ), int( pointSize ) ) ), // will be taken from parentPlot if available, see below - mTextColor( Qt::black ) - , mSelectedFont( QFont( QLatin1String( "sans serif" ), int( 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), + mFont(QFont(QLatin1String("sans serif"), int(pointSize))), // will be taken from parentPlot if available, see below + mTextColor(Qt::black), + mSelectedFont(QFont(QLatin1String("sans serif"), int(pointSize))), // will be taken from parentPlot if available, see below + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) { - mFont.setPointSizeF( pointSize ); // set here again as floating point, because constructor above only takes integer - if( parentPlot ) + mFont.setPointSizeF(pointSize); // set here again as floating point, because constructor above only takes integer + 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 @@ -19903,11 +19754,19 @@ QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, do 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 ), mFont( QFont( fontFamily, int( pointSize ) ) ), mTextColor( Qt::black ), mSelectedFont( QFont( fontFamily, int( 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), + mFont(QFont(fontFamily, int(pointSize))), + mTextColor(Qt::black), + mSelectedFont(QFont(fontFamily, int(pointSize))), + mSelectedTextColor(Qt::blue), + mSelectable(false), + mSelected(false) { - mFont.setPointSizeF( pointSize ); // set here again as floating point, because constructor above only takes integer - setMargins( QMargins( 2, 2, 2, 2 ) ); + mFont.setPointSizeF(pointSize); // set here again as floating point, because constructor above only takes integer + setMargins(QMargins(2, 2, 2, 2)); } /*! \overload @@ -19916,10 +19775,18 @@ QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, co 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 ), 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), + 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)); } /*! @@ -19927,7 +19794,7 @@ QCPTextElement::QCPTextElement( QCustomPlot* parentPlot, const QString& text, co \see setFont, setTextColor, setTextFlags */ -void QCPTextElement::setText( const QString& text ) +void QCPTextElement::setText(const QString &text) { mText = text; } @@ -19952,7 +19819,7 @@ void QCPTextElement::setText( const QString& text ) - Qt::TextWordWrap - Qt::TextIncludeTrailingSpaces */ -void QCPTextElement::setTextFlags( int flags ) +void QCPTextElement::setTextFlags(int flags) { mTextFlags = flags; } @@ -19962,7 +19829,7 @@ void QCPTextElement::setTextFlags( int flags ) \see setTextColor, setSelectedFont */ -void QCPTextElement::setFont( const QFont& font ) +void QCPTextElement::setFont(const QFont &font) { mFont = font; } @@ -19972,7 +19839,7 @@ void QCPTextElement::setFont( const QFont& font ) \see setFont, setSelectedTextColor */ -void QCPTextElement::setTextColor( const QColor& color ) +void QCPTextElement::setTextColor(const QColor &color) { mTextColor = color; } @@ -19982,7 +19849,7 @@ void QCPTextElement::setTextColor( const QColor& color ) \see setFont */ -void QCPTextElement::setSelectedFont( const QFont& font ) +void QCPTextElement::setSelectedFont(const QFont &font) { mSelectedFont = font; } @@ -19992,7 +19859,7 @@ void QCPTextElement::setSelectedFont( const QFont& font ) \see setTextColor */ -void QCPTextElement::setSelectedTextColor( const QColor& color ) +void QCPTextElement::setSelectedTextColor(const QColor &color) { mSelectedTextColor = color; } @@ -20003,12 +19870,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); } } @@ -20019,71 +19886,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, mTextFlags, mText, &mTextBoundingRect ); + painter->setFont(mainFont()); + painter->setPen(QPen(mainTextColor())); + painter->drawText(mRect, mTextFlags, mText, &mTextBoundingRect); } /* inherits documentation from base class */ QSize QCPTextElement::minimumOuterSizeHint() const { - QFontMetrics metrics( mFont ); - QSize result( metrics.boundingRect( 0, 0, 0, 0, Qt::TextDontClip, 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::TextDontClip, 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::TextDontClip, mText ).size() ); - result.setWidth( QWIDGETSIZE_MAX ); - result.rheight() += mMargins.top() + mMargins.bottom(); + QFontMetrics metrics(mFont); + QSize result(metrics.boundingRect(0, 0, 0, 0, Qt::TextDontClip, 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; } } @@ -20098,14 +19965,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; } @@ -20116,9 +19983,9 @@ double QCPTextElement::selectTest( const QPointF& pos, bool onlySelectable, QVar \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(); } @@ -20128,10 +19995,10 @@ void QCPTextElement::mousePressEvent( QMouseEvent* event, const QVariant& detail \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); } /*! @@ -20139,10 +20006,10 @@ void QCPTextElement::mouseReleaseEvent( QMouseEvent* event, const QPointF& start \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 @@ -20166,8 +20033,10 @@ QColor QCPTextElement::mainTextColor() const } /* end of 'src/layoutelements/layoutelement-textelement.cpp' */ + /* including file 'src/layoutelements/layoutelement-colorscale.cpp' */ -/* modified 2021-03-29T02:30:44, size 26531 */ +/* modified 2022-11-06T12:45:56, size 26531 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorScale @@ -20255,16 +20124,17 @@ 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 ) - , mGradient( QCPColorGradient::gpCold ) - , 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), + mGradient(QCPColorGradient::gpCold), + 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() @@ -20275,41 +20145,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); } /*! @@ -20319,48 +20189,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 = !mColorAxis.isNull(); - 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))); } const 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()); } } @@ -20373,14 +20243,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); } } @@ -20403,16 +20273,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); } } @@ -20423,14 +20293,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); } } @@ -20438,22 +20308,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; } @@ -20464,24 +20334,23 @@ 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 ) + + if (enabled) { - mAxisRect.data()->setRangeDrag( QCPAxis::orientation( mType ) ); - } - else + mAxisRect.data()->setRangeDrag(QCPAxis::orientation(mType)); + } else { -#if QT_VERSION < QT_VERSION_CHECK( 5, 2, 0 ) - mAxisRect.data()->setRangeDrag( nullptr ); +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + mAxisRect.data()->setRangeDrag(nullptr); #else - mAxisRect.data()->setRangeDrag( {} ); + mAxisRect.data()->setRangeDrag({}); #endif } } @@ -20492,24 +20361,23 @@ 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 ) + + if (enabled) { - mAxisRect.data()->setRangeZoom( QCPAxis::orientation( mType ) ); - } - else + mAxisRect.data()->setRangeZoom(QCPAxis::orientation(mType)); + } else { -#if QT_VERSION < QT_VERSION_CHECK( 5, 2, 0 ) - mAxisRect.data()->setRangeDrag( nullptr ); +#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) + mAxisRect.data()->setRangeDrag(nullptr); #else - mAxisRect.data()->setRangeZoom( {} ); + mAxisRect.data()->setRangeZoom({}); #endif } } @@ -20520,11 +20388,11 @@ void QCPColorScale::setRangeZoom( bool enabled ) QList QCPColorScale::colorMaps() const { QList result; - for( int i = 0; i < mParentPlot->plottableCount(); ++i ) + for (int i=0; iplottableCount(); ++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; } @@ -20535,151 +20403,149 @@ 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 ); - foreach( QCPColorMap* map, maps ) + if (mDataScaleType == QCPAxis::stLogarithmic) + sign = (mDataRange.upper < 0 ? QCP::sdNegative : QCP::sdPositive); + foreach (QCPColorMap *map, maps) { - if( !map->realVisibility() && onlyVisibleMaps ) + if (!map->realVisibility() && onlyVisibleMaps) continue; QCPRange mapRange; - if( map->colorScale() == this ) + if (map->colorScale() == this) { bool currentFoundRange = true; mapRange = map->data()->dataBounds(); - if( sign == QCP::sdPositive ) + 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 ) + 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) currentFoundRange = false; } - else if( sign == QCP::sdNegative ) + if (currentFoundRange) { - 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 ) + 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: { - if( mType == QCPAxis::atBottom || mType == QCPAxis::atTop ) + case upMargins: { - setMaximumSize( QWIDGETSIZE_MAX, mBarWidth + mAxisRect.data()->margins().top() + mAxisRect.data()->margins().bottom() ); - setMinimumSize( 0, mBarWidth + mAxisRect.data()->margins().top() + mAxisRect.data()->margins().bottom() ); + 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; } - else + case upLayout: { - setMaximumSize( mBarWidth + mAxisRect.data()->margins().left() + mAxisRect.data()->margins().right(), QWIDGETSIZE_MAX ); - setMinimumSize( mBarWidth + mAxisRect.data()->margins().left() + mAxisRect.data()->margins().right(), 0 ); + mAxisRect.data()->setOuterRect(rect()); + break; } - break; - } - case upLayout: { - mAxisRect.data()->setOuterRect( rect() ); - break; - } - default: - 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); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -20696,38 +20562,41 @@ 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)); const 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 @@ -20737,21 +20606,21 @@ QCPColorScaleAxisRectPrivate::QCPColorScaleAxisRectPrivate( QCPColorScale* paren \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 @@ -20761,37 +20630,36 @@ 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 < n; ++i ) + QVector data(n); + for (int i=0; imType == 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 < h; ++y ) - pixels.append( reinterpret_cast( 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(), size_t( n ) * sizeof( QRgb ) ); - } - else + 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 ) ); - const QRgb lineColor = mParentColorScale->mGradient.color( data[h - 1 - y], QCPRange( 0, n - 1 ) ); - for( int x = 0; x < w; ++x ) + QRgb *pixels = reinterpret_cast(mGradientImage.scanLine(y)); + const QRgb lineColor = mParentColorScale->mGradient.color(data[h-1-y], QCPRange(0, n-1)); + for (int x=0; x 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); } } } @@ -20828,29 +20696,30 @@ void QCPColorScaleAxisRectPrivate::axisSelectionChanged( QCPAxis::SelectablePart 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: const 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' */ -/* modified 2021-03-29T02:30:44, size 74518 */ +/* modified 2022-11-06T12:45:57, size 74926 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPGraphData @@ -20926,19 +20795,22 @@ void QCPColorScaleAxisRectPrivate::axisSelectableChanged( QCPAxis::SelectablePar /*! 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -21004,19 +20876,22 @@ 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 ), mLineStyle{}, mScatterSkip{}, mAdaptiveSampling{} +QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mLineStyle{}, + mScatterSkip{}, + mAdaptiveSampling{} { // 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( nullptr ); - setAdaptiveSampling( true ); + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + + setLineStyle(lsLine); + setScatterSkip(0); + setChannelFillGraph(nullptr); + setAdaptiveSampling(true); } QCPGraph::~QCPGraph() @@ -21038,7 +20913,7 @@ QCPGraph::~QCPGraph() \see addData */ -void QCPGraph::setData( QSharedPointer data ) +void QCPGraph::setData(QSharedPointer data) { mDataContainer = data; } @@ -21054,10 +20929,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); } /*! @@ -21066,7 +20941,7 @@ void QCPGraph::setData( const QVector& keys, const QVector& valu \see setScatterStyle */ -void QCPGraph::setLineStyle( LineStyle ls ) +void QCPGraph::setLineStyle(LineStyle ls) { mLineStyle = ls; } @@ -21077,7 +20952,7 @@ void QCPGraph::setLineStyle( LineStyle ls ) \see QCPScatterStyle, setLineStyle */ -void QCPGraph::setScatterStyle( const QCPScatterStyle& style ) +void QCPGraph::setScatterStyle(const QCPScatterStyle &style) { mScatterStyle = style; } @@ -21093,9 +20968,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); } /*! @@ -21107,23 +20982,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 = nullptr; 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 = nullptr; return; } - + mChannelFillGraph = targetGraph; } @@ -21158,7 +21033,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; } @@ -21175,23 +21050,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 @@ -21201,9 +21076,9 @@ void QCPGraph::addData( const QVector& keys, const QVector& valu 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)); } /*! @@ -21214,147 +21089,138 @@ 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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance( pos, closestDataPoint ); - if( details ) + double result = pointDistance(pos, closestDataPoint); + if (details) { - int pointIndex = int( closestDataPoint - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int(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 < allSegments.size(); ++i ) + 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()); } } } @@ -21379,45 +21245,32 @@ 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 (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()); - 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 ) + 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; } } @@ -21433,53 +21286,46 @@ 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; i < data.size(); ++i ) + 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; i < data.size(); ++i ) + 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)); } } } @@ -21495,34 +21341,29 @@ void QCPGraph::getScatters( QVector* scatters, const QCPDataRange& data \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; - } - - result.resize( data.size() ); + 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()); + // transform data points to pixels: - if( keyAxis->orientation() == Qt::Vertical ) + if (keyAxis->orientation() == Qt::Vertical) { - for( int i = 0; i < data.size(); ++i ) + 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; i < data.size(); ++i ) + 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; @@ -21538,44 +21379,39 @@ QVector QCPGraph::dataToLines( const QVector& data ) cons \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; i < data.size(); ++i ) + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel( 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; i < data.size(); ++i ) + double lastValue = valueAxis->coordToPixel(data.first().value); + for (int i=0; icoordToPixel( 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; @@ -21591,44 +21427,39 @@ QVector QCPGraph::dataToStepLeftLines( const QVector& dat \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; i < data.size(); ++i ) + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel( 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; i < data.size(); ++i ) + double lastKey = keyAxis->coordToPixel(data.first().key); + for (int i=0; icoordToPixel( 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; @@ -21644,57 +21475,52 @@ QVector QCPGraph::dataToStepRightLines( const QVector& da \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; i < data.size(); ++i ) + 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.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; i < data.size(); ++i ) + 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.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; } @@ -21709,40 +21535,51 @@ QVector QCPGraph::dataToStepCenterLines( const QVector& d \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; i < data.size(); ++i ) + 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 QCPGraphData ¤t = data.at(i); + if (!qIsNaN(current.value)) + { + const double key = keyAxis->coordToPixel(current.key); + result[i*2+0].setX(valueAxis->coordToPixel(0)); + result[i*2+0].setY(key); + result[i*2+1].setX(valueAxis->coordToPixel(current.value)); + result[i*2+1].setY(key); + } else + { + result[i*2+0] = QPointF(0, 0); + result[i*2+1] = QPointF(0, 0); + } } - } - else // key axis is horizontal + } else // key axis is horizontal { - for( int i = 0; i < data.size(); ++i ) + 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 QCPGraphData ¤t = data.at(i); + if (!qIsNaN(current.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)); + } else + { + result[i*2+0] = QPointF(0, 0); + result[i*2+1] = QPointF(0, 0); + } } } return result; @@ -21765,32 +21602,29 @@ 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 ); - const 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); + const QVector segments = getNonNanSegments(lines, keyAxis()->orientation()); + if (!mChannelFillGraph) { // draw base fill under graph, fill goes all the way to the zero-value-line: - foreach( QCPDataRange segment, segments ) - painter->drawPolygon( getFillPolygon( lines, segment ) ); - } - else + foreach (QCPDataRange segment, segments) + painter->drawPolygon(getFillPolygon(lines, segment)); + } 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; i < segmentPairs.size(); ++i ) - painter->drawPolygon( 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; idrawPolygon(getChannelFillPolygon(lines, segmentPairs.at(i).first, &otherLines, segmentPairs.at(i).second)); } } } @@ -21802,12 +21636,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 ); - foreach( const QPointF& scatter, scatters ) - style.drawShape( painter, scatter.x(), scatter.y() ); + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + foreach (const QPointF &scatter, scatters) + style.drawShape(painter, scatter.x(), scatter.y()); } /*! \internal @@ -21816,12 +21650,12 @@ void QCPGraph::drawScatterPlot( QCPPainter* painter, const QVector& sca \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); } } @@ -21833,17 +21667,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); } } @@ -21859,92 +21693,83 @@ void QCPGraph::drawImpulsePlot( QCPPainter* painter, const QVector& lin \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 = int( end - begin ); + 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 = int(end-begin); int maxCount = (std::numeric_limits::max)(); - if( mAdaptiveSampling ) + 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 = int( 2 * keyPixelSpan + 2 ); + double keyPixelSpan = qAbs(keyAxis->coordToPixel(begin->key)-keyAxis->coordToPixel((end-1)->key)); + if (2*keyPixelSpan+2 < static_cast((std::numeric_limits::max)())) + maxCount = int(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 { 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()); } } @@ -21960,61 +21785,55 @@ void QCPGraph::getOptimizedLineData( QVector* lineData, const QCPG \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 = int( begin - mDataContainer->constBegin() ); - int endIndex = int( end - mDataContainer->constBegin() ); - while( doScatterSkip && begin != end && beginIndex % scatterModulo != 0 ) // advance begin iterator to first non-skipped scatter + int beginIndex = int(begin-mDataContainer->constBegin()); + int endIndex = int(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 = int( end - begin ); + if (begin == end) return; + int dataCount = int(end-begin); int maxCount = (std::numeric_limits::max)(); - if( mAdaptiveSampling ) + if (mAdaptiveSampling) { - int keyPixelSpan = int( qAbs( keyAxis->coordToPixel( begin->key ) - keyAxis->coordToPixel( ( end - 1 )->key ) ) ); - maxCount = 2 * keyPixelSpan + 2; + int keyPixelSpan = int(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; QCPGraphDataContainer::const_iterator it = begin; - int itIndex = int( beginIndex ); + int itIndex = int(beginIndex); double minValue = it->value; double maxValue = it->value; 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 { @@ -22023,59 +21842,56 @@ void QCPGraph::getOptimizedScatterData( QVector* scatterData, QCPG } } // 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 { @@ -22085,25 +21901,25 @@ void QCPGraph::getOptimizedScatterData( QVector* scatterData, QCPG } } // 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 = int( intervalIt - mDataContainer->constBegin() ); + int intervalItIndex = int(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 { @@ -22112,25 +21928,24 @@ void QCPGraph::getOptimizedScatterData( QVector* scatterData, QCPG } } } - } - 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 { @@ -22151,27 +21966,22 @@ void QCPGraph::getOptimizedScatterData( QVector* scatterData, QCPG 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 } } @@ -22186,42 +21996,41 @@ void QCPGraph::getVisibleDataBounds( QCPGraphDataContainer::const_iterator& begi \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; @@ -22245,53 +22054,52 @@ QVector QCPGraph::getNonNanSegments( const QVector* lineD \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()).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()).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; } @@ -22309,26 +22117,24 @@ QVector > QCPGraph::getOverlappingSegments( QV \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; } } @@ -22344,51 +22150,44 @@ bool QCPGraph::segmentsIntersect( double aLower, double aUpper, double bLower, d 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 {}; - } - + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return {}; } + QPointF result; - if( valueAxis->scaleType() == QCPAxis::stLinear ) + if (valueAxis->scaleType() == QCPAxis::stLinear) { - if( keyAxis->orientation() == Qt::Horizontal ) + if (keyAxis->orientation() == Qt::Horizontal) { - result.setX( matchingDataPoint.x() ); - result.setY( valueAxis->coordToPixel( 0 ) ); - } - else // keyAxis->orientation() == Qt::Vertical + 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(valueAxis->coordToPixel(0)); + result.setY(matchingDataPoint.y()); } - } - else // valueAxis->mScaleType == QCPAxis::stLogarithmic + } 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; @@ -22410,16 +22209,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; } @@ -22441,121 +22240,103 @@ const QPolygonF QCPGraph::getFillPolygon( const QVector* lineData, QCPD \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 @@ -22566,16 +22347,16 @@ const QPolygonF QCPGraph::getChannelFillPolygon( const QVector* thisDat 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( i < data->size() - 1 ) - return i + 1; + if (isize()-1) + return i+1; else - return data->size() - 1; + return data->size()-1; } } return -1; @@ -22589,14 +22370,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; i < data->size(); ++i ) + for (int i=0; isize(); ++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; } @@ -22612,16 +22393,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( i < data->size() - 1 ) - return i + 1; + if (isize()-1) + return i+1; else - return data->size() - 1; + return data->size()-1; } } return -1; @@ -22638,52 +22419,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)(); // 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() ) ); // don't limit data range further since with sharp data spikes, line segments may be closer to test point than segments with closer key coordinate - 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 < lineData.size() - 1; i += step ) + getLines(&lineData, QCPDataRange(0, dataCount())); // don't limit data range further since with sharp data spikes, line segments may be closer to test point than segments with closer key coordinate + 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; i < data->size(); ++i ) + for (int i=0; isize(); ++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; } @@ -22710,8 +22491,9 @@ int QCPGraph::findIndexBelowY( const QVector* data, double y ) const } /* end of 'src/plottables/plottable-graph.cpp' */ + /* including file 'src/plottables/plottable-curve.cpp' */ -/* modified 2021-03-29T02:30:44, size 63851 */ +/* modified 2022-11-06T12:45:56, size 63851 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPCurveData @@ -22789,19 +22571,24 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -22863,16 +22650,18 @@ 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 ), mScatterSkip{}, mLineStyle{} +QCPCurve::QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mScatterSkip{}, + mLineStyle{} { // 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() @@ -22894,7 +22683,7 @@ QCPCurve::~QCPCurve() \see addData */ -void QCPCurve::setData( QSharedPointer data ) +void QCPCurve::setData(QSharedPointer data) { mDataContainer = data; } @@ -22910,12 +22699,13 @@ 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 @@ -22927,10 +22717,10 @@ void QCPCurve::setData( const QVector& t, const QVector& keys, c \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); } /*! @@ -22940,7 +22730,7 @@ void QCPCurve::setData( const QVector& keys, const QVector& valu \see QCPScatterStyle, setLineStyle */ -void QCPCurve::setScatterStyle( const QCPScatterStyle& style ) +void QCPCurve::setScatterStyle(const QCPScatterStyle &style) { mScatterStyle = style; } @@ -22956,9 +22746,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); } /*! @@ -22968,7 +22758,7 @@ void QCPCurve::setScatterSkip( int skip ) \see setScatterStyle */ -void QCPCurve::setLineStyle( QCPCurve::LineStyle style ) +void QCPCurve::setLineStyle(QCPCurve::LineStyle style) { mLineStyle = style; } @@ -22985,16 +22775,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]; @@ -23002,7 +22792,7 @@ void QCPCurve::addData( const QVector& t, const QVector& keys, c ++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 @@ -23017,21 +22807,21 @@ void QCPCurve::addData( const QVector& t, const QVector& keys, c 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]; @@ -23039,7 +22829,7 @@ void QCPCurve::addData( const QVector& keys, const QVector& valu ++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 @@ -23048,9 +22838,9 @@ void QCPCurve::addData( const QVector& keys, const QVector& valu 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 @@ -23063,12 +22853,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)); } /*! @@ -23079,142 +22869,138 @@ 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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { QCPCurveDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance( pos, closestDataPoint ); - if( details ) + double result = pointDistance(pos, closestDataPoint); + if (details) { - int pointIndex = int( closestDataPoint - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int( 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 < allSegments.size(); ++i ) + 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()); } } } @@ -23225,12 +23011,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); } } @@ -23241,14 +23027,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 ); - foreach( const QPointF& point, points ) - if( !qIsNaN( point.x() ) && !qIsNaN( point.y() ) ) - style.drawShape( painter, point ); + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + foreach (const QPointF &point, points) + if (!qIsNaN(point.x()) && !qIsNaN(point.y())) + style.drawShape(painter, point); } /*! \internal @@ -23279,89 +23065,78 @@ void QCPCurve::drawScatterPlot( QCPPainter* painter, const QVector& poi \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 + } else { - lines->append( crossB ); + lines->append(crossB); *lines << afterTraverseCornerPoints; - trailingPoints << beforeTraverseCornerPoints << crossA; + 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) + } 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 ); + *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 + } 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 ); + 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 ) ); + 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 + } else // region didn't change { - if( currentRegion == 5 ) // still in R, keep adding original points + 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 + 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... } @@ -23393,57 +23168,52 @@ void QCPCurve::getCurveLines( QVector* lines, const QCPDataRange& dataR \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 = int( end - mDataContainer->constBegin() ); - + int endIndex = int( 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 = int( begin - mDataContainer->constBegin() ); - while( doScatterSkip && it != end && itIndex % scatterModulo != 0 ) // advance begin iterator to first non-skipped scatter + int itIndex = int( 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 { @@ -23452,21 +23222,20 @@ void QCPCurve::getScatters( QVector* scatters, const QCPDataRange& data } } } - } - 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 { @@ -23497,31 +23266,29 @@ void QCPCurve::getScatters( QVector* scatters, const QCPDataRange& data 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; @@ -23543,101 +23310,102 @@ int QCPCurve::getRegion( double key, double value, double keyMin, double valueMa 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) + 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 { intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; } - 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) + case 3: // bottom and left edge { - intersectKeyPx = keyMinPx; - intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + 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; } - 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) + 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 { intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + intersectValuePx = otherValuePx + (valuePx-otherValuePx)/(keyPx-otherKeyPx)*(intersectKeyPx-otherKeyPx); + break; } - break; - } - 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) + case 9: // bottom and right edge { - intersectKeyPx = keyMaxPx; - intersectValuePx = otherValuePx + ( valuePx - otherValuePx ) / ( keyPx - otherKeyPx ) * ( intersectKeyPx - otherKeyPx ); + 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; } - break; } - } - if( mKeyAxis->orientation() == Qt::Horizontal ) - return { intersectKeyPx, intersectValuePx }; + if (mKeyAxis->orientation() == Qt::Horizontal) + return {intersectKeyPx, intersectValuePx}; else - return { intersectValuePx, intersectKeyPx }; + return {intersectValuePx, intersectKeyPx}; } /*! \internal @@ -23658,365 +23426,154 @@ QPointF QCPCurve::getOptimizedPoint( int otherRegion, double otherKey, double ot 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: { - switch( currentRegion ) + case 1: { - 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 + switch (currentRegion) { - 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 ); + 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; + } } break; } - } - break; - } - case 2: { - switch( currentRegion ) + case 2: { - 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 + switch (currentRegion) { - 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 ); + 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; } - } - break; - } - case 4: { - switch( currentRegion ) + case 3: { - 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 + switch (currentRegion) { - 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 ); + 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; + } } break; } - } - break; - } - case 8: { - switch( currentRegion ) + case 4: { - 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 + switch (currentRegion) { - 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 ); + 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 + { 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; } @@ -24033,105 +23590,96 @@ QVector QCPCurve::getOptimizedCornerPoints( int prevRegion, int current 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: { - switch( currentRegion ) + case 1: { - case 4: - case 7: + 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: - return false; - default: - return true; - } - } - case 2: { - switch( currentRegion ) { - case 1: - case 3: - return false; - default: - return true; + switch (currentRegion) + { + case 1: + case 2: + case 6: + case 9: 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 8: { - switch( currentRegion ) { - case 7: - case 9: - return false; - default: - return true; + switch (currentRegion) + { + case 1: + case 7: return false; + default: return true; + } } - } - case 9: { - switch( currentRegion ) - { - case 3: + case 5: return false; // should never occur case 6: - case 8: - case 7: - return false; - default: - return true; + { + switch (currentRegion) + { + case 3: + case 9: return false; + default: return true; + } } - } - 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. @@ -24145,94 +23693,91 @@ 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( keyPx - prevKeyPx ) ) // 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(keyPx-prevKeyPx)) // 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( valuePx - prevValuePx ) ) // 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(valuePx-prevValuePx)) // 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 < intersections.size() - 1; ++i ) + 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; } @@ -24261,145 +23806,87 @@ 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: { - switch( currentRegion ) + case 1: { - case 6: { - beforeTraverse << coordsToPixels( keyMin, valueMax ); + 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; } + } break; } - case 9: { - beforeTraverse << coordsToPixels( keyMin, valueMax ); - afterTraverse << coordsToPixels( keyMax, valueMin ); - break; - } - case 8: { - beforeTraverse << coordsToPixels( keyMin, valueMax ); - break; - } - } - break; - } - case 2: { - switch( currentRegion ) + case 2: { - case 7: { - afterTraverse << coordsToPixels( keyMax, valueMax ); + switch (currentRegion) + { + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } break; } - case 9: { - afterTraverse << coordsToPixels( keyMax, valueMin ); - break; - } - } - break; - } - case 3: { - switch( currentRegion ) + case 3: { - case 4: { - beforeTraverse << coordsToPixels( keyMin, valueMin ); + 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; } + } break; } - case 7: { - beforeTraverse << coordsToPixels( keyMin, valueMin ); - afterTraverse << coordsToPixels( keyMax, valueMax ); - break; - } - case 8: { - beforeTraverse << coordsToPixels( keyMin, valueMin ); - break; - } - } - break; - } - case 4: { - switch( currentRegion ) + case 4: { - case 3: { - afterTraverse << coordsToPixels( keyMin, valueMin ); + switch (currentRegion) + { + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + case 9: { afterTraverse << coordsToPixels(keyMax, valueMin); break; } + } 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 5: { break; } // shouldn't happen because this method only handles full traverses + case 6: { - case 1: { - afterTraverse << coordsToPixels( keyMin, valueMax ); + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 7: { afterTraverse << coordsToPixels(keyMax, valueMax); break; } + } break; } - case 7: { - afterTraverse << coordsToPixels( keyMax, valueMax ); - break; - } - } - break; - } - case 7: { - switch( currentRegion ) + case 7: { - case 2: { - beforeTraverse << coordsToPixels( keyMax, valueMax ); + 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 3: { - beforeTraverse << coordsToPixels( keyMax, valueMax ); - afterTraverse << coordsToPixels( keyMin, valueMin ); - break; - } - case 6: { - beforeTraverse << coordsToPixels( keyMax, valueMax ); - break; - } - } - break; - } - case 8: { - switch( currentRegion ) + case 8: { - case 1: { - afterTraverse << coordsToPixels( keyMin, valueMax ); + switch (currentRegion) + { + case 1: { afterTraverse << coordsToPixels(keyMin, valueMax); break; } + case 3: { afterTraverse << coordsToPixels(keyMin, valueMin); break; } + } break; } - case 3: { - afterTraverse << coordsToPixels( keyMin, valueMin ); - break; - } - } - break; - } - case 9: { - switch( currentRegion ) + case 9: { - case 2: { - beforeTraverse << coordsToPixels( keyMax, valueMin ); + 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; } - case 1: { - beforeTraverse << coordsToPixels( keyMax, valueMin ); - afterTraverse << coordsToPixels( keyMin, valueMax ); - break; - } - case 4: { - beforeTraverse << coordsToPixels( keyMax, valueMin ); - break; - } - } - break; - } } } @@ -24415,55 +23902,57 @@ void QCPCurve::getTraverseCornerPoints( int prevRegion, int currentRegion, doubl 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)(); // 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; i < lines.size() - 1; ++i ) + 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; i= 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 nullptr; @@ -24596,8 +24087,8 @@ QCPBars* QCPBarsGroup::bars( int index ) const void QCPBarsGroup::clear() { const QList oldBars = mBars; - foreach( QCPBars* bars, oldBars ) - bars->setBarsGroup( nullptr ); // removes itself from mBars via removeBars + foreach (QCPBars *bars, oldBars) + bars->setBarsGroup(nullptr); // removes itself from mBars via removeBars } /*! @@ -24606,18 +24097,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); } /*! @@ -24629,19 +24120,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)); } /*! @@ -24649,18 +24140,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( nullptr ); + + if (mBars.contains(bars)) + bars->setBarsGroup(nullptr); 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 @@ -24670,10 +24161,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 @@ -24683,9 +24174,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 @@ -24694,59 +24185,57 @@ 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 + 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 } - else // uneven number of bars + for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our 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 - } - 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 ); + 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; @@ -24762,27 +24251,31 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -24857,19 +24350,22 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -24944,22 +24440,27 @@ 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( nullptr ), mBaseValue( 0 ), mStackingGap( 1 ) +QCPBars::QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable1D(keyAxis, valueAxis), + mWidth(0.75), + mWidthType(wtPlotCoords), + mBarsGroup(nullptr), + mBaseValue(0), + mStackingGap(1) { // 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( nullptr ); - if( mBarBelow || mBarAbove ) - connectBars( mBarBelow.data(), mBarAbove.data() ); // take this bar out of any stacking + setBarsGroup(nullptr); + if (mBarBelow || mBarAbove) + connectBars(mBarBelow.data(), mBarAbove.data()); // take this bar out of any stacking } /*! \overload @@ -24977,7 +24478,7 @@ QCPBars::~QCPBars() \see addData */ -void QCPBars::setData( QSharedPointer data ) +void QCPBars::setData(QSharedPointer data) { mDataContainer = data; } @@ -24993,10 +24494,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); } /*! @@ -25005,7 +24506,7 @@ void QCPBars::setData( const QVector& keys, const QVector& value 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; } @@ -25018,7 +24519,7 @@ void QCPBars::setWidth( double width ) \see setWidth */ -void QCPBars::setWidthType( QCPBars::WidthType widthType ) +void QCPBars::setWidthType(QCPBars::WidthType widthType) { mWidthType = widthType; } @@ -25029,15 +24530,15 @@ void QCPBars::setWidthType( QCPBars::WidthType widthType ) To remove this QCPBars from any group, set \a barsGroup to \c nullptr. */ -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); } /*! @@ -25052,7 +24553,7 @@ void QCPBars::setBarsGroup( QCPBarsGroup* barsGroup ) The default base value is 0. */ -void QCPBars::setBaseValue( double baseValue ) +void QCPBars::setBaseValue(double baseValue) { mBaseValue = baseValue; } @@ -25062,7 +24563,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; } @@ -25079,23 +24580,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 @@ -25104,9 +24605,9 @@ void QCPBars::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 QCPBars::addData( double key, double value ) +void QCPBars::addData(double key, double value) { - mDataContainer->add( QCPBarsData( key, value ) ); + mDataContainer->add(QCPBarsData(key, value)); } /*! @@ -25123,23 +24624,22 @@ 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); } } @@ -25157,44 +24657,43 @@ 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( int( it - mDataContainer->constBegin() ), int( it - mDataContainer->constBegin() + 1 ) ), false ); + if (rect.intersects(getBarRect(it->key, it->value))) + result.addDataRange(QCPDataRange(int(it-mDataContainer->constBegin()), int(it-mDataContainer->constBegin()+1)), false); } result.simplify(); return result; @@ -25208,29 +24707,29 @@ QCPDataSelection QCPBars::selectTestRect( const QRectF& rect, bool onlySelectabl \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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { // 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 = int( it - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int(it-mDataContainer->constBegin()); + details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex+1))); } - return mParentPlot->selectionTolerance() * 0.99; + return mParentPlot->selectionTolerance()*0.99; } } } @@ -25238,7 +24737,7 @@ double QCPBars::selectTest( const QPointF& pos, bool onlySelectable, QVariant* d } /* 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 @@ -25250,95 +24749,89 @@ QCPRange QCPBars::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) 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, false ); - itEnd = mDataContainer->findEnd( inKeyRange.upper, false ); + itBegin = mDataContainer->findBegin(inKeyRange.lower, false); + itEnd = mDataContainer->findEnd(inKeyRange.upper, false); } - 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 {}; - } - - 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 { keyPixel, valuePixel }; + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return {}; } + + 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 {keyPixel, valuePixel}; else - return { valuePixel, keyPixel }; - } - else + return {valuePixel, keyPixel}; + } else { qDebug() << Q_FUNC_INFO << "Index out of bounds" << index; return {}; @@ -25346,71 +24839,64 @@ 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 < allSegments.size(); ++i ) + 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 + mSelectionDecorator->applyBrush(painter); + mSelectionDecorator->applyPen(painter); + } else { - painter->setBrush( mBrush ); - painter->setPen( mPen ); + painter->setBrush(mBrush); + painter->setPen(mPen); } - applyDefaultAntialiasingHint( painter ); - painter->drawPolygon( getBarRect( it->key, it->value ) ); + 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 @@ -25427,54 +24913,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; @@ -25487,36 +24973,31 @@ 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 {}; - } - + QCPAxis *keyAxis = mKeyAxis.data(); + QCPAxis *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return {}; } + 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(); } } @@ -25529,43 +25010,44 @@ 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: { - upper = mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); - lower = -upper; - break; - } - case wtAxisRectRatio: { - if( mKeyAxis && mKeyAxis.data()->axisRect() ) + case wtAbsolute: { - 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(); + upper = mWidth*0.5*mKeyAxis.data()->pixelOrientation(); lower = -upper; + break; } - else - qDebug() << Q_FUNC_INFO << "No key axis or axis rect defined"; - break; - } - case wtPlotCoords: { - if( mKeyAxis ) + case wtAxisRectRatio: { - 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 + 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; } - else - qDebug() << Q_FUNC_INFO << "No key axis defined"; - break; - } } } @@ -25578,31 +25060,30 @@ 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; } @@ -25614,32 +25095,29 @@ 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 = nullptr; upper->mBarBelow = nullptr; - } - 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 = nullptr; lower->mBarAbove = nullptr; - } - 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 = nullptr; // 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 = nullptr; lower->mBarAbove = upper; upper->mBarBelow = lower; @@ -25647,8 +25125,9 @@ void QCPBars::connectBars( QCPBars* lower, QCPBars* upper ) } /* end of 'src/plottables/plottable-bars.cpp' */ + /* including file 'src/plottables/plottable-statisticalbox.cpp' */ -/* modified 2021-03-29T02:30:44, size 28951 */ +/* modified 2022-11-06T12:45:57, size 28951 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPStatisticalBoxData @@ -25746,8 +25225,13 @@ 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) { } @@ -25755,11 +25239,18 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -25833,11 +25324,18 @@ 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 @@ -25856,7 +25354,7 @@ QCPStatisticalBox::QCPStatisticalBox( QCPAxis* keyAxis, QCPAxis* valueAxis ) \see addData */ -void QCPStatisticalBox::setData( QSharedPointer data ) +void QCPStatisticalBox::setData(QSharedPointer data) { mDataContainer = data; } @@ -25871,10 +25369,10 @@ void QCPStatisticalBox::setData( QSharedPointer \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); } /*! @@ -25882,7 +25380,7 @@ void QCPStatisticalBox::setData( const QVector& keys, const QVector &outliers) */ -void QCPStatisticalBox::setOutlierStyle( const QCPScatterStyle& style ) +void QCPStatisticalBox::setOutlierStyle(const QCPScatterStyle &style) { mOutlierStyle = style; } @@ -25972,18 +25470,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]; @@ -25994,7 +25492,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 @@ -26005,29 +25503,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( int( it - mDataContainer->constBegin() ), int( it - mDataContainer->constBegin() + 1 ) ), false ); + if (rect.intersects(getQuartileBox(it))) + result.addDataRange(QCPDataRange(int(it-mDataContainer->constBegin()), int(it-mDataContainer->constBegin()+1)), false); } result.simplify(); return result; @@ -26041,40 +25539,39 @@ QCPDataSelection QCPStatisticalBox::selectTestRect( const QRectF& rect, bool onl \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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { // get visible data range: QCPStatisticalBoxDataContainer::const_iterator visibleBegin, visibleEnd; QCPStatisticalBoxDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - getVisibleDataBounds( visibleBegin, visibleEnd ); + getVisibleDataBounds(visibleBegin, visibleEnd); double minDistSqr = (std::numeric_limits::max)(); - for( QCPStatisticalBoxDataContainer::const_iterator it = visibleBegin; it != visibleEnd; ++it ) + 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 ); - const QCPVector2D posVec( pos ); - foreach( const QLineF& backbone, whiskerBackbones ) + const QVector whiskerBackbones = getWhiskerBackboneLines(it); + const QCPVector2D posVec(pos); + foreach (const QLineF &backbone, whiskerBackbones) { - double currentDistSqr = posVec.distanceSquaredToLine( backbone ); - if( currentDistSqr < minDistSqr ) + double currentDistSqr = posVec.distanceSquaredToLine(backbone); + if (currentDistSqr < minDistSqr) { minDistSqr = currentDistSqr; closestDataPoint = it; @@ -26082,113 +25579,105 @@ double QCPStatisticalBox::selectTest( const QPointF& pos, bool onlySelectable, Q } } } - if( details ) + if (details) { - int pointIndex = int( closestDataPoint - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int(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 < allSegments.size(); ++i ) + 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; 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 ) +# 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) { - 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); } /*! @@ -26199,29 +25688,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; i < it->outliers.size(); ++i ) - outlierStyle.drawShape( painter, coordsToPixels( it->key, it->outliers.at( i ) ) ); + applyScattersAntialiasingHint(painter); + outlierStyle.applyTo(painter, mPen); + for (int i=0; ioutliers.size(); ++i) + outlierStyle.drawShape(painter, coordsToPixels(it->key, it->outliers.at(i))); } /*! \internal @@ -26238,17 +25727,17 @@ void QCPStatisticalBox::drawStatisticalBox( QCPPainter* painter, QCPStatisticalB 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 @@ -26258,11 +25747,11 @@ void QCPStatisticalBox::getVisibleDataBounds( QCPStatisticalBoxDataContainer::co \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; } @@ -26274,11 +25763,11 @@ QRectF QCPStatisticalBox::getQuartileBox( QCPStatisticalBoxDataContainer::const_ \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; } @@ -26289,17 +25778,18 @@ QVector QCPStatisticalBox::getWhiskerBackboneLines( QCPStatisticalBoxDat \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' */ -/* modified 2021-03-29T02:30:44, size 48149 */ +/* modified 2022-11-06T12:45:56, size 48189 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorMapData @@ -26355,11 +25845,18 @@ QVector QCPStatisticalBox::getWhiskerBarLines( QCPStatisticalBoxDataCont \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( nullptr ), mAlpha( nullptr ), 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(nullptr), + mAlpha(nullptr), + mDataModified(true) { - setSize( keySize, valueSize ); - fill( 0 ); + setSize(keySize, valueSize); + fill(0); } QCPColorMapData::~QCPColorMapData() @@ -26371,8 +25868,13 @@ QCPColorMapData::~QCPColorMapData() /*! 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( nullptr ), mAlpha( nullptr ), mDataModified( true ) +QCPColorMapData::QCPColorMapData(const QCPColorMapData &other) : + mKeySize(0), + mValueSize(0), + mIsEmpty(true), + mData(nullptr), + mAlpha(nullptr), + mDataModified(true) { *this = other; } @@ -26381,23 +25883,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] ) * size_t( keySize * valueSize ) ); - if( mAlpha ) - memcpy( mAlpha, other.mAlpha, sizeof( mAlpha[0] ) * size_t( keySize * valueSize ) ); + memcpy(mData, other.mData, sizeof(mData[0])*size_t(keySize*valueSize)); + if (mAlpha) + memcpy(mAlpha, other.mAlpha, sizeof(mAlpha[0])*size_t(keySize*valueSize)); } mDataBounds = other.mDataBounds; mDataModified = true; @@ -26406,21 +25908,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 = int( ( key - mKeyRange.lower ) / ( mKeyRange.upper - mKeyRange.lower ) * ( mKeySize - 1 ) + 0.5 ); - int valueCell = int( ( 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 = int( (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5 ); + int valueCell = int( (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; } @@ -26433,10 +25935,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; } @@ -26453,39 +25955,33 @@ 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; 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[size_t( mKeySize * mValueSize )]; + mData = new double[size_t(mKeySize*mValueSize)]; #ifdef __EXCEPTIONS - } - catch( ... ) - { - mData = nullptr; - } + } catch (...) { mData = nullptr; } #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 = nullptr; - - 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; } } @@ -26500,9 +25996,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); } /*! @@ -26515,9 +26011,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); } /*! @@ -26530,10 +26026,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); } /*! @@ -26546,7 +26042,7 @@ void QCPColorMapData::setRange( const QCPRange& keyRange, const QCPRange& valueR \see setRange, setValueRange, setSize */ -void QCPColorMapData::setKeyRange( const QCPRange& keyRange ) +void QCPColorMapData::setKeyRange(const QCPRange &keyRange) { mKeyRange = keyRange; } @@ -26561,7 +26057,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; } @@ -26578,18 +26074,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 = int( ( key - mKeyRange.lower ) / ( mKeyRange.upper - mKeyRange.lower ) * ( mKeySize - 1 ) + 0.5 ); - int valueCell = int( ( value - mValueRange.lower ) / ( mValueRange.upper - mValueRange.lower ) * ( mValueSize - 1 ) + 0.5 ); - if( keyCell >= 0 && keyCell < mKeySize && valueCell >= 0 && valueCell < mValueSize ) + int keyCell = int( (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5 ); + int valueCell = int( (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; } } @@ -26604,18 +26100,17 @@ 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; } @@ -26634,17 +26129,16 @@ 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; } @@ -26663,16 +26157,16 @@ void QCPColorMapData::setAlpha( int keyIndex, int valueIndex, unsigned char alph */ 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 < dataCount; ++i ) + double minHeight = std::numeric_limits::max(); + double maxHeight = -std::numeric_limits::max(); + 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; @@ -26687,7 +26181,7 @@ void QCPColorMapData::recalculateDataBounds() */ void QCPColorMapData::clear() { - setSize( 0, 0 ); + setSize(0, 0); } /*! @@ -26695,7 +26189,7 @@ void QCPColorMapData::clear() */ void QCPColorMapData::clearAlpha() { - if( mAlpha ) + if (mAlpha) { delete[] mAlpha; mAlpha = nullptr; @@ -26706,12 +26200,11 @@ 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 < dataCount; ++i ) - mData[i] = z; - mDataBounds = QCPRange( z, z ); + const int dataCount = mValueSize*mKeySize; + memset(mData, z, dataCount*sizeof(*mData)); + mDataBounds = QCPRange(z, z); mDataModified = true; } @@ -26724,13 +26217,12 @@ void QCPColorMapData::fill( double z ) \see setAlpha */ -void QCPColorMapData::fillAlpha( unsigned char alpha ) +void QCPColorMapData::fillAlpha(unsigned char alpha) { - if( mAlpha || createAlpha( false ) ) + if (mAlpha || createAlpha(false)) { - const int dataCount = mValueSize * mKeySize; - for( int i = 0; i < dataCount; ++i ) - mAlpha[i] = alpha; + const int dataCount = mValueSize*mKeySize; + memset(mAlpha, alpha, dataCount*sizeof(*mAlpha)); mDataModified = true; } } @@ -26752,12 +26244,12 @@ void QCPColorMapData::fillAlpha( unsigned char alpha ) \see cellToCoord, QCPAxis::coordToPixel */ -void QCPColorMapData::coordToCell( double key, double value, int* keyIndex, int* valueIndex ) const +void QCPColorMapData::coordToCell(double key, double value, int *keyIndex, int *valueIndex) const { - if( keyIndex ) - *keyIndex = int( ( key - mKeyRange.lower ) / ( mKeyRange.upper - mKeyRange.lower ) * ( mKeySize - 1 ) + 0.5 ); - if( valueIndex ) - *valueIndex = int( ( value - mValueRange.lower ) / ( mValueRange.upper - mValueRange.lower ) * ( mValueSize - 1 ) + 0.5 ); + if (keyIndex) + *keyIndex = int( (key-mKeyRange.lower)/(mKeyRange.upper-mKeyRange.lower)*(mKeySize-1)+0.5 ); + if (valueIndex) + *valueIndex = int( (value-mValueRange.lower)/(mValueRange.upper-mValueRange.lower)*(mValueSize-1)+0.5 ); } /*! @@ -26775,12 +26267,12 @@ void QCPColorMapData::coordToCell( double key, double value, int* keyIndex, int* \see coordToCell, QCPAxis::pixelToCoord */ -void QCPColorMapData::cellToCoord( int keyIndex, int valueIndex, double* key, double* value ) const +void QCPColorMapData::cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const { - if( key ) - *key = keyIndex / double( mKeySize - 1 ) * ( mKeyRange.upper - mKeyRange.lower ) + mKeyRange.lower; - if( value ) - *value = valueIndex / double( mValueSize - 1 ) * ( mValueRange.upper - mValueRange.lower ) + mValueRange.lower; + if (key) + *key = keyIndex/double(mKeySize-1)*(mKeyRange.upper-mKeyRange.lower)+mKeyRange.lower; + if (value) + *value = valueIndex/double(mValueSize-1)*(mValueRange.upper-mValueRange.lower)+mValueRange.lower; } /*! \internal @@ -26796,37 +26288,32 @@ void QCPColorMapData::cellToCoord( int keyIndex, int valueIndex, double* key, do The return value indicates the existence of the alpha map after the call. So this method returns true if the data map isn't empty and an alpha map was successfully allocated. */ -bool QCPColorMapData::createAlpha( bool initializeOpaque ) +bool QCPColorMapData::createAlpha(bool initializeOpaque) { clearAlpha(); - if( isEmpty() ) + if (isEmpty()) return false; - + #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 - mAlpha = new unsigned char[size_t( mKeySize * mValueSize )]; + mAlpha = new unsigned char[size_t(mKeySize*mValueSize)]; #ifdef __EXCEPTIONS - } - catch( ... ) - { - mAlpha = nullptr; - } + } catch (...) { mAlpha = nullptr; } #endif - if( mAlpha ) + if (mAlpha) { - if( initializeOpaque ) - fillAlpha( 255 ); + if (initializeOpaque) + fillAlpha(255); return true; - } - else + } else { - qDebug() << Q_FUNC_INFO << "out of memory for data dimensions " << mKeySize << "*" << mValueSize; + qDebug() << Q_FUNC_INFO << "out of memory for data dimensions "<< mKeySize << "*" << mValueSize; return false; } } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPColorMap //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -26951,8 +26438,14 @@ bool QCPColorMapData::createAlpha( bool initializeOpaque ) \a keyAxis. This QCustomPlot instance takes ownership of the QCPColorMap, so do not delete it manually but use QCustomPlot::removePlottable() instead. */ -QCPColorMap::QCPColorMap( QCPAxis* keyAxis, QCPAxis* valueAxis ) - : QCPAbstractPlottable( keyAxis, valueAxis ), mDataScaleType( QCPAxis::stLinear ), mMapData( new QCPColorMapData( 10, 10, QCPRange( 0, 5 ), QCPRange( 0, 5 ) ) ), mGradient( QCPColorGradient::gpCold ), mInterpolate( true ), mTightBoundary( false ), mMapImageInvalidated( true ) +QCPColorMap::QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis) : + QCPAbstractPlottable(keyAxis, valueAxis), + mDataScaleType(QCPAxis::stLinear), + mMapData(new QCPColorMapData(10, 10, QCPRange(0, 5), QCPRange(0, 5))), + mGradient(QCPColorGradient::gpCold), + mInterpolate(true), + mTightBoundary(false), + mMapImageInvalidated(true) { } @@ -26968,18 +26461,17 @@ QCPColorMap::~QCPColorMap() takes ownership of the passed data and replaces the internal data pointer with it. This is significantly faster than copying for large datasets. */ -void QCPColorMap::setData( QCPColorMapData* data, bool copy ) +void QCPColorMap::setData(QCPColorMapData *data, bool copy) { - if( mMapData == data ) + if (mMapData == data) { - qDebug() << Q_FUNC_INFO << "The data pointer is already in (and owned by) this plottable" << reinterpret_cast( 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; @@ -26995,18 +26487,17 @@ 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); } } @@ -27015,15 +26506,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()); } } @@ -27038,13 +26529,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); } } @@ -27054,10 +26545,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 } /*! @@ -27071,7 +26562,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; } @@ -27090,29 +26581,29 @@ void QCPColorMap::setTightBoundary( bool enabled ) Pass \c nullptr 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))); } } @@ -27136,11 +26627,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()); } /*! @@ -27157,92 +26648,90 @@ 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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { 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 {}; } } - + 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; @@ -27264,80 +26753,75 @@ QCPRange QCPColorMap::getValueRange( bool& foundRange, QCP::SignDomain inSignDom */ 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 < lineCount; ++line ) + 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 < lineCount; ++line ) + 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; @@ -27345,90 +26829,85 @@ 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) + 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) + 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 ); + 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: @@ -27439,8 +26918,9 @@ void QCPColorMap::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) cons } /* end of 'src/plottables/plottable-colormap.cpp' */ + /* including file 'src/plottables/plottable-financial.cpp' */ -/* modified 2021-03-29T02:30:44, size 42914 */ +/* modified 2022-11-06T12:45:57, size 42914 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPFinancialData @@ -27519,19 +26999,28 @@ void QCPColorMap::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) cons /*! 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -27606,10 +27095,18 @@ 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() @@ -27631,7 +27128,7 @@ QCPFinancial::~QCPFinancial() \see addData, timeSeriesToOhlc */ -void QCPFinancial::setData( QSharedPointer data ) +void QCPFinancial::setData(QSharedPointer data) { mDataContainer = data; } @@ -27647,16 +27144,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; } @@ -27666,7 +27163,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; } @@ -27679,7 +27176,7 @@ void QCPFinancial::setWidth( double width ) \see setWidth */ -void QCPFinancial::setWidthType( QCPFinancial::WidthType widthType ) +void QCPFinancial::setWidthType(QCPFinancial::WidthType widthType) { mWidthType = widthType; } @@ -27693,7 +27190,7 @@ void QCPFinancial::setWidthType( QCPFinancial::WidthType widthType ) \see setPenPositive, setPenNegative, setBrushPositive, setBrushNegative */ -void QCPFinancial::setTwoColored( bool twoColored ) +void QCPFinancial::setTwoColored(bool twoColored) { mTwoColored = twoColored; } @@ -27707,7 +27204,7 @@ void QCPFinancial::setTwoColored( bool twoColored ) \see setBrushNegative, setPenPositive, setPenNegative */ -void QCPFinancial::setBrushPositive( const QBrush& brush ) +void QCPFinancial::setBrushPositive(const QBrush &brush) { mBrushPositive = brush; } @@ -27721,7 +27218,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; } @@ -27735,7 +27232,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; } @@ -27749,7 +27246,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; } @@ -27768,16 +27265,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]; @@ -27787,7 +27284,7 @@ void QCPFinancial::addData( const QVector& keys, const QVector& ++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 @@ -27800,29 +27297,29 @@ void QCPFinancial::addData( const QVector& keys, const QVector& \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( int( it - mDataContainer->constBegin() ), int( it - mDataContainer->constBegin() + 1 ) ), false ); + if (rect.intersects(selectionHitBox(it))) + result.addDataRange(QCPDataRange(int(it-mDataContainer->constBegin()), int(it-mDataContainer->constBegin()+1)), false); } result.simplify(); return result; @@ -27836,61 +27333,59 @@ QCPDataSelection QCPFinancial::selectTestRect( const QRectF& rect, bool onlySele \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() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { // 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 = int( closestDataPoint - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int(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); } /*! @@ -27907,143 +27402,135 @@ QCPRange QCPFinancial::getValueRange( bool& foundRange, QCP::SignDomain inSignDo 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 < count; ++i ) + + 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 < allSegments.size(); ++i ) + 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(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(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 ) + } 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())); } } } @@ -28054,58 +27541,53 @@ void QCPFinancial::drawLegendIcon( QCPPainter* painter, const QRectF& rect ) con 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 ) + 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) { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - - if( keyAxis->orientation() == Qt::Horizontal ) - { - 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( 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)); } } } @@ -28116,76 +27598,67 @@ void QCPFinancial::drawOhlcPlot( QCPPainter* painter, const QCPFinancialDataCont 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 ) + 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) { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - - if( keyAxis->orientation() == Qt::Horizontal ) - { - 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 ) + 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(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else { - painter->setPen( mPen ); - painter->setBrush( mBrush ); + painter->setPen(mPen); + painter->setBrush(mBrush); } - double keyPixel = keyAxis->coordToPixel( it->key ); - double openPixel = valueAxis->coordToPixel( it->open ); - double closePixel = valueAxis->coordToPixel( it->close ); + 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 ) + 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(it->close >= it->open ? mPenPositive : mPenNegative); + painter->setBrush(it->close >= it->open ? mBrushPositive : mBrushNegative); + } else { - painter->setPen( mPen ); - painter->setBrush( mBrush ); + painter->setPen(mPen); + painter->setBrush(mBrush); } - double keyPixel = keyAxis->coordToPixel( it->key ); - double openPixel = valueAxis->coordToPixel( it->open ); - double closePixel = valueAxis->coordToPixel( it->close ); + 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))); } } } @@ -28202,35 +27675,37 @@ void QCPFinancial::drawCandlestickPlot( QCPPainter* painter, const QCPFinancialD 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: { - if( mKeyAxis ) - result = mWidth * 0.5 * mKeyAxis.data()->pixelOrientation(); - break; - } - case wtAxisRectRatio: { - if( mKeyAxis && mKeyAxis.data()->axisRect() ) + case wtAbsolute: { - 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(); + 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; + else + qDebug() << Q_FUNC_INFO << "No key axis defined"; + break; } - 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; } @@ -28243,47 +27718,42 @@ 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 ) + 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 ) + 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) { 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 ) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt( minDistSqr ); + return qSqrt(minDistSqr); } /*! \internal @@ -28295,77 +27765,70 @@ double QCPFinancial::ohlcSelectTest( const QPointF& pos, const QCPFinancialDataC 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 ) + 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 ) + 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) { 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 ) - { - minDistSqr = currentDistSqr; - closestDataPoint = it; - } - } - } - return qSqrt( minDistSqr ); + return qSqrt(minDistSqr); } /*! \internal @@ -28382,17 +27845,17 @@ double QCPFinancial::candlestickSelectTest( const QPointF& pos, const QCPFinanci 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 @@ -28400,29 +27863,26 @@ void QCPFinancial::getVisibleDataBounds( QCPFinancialDataContainer::const_iterat 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 {}; - } - - 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 {}; } + + 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' */ -/* modified 2021-03-29T02:30:44, size 37679 */ +/* modified 2022-11-06T12:45:56, size 37679 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPErrorBarsData @@ -28446,16 +27906,18 @@ QRectF QCPFinancial::selectionHitBox( QCPFinancialDataContainer::const_iterator /*! 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) { } @@ -28463,11 +27925,13 @@ 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 //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -28525,11 +27989,15 @@ 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() @@ -28554,7 +28022,7 @@ QCPErrorBars::~QCPErrorBars() \see addData */ -void QCPErrorBars::setData( QSharedPointer data ) +void QCPErrorBars::setData(QSharedPointer data) { mDataContainer = data; } @@ -28568,10 +28036,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 @@ -28584,10 +28052,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); } /*! @@ -28604,21 +28072,21 @@ void QCPErrorBars::setData( const QVector& errorMinus, const QVector( plottable ) ) + if (plottable && qobject_cast(plottable)) { mDataPlottable = nullptr; qDebug() << Q_FUNC_INFO << "can't set another QCPErrorBars instance as data plottable"; return; } - if( plottable && !plottable->interface1D() ) + if (plottable && !plottable->interface1D()) { mDataPlottable = nullptr; qDebug() << Q_FUNC_INFO << "passed plottable doesn't implement 1d interface, can't associate with QCPErrorBars"; return; } - + mDataPlottable = plottable; } @@ -28626,7 +28094,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; } @@ -28635,7 +28103,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; } @@ -28645,7 +28113,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; } @@ -28659,9 +28127,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 @@ -28674,14 +28142,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; i < n; ++i ) - mDataContainer->append( QCPErrorBarsData( errorMinus.at( i ), errorPlus.at( i ) ) ); + const int n = qMin(errorMinus.size(), errorPlus.size()); + mDataContainer->reserve(n); + for (int i=0; iappend(QCPErrorBarsData(errorMinus.at(i), errorPlus.at(i))); } /*! \overload @@ -28693,9 +28161,9 @@ void QCPErrorBars::addData( const QVector& errorMinus, const QVectorappend( QCPErrorBarsData( error ) ); + mDataContainer->append(QCPErrorBarsData(error)); } /*! \overload @@ -28708,9 +28176,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 */ @@ -28720,47 +28188,46 @@ 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 { 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 {value-mDataContainer->at(index).errorMinus, value+mDataContainer->at(index).errorPlus}; else - return { value, value }; - } - else + return {value, value}; + } else { qDebug() << Q_FUNC_INFO << "no data plottable set"; return {}; @@ -28768,10 +28235,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 {}; @@ -28780,11 +28247,10 @@ 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; @@ -28794,30 +28260,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 ); - foreach( const QLineF& backbone, backbones ) + getErrorBarLines(it, backbones, whiskers); + foreach (const QLineF &backbone, backbones) { - if( rectIntersectsLine( rect, backbone ) ) + if (rectIntersectsLine(rect, backbone)) { - result.addDataRange( QCPDataRange( int( it - mDataContainer->constBegin() ), int( it - mDataContainer->constBegin() + 1 ) ), false ); + result.addDataRange(QCPDataRange(int(it-mDataContainer->constBegin()), int(it-mDataContainer->constBegin()+1)), false); break; } } @@ -28827,35 +28293,33 @@ QCPDataSelection QCPErrorBars::selectTestRect( const QRectF& rect, bool onlySele } /* 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; } @@ -28868,174 +28332,161 @@ 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 ) + if (!mDataPlottable) return -1; + + if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) return -1; - - if( ( onlySelectable && mSelectable == QCP::stNone ) || mDataContainer->isEmpty() ) + if (!mKeyAxis || !mValueAxis) return -1; - if( !mKeyAxis || !mValueAxis ) - return -1; - - if( mKeyAxis.data()->axisRect()->rect().contains( pos.toPoint() ) || mParentPlot->interactions().testFlag( QCP::iSelectPlottablesBeyondAxisRect ) ) + + if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { QCPErrorBarsDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); - double result = pointDistance( pos, closestDataPoint ); - if( details ) + double result = pointDistance(pos, closestDataPoint); + if (details) { - int pointIndex = int( closestDataPoint - mDataContainer->constBegin() ); - details->setValue( QCPDataSelection( QCPDataRange( pointIndex, pointIndex + 1 ) ) ); + int pointIndex = int(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 < allSegments.size(); ++i ) + 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( int( it - mDataContainer->constBegin() ) ) ) - getErrorBarLines( it, backbones, whiskers ); + if (!checkPointVisibility || errorBarVisible(int(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 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( int( 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(int(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( int( it - mDataContainer->constBegin() ) ); - if( qIsNaN( dataKey ) ) - continue; + const double dataKey = mDataPlottable->interface1D()->dataMainKey(int(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; @@ -29043,90 +28494,86 @@ QCPRange QCPErrorBars::getKeyRange( bool& foundRange, QCP::SignDomain inSignDoma } } } - - 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 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, false ); - itEnd = mDataContainer->constBegin() + findEnd( inKeyRange.upper, false ); + itBegin = mDataContainer->constBegin()+findBegin(inKeyRange.lower, false); + itEnd = mDataContainer->constBegin()+findEnd(inKeyRange.upper, false); } - 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( int( it - mDataContainer->constBegin() ) ); - if( dataKey < inKeyRange.lower || dataKey > inKeyRange.upper ) + const double dataKey = mDataPlottable->interface1D()->dataMainKey(int(it-mDataContainer->constBegin())); + if (dataKey < inKeyRange.lower || dataKey > inKeyRange.upper) continue; } - if( mErrorType == etValueError ) + if (mErrorType == etValueError) { - const double dataValue = mDataPlottable->interface1D()->dataMainValue( int( it - mDataContainer->constBegin() ) ); - if( qIsNaN( dataValue ) ) - continue; + const double dataValue = mDataPlottable->interface1D()->dataMainValue(int(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( int( 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(int(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; @@ -29134,18 +28581,17 @@ QCPRange QCPErrorBars::getValueRange( bool& foundRange, QCP::SignDomain inSignDo } } } - - 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; } @@ -29161,56 +28607,53 @@ QCPRange QCPErrorBars::getValueRange( bool& foundRange, QCP::SignDomain inSignDo 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 ) + if (!mDataPlottable) return; + + int index = int(it-mDataContainer->constBegin()); + QPointF centerPixel = mDataPlottable->interface1D()->dataPixelPosition(index); + if (qIsNaN(centerPixel.x()) || qIsNaN(centerPixel.y())) return; - - int index = int( 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(); + 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)); } } } @@ -29233,57 +28676,57 @@ void QCPErrorBars::getErrorBarLines( QCPErrorBarsDataContainer::const_iterator i 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 @@ -29292,37 +28735,37 @@ void QCPErrorBars::getVisibleDataBounds( QCPErrorBarsDataContainer::const_iterat 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)(); 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 ); - foreach( const QLineF& backbone, backbones ) + getErrorBarLines(it, backbones, whiskers); + foreach (const QLineF &backbone, backbones) { - const double currentDistSqr = QCPVector2D( pixelPoint ).distanceSquaredToLine( backbone ); - if( currentDistSqr < minDistSqr ) + const double currentDistSqr = QCPVector2D(pixelPoint).distanceSquaredToLine(backbone); + if (currentDistSqr < minDistSqr) { minDistSqr = currentDistSqr; closestData = it; } } } - return qSqrt( minDistSqr ); + return qSqrt(minDistSqr); } /*! \internal @@ -29332,23 +28775,22 @@ double QCPErrorBars::pointDistance( const QPointF& pixelPoint, QCPErrorBarsDataC own key/value data coordinates, doesn't derive from \ref QCPAbstractPlottable1D. See the documentation there for details. */ -void QCPErrorBars::getDataSegments( QList& 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(); } } @@ -29361,28 +28803,27 @@ void QCPErrorBars::getDataSegments( QList& selectedSegments, QList and the data plottable (\ref setDataPlottable) are not \c nullptr 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 + 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() ); + 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 ) ); + return ((keyMax > mKeyAxis->range().lower) && (keyMin < mKeyAxis->range().upper)); } /*! \internal @@ -29392,23 +28833,24 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7596 */ +/* modified 2022-11-06T12:45:56, size 7596 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemStraightLine @@ -29428,14 +28870,16 @@ bool QCPErrorBars::rectIntersectsLine( const QRectF& pixelRect, const QLineF& li 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() @@ -29447,7 +28891,7 @@ QCPItemStraightLine::~QCPItemStraightLine() \see setSelectedPen */ -void QCPItemStraightLine::setPen( const QPen& pen ) +void QCPItemStraightLine::setPen(const QPen &pen) { mPen = pen; } @@ -29457,34 +28901,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: - int clipPad = qCeil( mainPen().widthF() ); - QLineF line = getRectClippedStraightLine( start, end - start, clipRect().adjusted( -clipPad, -clipPad, clipPad, clipPad ) ); + int clipPad = qCeil(mainPen().widthF()); + 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); } } @@ -29495,83 +28939,80 @@ 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 < pointVectors.size() - 1; ++i ) + 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; @@ -29588,8 +29029,9 @@ QPen QCPItemStraightLine::mainPen() const } /* end of 'src/items/item-straightline.cpp' */ + /* including file 'src/items/item-line.cpp' */ -/* modified 2021-03-29T02:30:44, size 8525 */ +/* modified 2022-11-06T12:45:56, size 8525 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemLine @@ -29611,14 +29053,16 @@ 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() @@ -29630,7 +29074,7 @@ QCPItemLine::~QCPItemLine() \see setSelectedPen */ -void QCPItemLine::setPen( const QPen& pen ) +void QCPItemLine::setPen(const QPen &pen) { mPen = pen; } @@ -29640,7 +29084,7 @@ void QCPItemLine::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemLine::setSelectedPen( const QPen& pen ) +void QCPItemLine::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -29653,7 +29097,7 @@ void QCPItemLine::setSelectedPen( const QPen& pen ) \see setTail */ -void QCPItemLine::setHead( const QCPLineEnding& head ) +void QCPItemLine::setHead(const QCPLineEnding &head) { mHead = head; } @@ -29666,42 +29110,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: - int clipPad = int( qMax( mHead.boundingDistance(), mTail.boundingDistance() ) ); - clipPad = qMax( clipPad, qCeil( mainPen().widthF() ) ); - QLineF line = getRectClippedLine( startVec, endVec, clipRect().adjusted( -clipPad, -clipPad, clipPad, clipPad ) ); + int clipPad = int(qMax(mHead.boundingDistance(), mTail.boundingDistance())); + clipPad = qMax(clipPad, qCeil(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); } } @@ -29712,96 +29156,95 @@ 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( qRound( start.x() ), qRound( start.y() ) ); - bool containsEnd = rect.contains( qRound( end.x() ), qRound( end.y() ) ); - if( containsStart && containsEnd ) - return { start.toPointF(), end.toPointF() }; - + bool containsStart = rect.contains(qRound(start.x()), qRound(start.y())); + bool containsEnd = rect.contains(qRound(end.x()), qRound(end.y())); + if (containsStart && containsEnd) + return {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 < pointVectors.size() - 1; ++i ) + 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; } @@ -29817,8 +29260,9 @@ QPen QCPItemLine::mainPen() const } /* end of 'src/items/item-line.cpp' */ + /* including file 'src/items/item-curve.cpp' */ -/* modified 2021-03-29T02:30:44, size 7273 */ +/* modified 2022-11-06T12:45:56, size 7273 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemCurve @@ -29847,16 +29291,20 @@ 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() @@ -29868,7 +29316,7 @@ QCPItemCurve::~QCPItemCurve() \see setSelectedPen */ -void QCPItemCurve::setPen( const QPen& pen ) +void QCPItemCurve::setPen(const QPen &pen) { mPen = pen; } @@ -29878,7 +29326,7 @@ void QCPItemCurve::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemCurve::setSelectedPen( const QPen& pen ) +void QCPItemCurve::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -29891,7 +29339,7 @@ void QCPItemCurve::setSelectedPen( const QPen& pen ) \see setTail */ -void QCPItemCurve::setHead( const QCPLineEnding& head ) +void QCPItemCurve::setHead(const QCPLineEnding &head) { mHead = head; } @@ -29904,69 +29352,69 @@ 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()); - QPointF startVec( start->pixelPosition() ); - QPointF startDirVec( startDir->pixelPosition() ); - QPointF endDirVec( endDir->pixelPosition() ); - QPointF endVec( end->pixelPosition() ); - - QPainterPath cubicPath( startVec ); - cubicPath.cubicTo( startDirVec, endDirVec, endVec ); - + 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 ); + QCPVector2D p(pos); double minDistSqr = (std::numeric_limits::max)(); - for( int i = 1; i < polygon.size(); ++i ) + for (int i=1; ipixelPosition() ); - 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: - const int clipEnlarge = qCeil( mainPen().widthF() ); - QRect clip = clipRect().adjusted( -clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge ); + const int clipEnlarge = qCeil(mainPen().widthF()); + QRect clip = clipRect().adjusted(-clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge); 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); } } @@ -29981,8 +29429,9 @@ QPen QCPItemCurve::mainPen() const } /* end of 'src/items/item-curve.cpp' */ + /* including file 'src/items/item-rect.cpp' */ -/* modified 2021-03-29T02:30:44, size 6472 */ +/* modified 2022-11-06T12:45:56, size 6472 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemRect @@ -30002,16 +29451,24 @@ 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() @@ -30023,7 +29480,7 @@ QCPItemRect::~QCPItemRect() \see setSelectedPen, setBrush */ -void QCPItemRect::setPen( const QPen& pen ) +void QCPItemRect::setPen(const QPen &pen) { mPen = pen; } @@ -30033,7 +29490,7 @@ void QCPItemRect::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemRect::setSelectedPen( const QPen& pen ) +void QCPItemRect::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -30044,7 +29501,7 @@ void QCPItemRect::setSelectedPen( const QPen& pen ) \see setSelectedBrush, setPen */ -void QCPItemRect::setBrush( const QBrush& brush ) +void QCPItemRect::setBrush(const QBrush &brush) { mBrush = brush; } @@ -30055,61 +29512,55 @@ 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 {}; } @@ -30135,8 +29586,9 @@ QBrush QCPItemRect::mainBrush() const } /* end of 'src/items/item-rect.cpp' */ + /* including file 'src/items/item-text.cpp' */ -/* modified 2021-03-29T02:30:44, size 13335 */ +/* modified 2022-11-06T12:45:56, size 13335 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemText @@ -30162,17 +29614,30 @@ 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() @@ -30182,7 +29647,7 @@ QCPItemText::~QCPItemText() /*! Sets the color of the text. */ -void QCPItemText::setColor( const QColor& color ) +void QCPItemText::setColor(const QColor &color) { mColor = color; } @@ -30190,7 +29655,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; } @@ -30201,7 +29666,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; } @@ -30212,7 +29677,7 @@ void QCPItemText::setPen( const QPen& pen ) \see setPen */ -void QCPItemText::setSelectedPen( const QPen& pen ) +void QCPItemText::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -30223,7 +29688,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; } @@ -30234,7 +29699,7 @@ void QCPItemText::setBrush( const QBrush& brush ) \see setBrush */ -void QCPItemText::setSelectedBrush( const QBrush& brush ) +void QCPItemText::setSelectedBrush(const QBrush &brush) { mSelectedBrush = brush; } @@ -30244,7 +29709,7 @@ void QCPItemText::setSelectedBrush( const QBrush& brush ) \see setSelectedFont, setColor */ -void QCPItemText::setFont( const QFont& font ) +void QCPItemText::setFont(const QFont &font) { mFont = font; } @@ -30254,7 +29719,7 @@ void QCPItemText::setFont( const QFont& font ) \see setFont */ -void QCPItemText::setSelectedFont( const QFont& font ) +void QCPItemText::setSelectedFont(const QFont &font) { mSelectedFont = font; } @@ -30265,7 +29730,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; } @@ -30282,7 +29747,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; } @@ -30290,7 +29755,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; } @@ -30299,7 +29764,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; } @@ -30308,103 +29773,95 @@ 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() ); - int clipPad = qCeil( mainPen().widthF() ); - QRect boundingRect = textBoxRect.adjusted( -clipPad, -clipPad, clipPad, clipPad ); - if( transform.mapRect( boundingRect ).intersects( painter->transform().mapRect( clipRect() ) ) ) + 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()); + int clipPad = qCeil(mainPen().widthF()); + 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 {}; } @@ -30419,19 +29876,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; } @@ -30477,8 +29934,9 @@ QBrush QCPItemText::mainBrush() const } /* end of 'src/items/item-text.cpp' */ + /* including file 'src/items/item-ellipse.cpp' */ -/* modified 2021-03-29T02:30:44, size 7881 */ +/* modified 2022-11-06T12:45:56, size 7881 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemEllipse @@ -30498,16 +29956,27 @@ 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() @@ -30519,7 +29988,7 @@ QCPItemEllipse::~QCPItemEllipse() \see setSelectedPen, setBrush */ -void QCPItemEllipse::setPen( const QPen& pen ) +void QCPItemEllipse::setPen(const QPen &pen) { mPen = pen; } @@ -30529,7 +29998,7 @@ void QCPItemEllipse::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemEllipse::setSelectedPen( const QPen& pen ) +void QCPItemEllipse::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -30540,7 +30009,7 @@ void QCPItemEllipse::setSelectedPen( const QPen& pen ) \see setSelectedBrush, setPen */ -void QCPItemEllipse::setBrush( const QBrush& brush ) +void QCPItemEllipse::setBrush(const QBrush &brush) { mBrush = brush; } @@ -30551,94 +30020,84 @@ 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(); - const int clipEnlarge = qCeil( mainPen().widthF() ); - QRect clip = clipRect().adjusted( -clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge ); - if( ellipseRect.intersects( clip ) ) // only draw if bounding rect of ellipse is visible in cliprect + QRectF ellipseRect = QRectF(p1, p2).normalized(); + const int clipEnlarge = qCeil(mainPen().widthF()); + QRect clip = clipRect().adjusted(-clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge); + 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 {}; } @@ -30664,8 +30123,9 @@ QBrush QCPItemEllipse::mainBrush() const } /* end of 'src/items/item-ellipse.cpp' */ + /* including file 'src/items/item-pixmap.cpp' */ -/* modified 2021-03-29T02:30:44, size 10622 */ +/* modified 2022-11-06T12:45:56, size 10622 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemPixmap @@ -30691,14 +30151,26 @@ 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() @@ -30708,11 +30180,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"; } @@ -30720,7 +30192,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; @@ -30733,7 +30205,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; } @@ -30743,72 +30215,66 @@ 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 ); - int clipPad = mainPen().style() == Qt::NoPen ? 0 : qCeil( mainPen().widthF() ); - QRect boundingRect = rect.adjusted( -clipPad, -clipPad, clipPad, clipPad ); - if( boundingRect.intersects( clipRect() ) ) + QRect rect = getFinalRect(&flipHorz, &flipVert); + int clipPad = mainPen().style() == Qt::NoPen ? 0 : qCeil(mainPen().widthF()); + 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 = false; bool flipVert = false; - 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 {}; } @@ -30826,31 +30292,30 @@ 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; } @@ -30869,51 +30334,50 @@ void QCPItemPixmap::updateScaledPixmap( QRect finalRect, bool flipHorz, bool fli 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 { p1, QSize( 0, 0 ) }; - if( mScaled ) + if (p1 == p2) + return {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; } @@ -30929,8 +30393,9 @@ QPen QCPItemPixmap::mainPen() const } /* end of 'src/items/item-pixmap.cpp' */ + /* including file 'src/items/item-tracer.cpp' */ -/* modified 2021-03-29T02:30:44, size 14645 */ +/* modified 2022-11-06T12:45:56, size 14645 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemTracer @@ -30972,15 +30437,21 @@ 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( nullptr ), mGraphKey( 0 ), mInterpolating( false ) +QCPItemTracer::QCPItemTracer(QCustomPlot *parentPlot) : + QCPAbstractItem(parentPlot), + position(createPosition(QLatin1String("position"))), + mSize(6), + mStyle(tsCrosshair), + mGraph(nullptr), + 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() @@ -30992,7 +30463,7 @@ QCPItemTracer::~QCPItemTracer() \see setSelectedPen, setBrush */ -void QCPItemTracer::setPen( const QPen& pen ) +void QCPItemTracer::setPen(const QPen &pen) { mPen = pen; } @@ -31002,7 +30473,7 @@ void QCPItemTracer::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemTracer::setSelectedPen( const QPen& pen ) +void QCPItemTracer::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -31012,7 +30483,7 @@ void QCPItemTracer::setSelectedPen( const QPen& pen ) \see setSelectedBrush, setPen */ -void QCPItemTracer::setBrush( const QBrush& brush ) +void QCPItemTracer::setBrush(const QBrush &brush) { mBrush = brush; } @@ -31022,7 +30493,7 @@ void QCPItemTracer::setBrush( const QBrush& brush ) \see setBrush, setSelected */ -void QCPItemTracer::setSelectedBrush( const QBrush& brush ) +void QCPItemTracer::setSelectedBrush(const QBrush &brush) { mSelectedBrush = brush; } @@ -31031,7 +30502,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; } @@ -31042,7 +30513,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; } @@ -31057,21 +30528,19 @@ 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 = nullptr; } @@ -31086,7 +30555,7 @@ void QCPItemTracer::setGraph( QCPGraph* graph ) \see setGraph, setInterpolating */ -void QCPItemTracer::setGraphKey( double key ) +void QCPItemTracer::setGraphKey(double key) { mGraphKey = key; } @@ -31102,106 +30571,112 @@ 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: { - 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() ) ) + case tsNone: return -1; + case tsPlus: { - // 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 (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( centerDist <= circleLine ) - result = mParentPlot->selectionTolerance() * 0.99; + // 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; } - return result; + break; } - break; - } - case tsSquare: { - if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) + case tsSquare: { - 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 ); + 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; } - 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: { - if( clip.intersects( QRectF( center - QPointF( w, w ), center + QPointF( w, w ) ).toRect() ) ) + case tsNone: return; + case tsPlus: { - painter->drawLine( QLineF( center + QPointF( -w, 0 ), center + QPointF( w, 0 ) ) ); - painter->drawLine( QLineF( center + QPointF( 0, -w ), center + QPointF( 0, w ) ) ); + 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; } - 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; - } } } @@ -31219,55 +30694,50 @@ 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)"; } } @@ -31293,8 +30763,9 @@ QBrush QCPItemTracer::mainBrush() const } /* end of 'src/items/item-tracer.cpp' */ + /* including file 'src/items/item-bracket.cpp' */ -/* modified 2021-03-29T02:30:44, size 10705 */ +/* modified 2022-11-06T12:45:56, size 10705 */ //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPItemBracket @@ -31326,14 +30797,19 @@ 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() @@ -31349,7 +30825,7 @@ QCPItemBracket::~QCPItemBracket() \see setSelectedPen */ -void QCPItemBracket::setPen( const QPen& pen ) +void QCPItemBracket::setPen(const QPen &pen) { mPen = pen; } @@ -31359,7 +30835,7 @@ void QCPItemBracket::setPen( const QPen& pen ) \see setPen, setSelected */ -void QCPItemBracket::setSelectedPen( const QPen& pen ) +void QCPItemBracket::setSelectedPen(const QPen &pen) { mSelectedPen = pen; } @@ -31372,7 +30848,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; } @@ -31382,130 +30858,136 @@ 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(); - const int clipEnlarge = qCeil( mainPen().widthF() ); - QRect clip = clipRect().adjusted( -clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge ); - if( clip.intersects( boundingPoly.boundingRect() ) ) + << (rightVec-lengthVec).toPoint() << (leftVec-lengthVec).toPoint(); + const int clipEnlarge = qCeil(mainPen().widthF()); + QRect clip = clipRect().adjusted(-clipEnlarge, -clipEnlarge, clipEnlarge, clipEnlarge); + 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 {}; @@ -31518,12 +31000,15 @@ 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' */ + /* including file 'src/polar/radialaxis.cpp' */ -/* modified 2021-03-29T02:30:44, size 49415 */ +/* modified 2022-11-06T12:45:57, size 49415 */ + + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPolarAxisRadial @@ -31609,70 +31094,66 @@ QPen QCPItemBracket::mainPen() 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. */ -QCPPolarAxisRadial::QCPPolarAxisRadial( QCPPolarAxisAngular* parent ) - : QCPLayerable( parent->parentPlot(), QString(), parent ), mRangeDrag( true ), mRangeZoom( true ), mRangeZoomFactor( 0.85 ), - // axis base: - mAngularAxis( parent ) - , mAngle( 45 ) - , mAngleReference( arAngularAxis ) - , mSelectableParts( spAxis | spTickLabels | spAxisLabel ) - , mSelectedParts( spNone ) - , mBasePen( QPen( Qt::black, 0, Qt::SolidLine, Qt::SquareCap ) ) - , mSelectedBasePen( QPen( Qt::blue, 2 ) ) - , - // axis label: - mLabelPadding( 0 ) - , mLabel() - , mLabelFont( mParentPlot->font() ) - , mSelectedLabelFont( QFont( mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold ) ) - , mLabelColor( Qt::black ) - , mSelectedLabelColor( Qt::blue ) - , - // tick labels: - // mTickLabelPadding(0), in label painter - mTickLabels( true ) - , - // mTickLabelRotation(0), in label painter - mTickLabelFont( mParentPlot->font() ) - , mSelectedTickLabelFont( QFont( mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold ) ) - , mTickLabelColor( Qt::black ) - , mSelectedTickLabelColor( Qt::blue ) - , mNumberPrecision( 6 ) - , mNumberFormatChar( 'g' ) - , mNumberBeautifulPowers( true ) - , mNumberMultiplyCross( false ) - , - // ticks and subticks: - mTicks( true ) - , mSubTicks( true ) - , mTickLengthIn( 5 ) - , mTickLengthOut( 0 ) - , mSubTickLengthIn( 2 ) - , mSubTickLengthOut( 0 ) - , 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: - mRadius( 1 ) - , // non-zero initial value, will be overwritten in ::update() according to inner rect - mTicker( new QCPAxisTicker ) - , mLabelPainter( mParentPlot ) +QCPPolarAxisRadial::QCPPolarAxisRadial(QCPPolarAxisAngular *parent) : + QCPLayerable(parent->parentPlot(), QString(), parent), + mRangeDrag(true), + mRangeZoom(true), + mRangeZoomFactor(0.85), + // axis base: + mAngularAxis(parent), + mAngle(45), + mAngleReference(arAngularAxis), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabelPadding(0), + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + // mTickLabelPadding(0), in label painter + mTickLabels(true), + // mTickLabelRotation(0), in label painter + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + mNumberMultiplyCross(false), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickLengthIn(5), + mTickLengthOut(0), + mSubTickLengthIn(2), + mSubTickLengthOut(0), + 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: + mRadius(1), // non-zero initial value, will be overwritten in ::update() according to inner rect + mTicker(new QCPAxisTicker), + mLabelPainter(mParentPlot) { - setParent( parent ); - setAntialiased( true ); - - setTickLabelPadding( 5 ); - setTickLabelRotation( 0 ); - setTickLabelMode( lmUpright ); - mLabelPainter.setAnchorReferenceType( QCPLabelPainterPrivate::artTangent ); - mLabelPainter.setAbbreviateDecimalPowers( false ); + setParent(parent); + setAntialiased(true); + + setTickLabelPadding(5); + setTickLabelRotation(0); + setTickLabelMode(lmUpright); + mLabelPainter.setAnchorReferenceType(QCPLabelPainterPrivate::artTangent); + mLabelPainter.setAbbreviateDecimalPowers(false); } QCPPolarAxisRadial::~QCPPolarAxisRadial() @@ -31681,15 +31162,11 @@ QCPPolarAxisRadial::~QCPPolarAxisRadial() QCPPolarAxisRadial::LabelMode QCPPolarAxisRadial::tickLabelMode() const { - switch( mLabelPainter.anchorMode() ) + switch (mLabelPainter.anchorMode()) { - case QCPLabelPainterPrivate::amSkewedUpright: - return lmUpright; - case QCPLabelPainterPrivate::amSkewedRotated: - return lmRotated; - default: - qDebug() << Q_FUNC_INFO << "invalid mode for polar axis"; - break; + case QCPLabelPainterPrivate::amSkewedUpright: return lmUpright; + case QCPLabelPainterPrivate::amSkewedRotated: return lmRotated; + default: qDebug() << Q_FUNC_INFO << "invalid mode for polar axis"; break; } return lmUpright; } @@ -31698,12 +31175,12 @@ QCPPolarAxisRadial::LabelMode QCPPolarAxisRadial::tickLabelMode() const QString QCPPolarAxisRadial::numberFormat() const { QString result; - result.append( mNumberFormatChar ); - if( mNumberBeautifulPowers ) + result.append(mNumberFormatChar); + if (mNumberBeautifulPowers) { - result.append( QLatin1Char( 'b' ) ); - if( mNumberMultiplyCross ) - result.append( QLatin1Char( 'c' ) ); + result.append(QLatin1Char('b')); + if (mNumberMultiplyCross) + result.append(QLatin1Char('c')); } return result; } @@ -31738,17 +31215,17 @@ int QCPPolarAxisRadial::labelPadding() const return mLabelPadding; } -void QCPPolarAxisRadial::setRangeDrag( bool enabled ) +void QCPPolarAxisRadial::setRangeDrag(bool enabled) { mRangeDrag = enabled; } -void QCPPolarAxisRadial::setRangeZoom( bool enabled ) +void QCPPolarAxisRadial::setRangeZoom(bool enabled) { mRangeZoom = enabled; } -void QCPPolarAxisRadial::setRangeZoomFactor( double factor ) +void QCPPolarAxisRadial::setRangeZoomFactor(double factor) { mRangeZoomFactor = factor; } @@ -31767,15 +31244,15 @@ void QCPPolarAxisRadial::setRangeZoomFactor( double factor ) \ref setNumberPrecision */ -void QCPPolarAxisRadial::setScaleType( QCPPolarAxisRadial::ScaleType type ) +void QCPPolarAxisRadial::setScaleType(QCPPolarAxisRadial::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); } } @@ -31787,24 +31264,22 @@ void QCPPolarAxisRadial::setScaleType( QCPPolarAxisRadial::ScaleType type ) To invert the direction of an axis, use \ref setRangeReversed. */ -void QCPPolarAxisRadial::setRange( const QCPRange& range ) +void QCPPolarAxisRadial::setRange(const QCPRange &range) { - if( range.lower == mRange.lower && range.upper == mRange.upper ) - return; - - if( !QCPRange::validRange( range ) ) + if (range.lower == mRange.lower && range.upper == mRange.upper) 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); } /*! @@ -31817,12 +31292,12 @@ void QCPPolarAxisRadial::setRange( const QCPRange& range ) \see SelectablePart, setSelectedParts */ -void QCPPolarAxisRadial::setSelectableParts( const SelectableParts& selectable ) +void QCPPolarAxisRadial::setSelectableParts(const SelectableParts &selectable) { - if( mSelectableParts != selectable ) + if (mSelectableParts != selectable) { mSelectableParts = selectable; - emit selectableChanged( mSelectableParts ); + emit selectableChanged(mSelectableParts); } } @@ -31841,12 +31316,12 @@ void QCPPolarAxisRadial::setSelectableParts( const SelectableParts& selectable ) \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor */ -void QCPPolarAxisRadial::setSelectedParts( const SelectableParts& selected ) +void QCPPolarAxisRadial::setSelectedParts(const SelectableParts &selected) { - if( mSelectedParts != selected ) + if (mSelectedParts != selected) { mSelectedParts = selected; - emit selectionChanged( mSelectedParts ); + emit selectionChanged(mSelectedParts); } } @@ -31859,26 +31334,24 @@ void QCPPolarAxisRadial::setSelectedParts( const SelectableParts& selected ) There is also a slot to set a range, see \ref setRange(const QCPRange &range). */ -void QCPPolarAxisRadial::setRange( double lower, double upper ) +void QCPPolarAxisRadial::setRange(double lower, double upper) { - if( lower == mRange.lower && upper == mRange.upper ) - return; - - if( !QCPRange::validRange( lower, upper ) ) + if (lower == mRange.lower && upper == mRange.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); } /*! @@ -31892,60 +31365,58 @@ void QCPPolarAxisRadial::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 QCPPolarAxisRadial::setRange( double position, double size, Qt::AlignmentFlag alignment ) +void QCPPolarAxisRadial::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 QCPPolarAxisRadial::setRangeLower( double lower ) +void QCPPolarAxisRadial::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 QCPPolarAxisRadial::setRangeUpper( double upper ) +void QCPPolarAxisRadial::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); } /*! @@ -31957,17 +31428,17 @@ void QCPPolarAxisRadial::setRangeUpper( double upper ) of the \ref setRange interface will still reference the mathematically smaller number than the \a upper part. */ -void QCPPolarAxisRadial::setRangeReversed( bool reversed ) +void QCPPolarAxisRadial::setRangeReversed(bool reversed) { mRangeReversed = reversed; } -void QCPPolarAxisRadial::setAngle( double degrees ) +void QCPPolarAxisRadial::setAngle(double degrees) { mAngle = degrees; } -void QCPPolarAxisRadial::setAngleReference( AngleReference reference ) +void QCPPolarAxisRadial::setAngleReference(AngleReference reference) { mAngleReference = reference; } @@ -31985,9 +31456,9 @@ void QCPPolarAxisRadial::setAngleReference( AngleReference reference ) \see ticker */ -void QCPPolarAxisRadial::setTicker( QSharedPointer ticker ) +void QCPPolarAxisRadial::setTicker(QSharedPointer ticker) { - if( ticker ) + if (ticker) mTicker = ticker; else qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; @@ -32002,9 +31473,9 @@ void QCPPolarAxisRadial::setTicker( QSharedPointer ticker ) \see setSubTicks */ -void QCPPolarAxisRadial::setTicks( bool show ) +void QCPPolarAxisRadial::setTicks(bool show) { - if( mTicks != show ) + if (mTicks != show) { mTicks = show; //mCachedMarginValid = false; @@ -32014,13 +31485,13 @@ void QCPPolarAxisRadial::setTicks( bool show ) /*! Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. */ -void QCPPolarAxisRadial::setTickLabels( bool show ) +void QCPPolarAxisRadial::setTickLabels(bool show) { - if( mTickLabels != show ) + if (mTickLabels != show) { mTickLabels = show; //mCachedMarginValid = false; - if( !mTickLabels ) + if (!mTickLabels) mTickVectorLabels.clear(); } } @@ -32029,9 +31500,9 @@ void QCPPolarAxisRadial::setTickLabels( bool show ) Sets the distance between the axis base line (including any outward ticks) and the tick labels. \see setLabelPadding, setPadding */ -void QCPPolarAxisRadial::setTickLabelPadding( int padding ) +void QCPPolarAxisRadial::setTickLabelPadding(int padding) { - mLabelPainter.setPadding( padding ); + mLabelPainter.setPadding(padding); } /*! @@ -32039,9 +31510,9 @@ void QCPPolarAxisRadial::setTickLabelPadding( int padding ) \see setTickLabels, setTickLabelColor */ -void QCPPolarAxisRadial::setTickLabelFont( const QFont& font ) +void QCPPolarAxisRadial::setTickLabelFont(const QFont &font) { - if( font != mTickLabelFont ) + if (font != mTickLabelFont) { mTickLabelFont = font; //mCachedMarginValid = false; @@ -32053,7 +31524,7 @@ void QCPPolarAxisRadial::setTickLabelFont( const QFont& font ) \see setTickLabels, setTickLabelFont */ -void QCPPolarAxisRadial::setTickLabelColor( const QColor& color ) +void QCPPolarAxisRadial::setTickLabelColor(const QColor &color) { mTickLabelColor = color; } @@ -32067,21 +31538,17 @@ void QCPPolarAxisRadial::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 QCPPolarAxisRadial::setTickLabelRotation( double degrees ) +void QCPPolarAxisRadial::setTickLabelRotation(double degrees) { - mLabelPainter.setRotation( degrees ); + mLabelPainter.setRotation(degrees); } -void QCPPolarAxisRadial::setTickLabelMode( LabelMode mode ) +void QCPPolarAxisRadial::setTickLabelMode(LabelMode mode) { - switch( mode ) + switch (mode) { - case lmUpright: - mLabelPainter.setAnchorMode( QCPLabelPainterPrivate::amSkewedUpright ); - break; - case lmRotated: - mLabelPainter.setAnchorMode( QCPLabelPainterPrivate::amSkewedRotated ); - break; + case lmUpright: mLabelPainter.setAnchorMode(QCPLabelPainterPrivate::amSkewedUpright); break; + case lmRotated: mLabelPainter.setAnchorMode(QCPLabelPainterPrivate::amSkewedRotated); break; } } @@ -32115,57 +31582,54 @@ void QCPPolarAxisRadial::setTickLabelMode( LabelMode mode ) \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 QCPPolarAxisRadial::setNumberFormat( const QString& formatCode ) +void QCPPolarAxisRadial::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; mNumberMultiplyCross = false; - } - else + } else { // 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 qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - - if( formatCode.length() < 3 ) + + if (formatCode.length() < 3) { mNumberMultiplyCross = false; - } - else + } else { // interpret third char as indicator for dot or cross multiplication symbol: - if( formatCode.at( 2 ) == QLatin1Char( 'c' ) ) + if (formatCode.at(2) == QLatin1Char('c')) mNumberMultiplyCross = true; - else if( formatCode.at( 2 ) == QLatin1Char( 'd' ) ) + else if (formatCode.at(2) == QLatin1Char('d')) mNumberMultiplyCross = false; else qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; } } - mLabelPainter.setSubstituteExponent( mNumberBeautifulPowers ); - mLabelPainter.setMultiplicationSymbol( mNumberMultiplyCross ? QCPLabelPainterPrivate::SymbolCross : QCPLabelPainterPrivate::SymbolDot ); + mLabelPainter.setSubstituteExponent(mNumberBeautifulPowers); + mLabelPainter.setMultiplicationSymbol(mNumberMultiplyCross ? QCPLabelPainterPrivate::SymbolCross : QCPLabelPainterPrivate::SymbolDot); } /*! @@ -32173,9 +31637,9 @@ void QCPPolarAxisRadial::setNumberFormat( const QString& formatCode ) for details. The effect of precisions are most notably for number Formats starting with 'e', see \ref setNumberFormat */ -void QCPPolarAxisRadial::setNumberPrecision( int precision ) +void QCPPolarAxisRadial::setNumberPrecision(int precision) { - if( mNumberPrecision != precision ) + if (mNumberPrecision != precision) { mNumberPrecision = precision; //mCachedMarginValid = false; @@ -32190,10 +31654,10 @@ void QCPPolarAxisRadial::setNumberPrecision( int precision ) \see setSubTickLength, setTickLengthIn, setTickLengthOut */ -void QCPPolarAxisRadial::setTickLength( int inside, int outside ) +void QCPPolarAxisRadial::setTickLength(int inside, int outside) { - setTickLengthIn( inside ); - setTickLengthOut( outside ); + setTickLengthIn(inside); + setTickLengthOut(outside); } /*! @@ -32202,9 +31666,9 @@ void QCPPolarAxisRadial::setTickLength( int inside, int outside ) \see setTickLengthOut, setTickLength, setSubTickLength */ -void QCPPolarAxisRadial::setTickLengthIn( int inside ) +void QCPPolarAxisRadial::setTickLengthIn(int inside) { - if( mTickLengthIn != inside ) + if (mTickLengthIn != inside) { mTickLengthIn = inside; } @@ -32217,9 +31681,9 @@ void QCPPolarAxisRadial::setTickLengthIn( int inside ) \see setTickLengthIn, setTickLength, setSubTickLength */ -void QCPPolarAxisRadial::setTickLengthOut( int outside ) +void QCPPolarAxisRadial::setTickLengthOut(int outside) { - if( mTickLengthOut != outside ) + if (mTickLengthOut != outside) { mTickLengthOut = outside; //mCachedMarginValid = false; // only outside tick length can change margin @@ -32233,9 +31697,9 @@ void QCPPolarAxisRadial::setTickLengthOut( int outside ) \see setTicks */ -void QCPPolarAxisRadial::setSubTicks( bool show ) +void QCPPolarAxisRadial::setSubTicks(bool show) { - if( mSubTicks != show ) + if (mSubTicks != show) { mSubTicks = show; //mCachedMarginValid = false; @@ -32250,10 +31714,10 @@ void QCPPolarAxisRadial::setSubTicks( bool show ) \see setTickLength, setSubTickLengthIn, setSubTickLengthOut */ -void QCPPolarAxisRadial::setSubTickLength( int inside, int outside ) +void QCPPolarAxisRadial::setSubTickLength(int inside, int outside) { - setSubTickLengthIn( inside ); - setSubTickLengthOut( outside ); + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); } /*! @@ -32262,9 +31726,9 @@ void QCPPolarAxisRadial::setSubTickLength( int inside, int outside ) \see setSubTickLengthOut, setSubTickLength, setTickLength */ -void QCPPolarAxisRadial::setSubTickLengthIn( int inside ) +void QCPPolarAxisRadial::setSubTickLengthIn(int inside) { - if( mSubTickLengthIn != inside ) + if (mSubTickLengthIn != inside) { mSubTickLengthIn = inside; } @@ -32277,9 +31741,9 @@ void QCPPolarAxisRadial::setSubTickLengthIn( int inside ) \see setSubTickLengthIn, setSubTickLength, setTickLength */ -void QCPPolarAxisRadial::setSubTickLengthOut( int outside ) +void QCPPolarAxisRadial::setSubTickLengthOut(int outside) { - if( mSubTickLengthOut != outside ) + if (mSubTickLengthOut != outside) { mSubTickLengthOut = outside; //mCachedMarginValid = false; // only outside tick length can change margin @@ -32291,7 +31755,7 @@ void QCPPolarAxisRadial::setSubTickLengthOut( int outside ) \see setTickPen, setSubTickPen */ -void QCPPolarAxisRadial::setBasePen( const QPen& pen ) +void QCPPolarAxisRadial::setBasePen(const QPen &pen) { mBasePen = pen; } @@ -32301,7 +31765,7 @@ void QCPPolarAxisRadial::setBasePen( const QPen& pen ) \see setTickLength, setBasePen */ -void QCPPolarAxisRadial::setTickPen( const QPen& pen ) +void QCPPolarAxisRadial::setTickPen(const QPen &pen) { mTickPen = pen; } @@ -32311,7 +31775,7 @@ void QCPPolarAxisRadial::setTickPen( const QPen& pen ) \see setSubTickCount, setSubTickLength, setBasePen */ -void QCPPolarAxisRadial::setSubTickPen( const QPen& pen ) +void QCPPolarAxisRadial::setSubTickPen(const QPen &pen) { mSubTickPen = pen; } @@ -32321,9 +31785,9 @@ void QCPPolarAxisRadial::setSubTickPen( const QPen& pen ) \see setLabelColor */ -void QCPPolarAxisRadial::setLabelFont( const QFont& font ) +void QCPPolarAxisRadial::setLabelFont(const QFont &font) { - if( mLabelFont != font ) + if (mLabelFont != font) { mLabelFont = font; //mCachedMarginValid = false; @@ -32335,7 +31799,7 @@ void QCPPolarAxisRadial::setLabelFont( const QFont& font ) \see setLabelFont */ -void QCPPolarAxisRadial::setLabelColor( const QColor& color ) +void QCPPolarAxisRadial::setLabelColor(const QColor &color) { mLabelColor = color; } @@ -32344,9 +31808,9 @@ void QCPPolarAxisRadial::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 QCPPolarAxisRadial::setLabel( const QString& str ) +void QCPPolarAxisRadial::setLabel(const QString &str) { - if( mLabel != str ) + if (mLabel != str) { mLabel = str; //mCachedMarginValid = false; @@ -32358,9 +31822,9 @@ void QCPPolarAxisRadial::setLabel( const QString& str ) \see setTickLabelPadding, setPadding */ -void QCPPolarAxisRadial::setLabelPadding( int padding ) +void QCPPolarAxisRadial::setLabelPadding(int padding) { - if( mLabelPadding != padding ) + if (mLabelPadding != padding) { mLabelPadding = padding; //mCachedMarginValid = false; @@ -32372,9 +31836,9 @@ void QCPPolarAxisRadial::setLabelPadding( int padding ) \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedTickLabelFont( const QFont& font ) +void QCPPolarAxisRadial::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 @@ -32386,7 +31850,7 @@ void QCPPolarAxisRadial::setSelectedTickLabelFont( const QFont& font ) \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedLabelFont( const QFont& font ) +void QCPPolarAxisRadial::setSelectedLabelFont(const QFont &font) { mSelectedLabelFont = font; // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts @@ -32397,9 +31861,9 @@ void QCPPolarAxisRadial::setSelectedLabelFont( const QFont& font ) \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedTickLabelColor( const QColor& color ) +void QCPPolarAxisRadial::setSelectedTickLabelColor(const QColor &color) { - if( color != mSelectedTickLabelColor ) + if (color != mSelectedTickLabelColor) { mSelectedTickLabelColor = color; } @@ -32410,7 +31874,7 @@ void QCPPolarAxisRadial::setSelectedTickLabelColor( const QColor& color ) \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedLabelColor( const QColor& color ) +void QCPPolarAxisRadial::setSelectedLabelColor(const QColor &color) { mSelectedLabelColor = color; } @@ -32420,7 +31884,7 @@ void QCPPolarAxisRadial::setSelectedLabelColor( const QColor& color ) \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedBasePen( const QPen& pen ) +void QCPPolarAxisRadial::setSelectedBasePen(const QPen &pen) { mSelectedBasePen = pen; } @@ -32430,7 +31894,7 @@ void QCPPolarAxisRadial::setSelectedBasePen( const QPen& pen ) \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedTickPen( const QPen& pen ) +void QCPPolarAxisRadial::setSelectedTickPen(const QPen &pen) { mSelectedTickPen = pen; } @@ -32440,7 +31904,7 @@ void QCPPolarAxisRadial::setSelectedTickPen( const QPen& pen ) \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisRadial::setSelectedSubTickPen( const QPen& pen ) +void QCPPolarAxisRadial::setSelectedSubTickPen(const QPen &pen) { mSelectedSubTickPen = pen; } @@ -32452,21 +31916,20 @@ void QCPPolarAxisRadial::setSelectedSubTickPen( const QPen& pen ) 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 QCPPolarAxisRadial::moveRange( double diff ) +void QCPPolarAxisRadial::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); } /*! @@ -32478,9 +31941,9 @@ void QCPPolarAxisRadial::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 QCPPolarAxisRadial::scaleRange( double factor ) +void QCPPolarAxisRadial::scaleRange(double factor) { - scaleRange( factor, range().center() ); + scaleRange(factor, range().center()); } /*! \overload @@ -32492,32 +31955,30 @@ void QCPPolarAxisRadial::scaleRange( double factor ) \see scaleRange(double factor) */ -void QCPPolarAxisRadial::scaleRange( double factor, double center ) +void QCPPolarAxisRadial::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); } /*! @@ -32526,9 +31987,9 @@ void QCPPolarAxisRadial::scaleRange( double factor, double center ) \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */ -void QCPPolarAxisRadial::rescale( bool onlyVisiblePlottables ) +void QCPPolarAxisRadial::rescale(bool onlyVisiblePlottables) { - Q_UNUSED( onlyVisiblePlottables ) + Q_UNUSED(onlyVisiblePlottables) /* TODO QList p = plottables(); QCPRange newRange; @@ -32578,66 +32039,65 @@ void QCPPolarAxisRadial::rescale( bool onlyVisiblePlottables ) /*! Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. */ -void QCPPolarAxisRadial::pixelToCoord( QPointF pixelPos, double& angleCoord, double& radiusCoord ) const +void QCPPolarAxisRadial::pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const { - QCPVector2D posVector( pixelPos - mCenter ); - radiusCoord = radiusToCoord( posVector.length() ); - angleCoord = mAngularAxis->angleRadToCoord( posVector.angle() ); + QCPVector2D posVector(pixelPos-mCenter); + radiusCoord = radiusToCoord(posVector.length()); + angleCoord = mAngularAxis->angleRadToCoord(posVector.angle()); } /*! Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. */ -QPointF QCPPolarAxisRadial::coordToPixel( double angleCoord, double radiusCoord ) const +QPointF QCPPolarAxisRadial::coordToPixel(double angleCoord, double radiusCoord) const { - const double radiusPixel = coordToRadius( radiusCoord ); - const double angleRad = mAngularAxis->coordToAngleRad( angleCoord ); - return QPointF( mCenter.x() + qCos( angleRad ) * radiusPixel, mCenter.y() + qSin( angleRad ) * radiusPixel ); + const double radiusPixel = coordToRadius(radiusCoord); + const double angleRad = mAngularAxis->coordToAngleRad(angleCoord); + return QPointF(mCenter.x()+qCos(angleRad)*radiusPixel, mCenter.y()+qSin(angleRad)*radiusPixel); } -double QCPPolarAxisRadial::coordToRadius( double coord ) const +double QCPPolarAxisRadial::coordToRadius(double coord) const { - if( mScaleType == stLinear ) + if (mScaleType == stLinear) { - if( !mRangeReversed ) - return ( coord - mRange.lower ) / mRange.size() * mRadius; + if (!mRangeReversed) + return (coord-mRange.lower)/mRange.size()*mRadius; else - return ( mRange.upper - coord ) / mRange.size() * mRadius; - } - else // mScaleType == stLogarithmic + return (mRange.upper-coord)/mRange.size()*mRadius; + } else // mScaleType == stLogarithmic { - if( coord >= 0.0 && mRange.upper < 0.0 ) // invalid value for logarithmic scale, just return outside visible range - return !mRangeReversed ? mRadius + 200 : mRadius - 200; - else if( coord <= 0.0 && mRange.upper >= 0.0 ) // invalid value for logarithmic scale, just return outside visible range - return !mRangeReversed ? mRadius - 200 : mRadius + 200; + if (coord >= 0.0 && mRange.upper < 0.0) // invalid value for logarithmic scale, just return outside visible range + return !mRangeReversed ? mRadius+200 : mRadius-200; + else if (coord <= 0.0 && mRange.upper >= 0.0) // invalid value for logarithmic scale, just return outside visible range + return !mRangeReversed ? mRadius-200 :mRadius+200; else { - if( !mRangeReversed ) - return qLn( coord / mRange.lower ) / qLn( mRange.upper / mRange.lower ) * mRadius; + if (!mRangeReversed) + return qLn(coord/mRange.lower)/qLn(mRange.upper/mRange.lower)*mRadius; else - return qLn( mRange.upper / coord ) / qLn( mRange.upper / mRange.lower ) * mRadius; + return qLn(mRange.upper/coord)/qLn(mRange.upper/mRange.lower)*mRadius; } } } -double QCPPolarAxisRadial::radiusToCoord( double radius ) const +double QCPPolarAxisRadial::radiusToCoord(double radius) const { - if( mScaleType == stLinear ) + if (mScaleType == stLinear) { - if( !mRangeReversed ) - return ( radius ) / mRadius * mRange.size() + mRange.lower; + if (!mRangeReversed) + return (radius)/mRadius*mRange.size()+mRange.lower; else - return -( radius ) / mRadius * mRange.size() + mRange.upper; - } - else // mScaleType == stLogarithmic + return -(radius)/mRadius*mRange.size()+mRange.upper; + } else // mScaleType == stLogarithmic { - if( !mRangeReversed ) - return qPow( mRange.upper / mRange.lower, ( radius ) / mRadius ) * mRange.lower; + if (!mRangeReversed) + return qPow(mRange.upper/mRange.lower, (radius)/mRadius)*mRange.lower; else - return qPow( mRange.upper / mRange.lower, ( -radius ) / mRadius ) * mRange.upper; + return qPow(mRange.upper/mRange.lower, (-radius)/mRadius)*mRange.upper; } } + /*! Returns the part of the axis that is hit by \a pos (in pixels). The return value of this function is independent of the user-selectable parts defined with \ref setSelectableParts. Further, this @@ -32647,12 +32107,12 @@ double QCPPolarAxisRadial::radiusToCoord( double radius ) const \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions */ -QCPPolarAxisRadial::SelectablePart QCPPolarAxisRadial::getPartAt( const QPointF& pos ) const +QCPPolarAxisRadial::SelectablePart QCPPolarAxisRadial::getPartAt(const QPointF &pos) const { - Q_UNUSED( pos ) // TODO remove later - if( !mVisible ) + Q_UNUSED(pos) // TODO remove later + if (!mVisible) return spNone; - + /* TODO: if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) @@ -32662,43 +32122,42 @@ QCPPolarAxisRadial::SelectablePart QCPPolarAxisRadial::getPartAt( const QPointF& else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) return spAxisLabel; else */ - return spNone; + return spNone; } /* inherits documentation from base class */ -double QCPPolarAxisRadial::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const +double QCPPolarAxisRadial::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const { - if( !mParentPlot ) + if (!mParentPlot) return -1; + SelectablePart part = getPartAt(pos); + if ((onlySelectable && !mSelectableParts.testFlag(part)) || part == spNone) return -1; - SelectablePart part = getPartAt( pos ); - if( ( onlySelectable && !mSelectableParts.testFlag( part ) ) || part == spNone ) - return -1; - - if( details ) - details->setValue( part ); - return mParentPlot->selectionTolerance() * 0.99; + + if (details) + details->setValue(part); + return mParentPlot->selectionTolerance()*0.99; } /* inherits documentation from base class */ -void QCPPolarAxisRadial::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) +void QCPPolarAxisRadial::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 QCPPolarAxisRadial::deselectEvent( bool* selectionStateChanged ) +void QCPPolarAxisRadial::deselectEvent(bool *selectionStateChanged) { SelectableParts selBefore = mSelectedParts; - setSelectedParts( mSelectedParts & ~mSelectableParts ); - if( selectionStateChanged ) + setSelectedParts(mSelectedParts & ~mSelectableParts); + if (selectionStateChanged) *selectionStateChanged = mSelectedParts != selBefore; } @@ -32717,26 +32176,26 @@ void QCPPolarAxisRadial::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 QCPPolarAxisRadial::mousePressEvent( QMouseEvent* event, const QVariant& details ) +void QCPPolarAxisRadial::mousePressEvent(QMouseEvent *event, const QVariant &details) { - Q_UNUSED( details ) - if( !mParentPlot->interactions().testFlag( QCP::iRangeDrag ) ) + Q_UNUSED(details) + if (!mParentPlot->interactions().testFlag(QCP::iRangeDrag)) { 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; } } @@ -32753,11 +32212,11 @@ void QCPPolarAxisRadial::mousePressEvent( QMouseEvent* event, const QVariant& de \see QCPAxis::mousePressEvent */ -void QCPPolarAxisRadial::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) +void QCPPolarAxisRadial::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) { - Q_UNUSED( event ) // TODO remove later - Q_UNUSED( startPos ) // TODO remove later - if( mDragging ) + Q_UNUSED(event) // TODO remove later + Q_UNUSED(startPos) // TODO remove later + if (mDragging) { /* TODO const double startPixel = orientation() == Qt::Horizontal ? startPos.x() : startPos.y(); @@ -32772,10 +32231,10 @@ void QCPPolarAxisRadial::mouseMoveEvent( QMouseEvent* event, const QPointF& star setRange(mDragStartRange.lower*diff, mDragStartRange.upper*diff); } */ - - if( mParentPlot->noAntialiasingOnDrag() ) - mParentPlot->setNotAntialiasedElements( QCP::aeAll ); - mParentPlot->replot( QCustomPlot::rpQueuedReplot ); + + if (mParentPlot->noAntialiasingOnDrag()) + mParentPlot->setNotAntialiasedElements(QCP::aeAll); + mParentPlot->replot(QCustomPlot::rpQueuedReplot); } } @@ -32791,15 +32250,15 @@ void QCPPolarAxisRadial::mouseMoveEvent( QMouseEvent* event, const QPointF& star \see QCPAxis::mousePressEvent */ -void QCPPolarAxisRadial::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) +void QCPPolarAxisRadial::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); } } @@ -32818,15 +32277,15 @@ void QCPPolarAxisRadial::mouseReleaseEvent( QMouseEvent* event, const QPointF& s \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 QCPPolarAxisRadial::wheelEvent( QWheelEvent* event ) +void QCPPolarAxisRadial::wheelEvent(QWheelEvent *event) { // Mouse range zooming interaction: - if( !mParentPlot->interactions().testFlag( QCP::iRangeZoom ) ) + if (!mParentPlot->interactions().testFlag(QCP::iRangeZoom)) { event->ignore(); return; } - + // TODO: //const double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually //const double factor = qPow(mRangeZoomFactor, wheelSteps); @@ -32834,12 +32293,11 @@ void QCPPolarAxisRadial::wheelEvent( QWheelEvent* event ) mParentPlot->replot(); } -void QCPPolarAxisRadial::updateGeometry( const QPointF& center, double radius ) +void QCPPolarAxisRadial::updateGeometry(const QPointF ¢er, double radius) { mCenter = center; mRadius = radius; - if( mRadius < 1 ) - mRadius = 1; + if (mRadius < 1) mRadius = 1; } /*! \internal @@ -32857,9 +32315,9 @@ void QCPPolarAxisRadial::updateGeometry( const QPointF& center, double radius ) \see setAntialiased */ -void QCPPolarAxisRadial::applyDefaultAntialiasingHint( QCPPainter* painter ) const +void QCPPolarAxisRadial::applyDefaultAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiased, QCP::aeAxes ); + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); } /*! \internal @@ -32868,46 +32326,46 @@ void QCPPolarAxisRadial::applyDefaultAntialiasingHint( QCPPainter* painter ) con \seebaseclassmethod */ -void QCPPolarAxisRadial::draw( QCPPainter* painter ) +void QCPPolarAxisRadial::draw(QCPPainter *painter) { - const double axisAngleRad = ( mAngle + ( mAngleReference == arAngularAxis ? mAngularAxis->angle() : 0 ) ) / 180.0 * M_PI; - const QPointF axisVector( qCos( axisAngleRad ), qSin( axisAngleRad ) ); // semantically should be QCPVector2D, but we save time in loops when we keep it as QPointF - const QPointF tickNormal = QCPVector2D( axisVector ).perpendicular().toPointF(); // semantically should be QCPVector2D, but we save time in loops when we keep it as QPointF - + const double axisAngleRad = (mAngle+(mAngleReference==arAngularAxis ? mAngularAxis->angle() : 0))/180.0*M_PI; + const QPointF axisVector(qCos(axisAngleRad), qSin(axisAngleRad)); // semantically should be QCPVector2D, but we save time in loops when we keep it as QPointF + const QPointF tickNormal = QCPVector2D(axisVector).perpendicular().toPointF(); // semantically should be QCPVector2D, but we save time in loops when we keep it as QPointF + // draw baseline: - painter->setPen( getBasePen() ); - painter->drawLine( QLineF( mCenter, mCenter + axisVector * ( mRadius - 0.5 ) ) ); - + painter->setPen(getBasePen()); + painter->drawLine(QLineF(mCenter, mCenter+axisVector*(mRadius-0.5))); + // draw subticks: - if( !mSubTickVector.isEmpty() ) + if (!mSubTickVector.isEmpty()) { - painter->setPen( getSubTickPen() ); - for( int i = 0; i < mSubTickVector.size(); ++i ) + painter->setPen(getSubTickPen()); + for (int i=0; idrawLine( QLineF( tickPosition - tickNormal * mSubTickLengthIn, tickPosition + tickNormal * mSubTickLengthOut ) ); + const QPointF tickPosition = mCenter+axisVector*coordToRadius(mSubTickVector.at(i)); + painter->drawLine(QLineF(tickPosition-tickNormal*mSubTickLengthIn, tickPosition+tickNormal*mSubTickLengthOut)); } } - + // draw ticks and labels: - if( !mTickVector.isEmpty() ) + if (!mTickVector.isEmpty()) { - mLabelPainter.setAnchorReference( mCenter - axisVector ); // subtract (normalized) axisVector, just to prevent degenerate tangents for tick label at exact lower axis range - mLabelPainter.setFont( getTickLabelFont() ); - mLabelPainter.setColor( getTickLabelColor() ); + mLabelPainter.setAnchorReference(mCenter-axisVector); // subtract (normalized) axisVector, just to prevent degenerate tangents for tick label at exact lower axis range + mLabelPainter.setFont(getTickLabelFont()); + mLabelPainter.setColor(getTickLabelColor()); const QPen ticksPen = getTickPen(); - painter->setPen( ticksPen ); - for( int i = 0; i < mTickVector.size(); ++i ) + painter->setPen(ticksPen); + for (int i=0; idrawLine( QLineF( tickPosition - tickNormal * mTickLengthIn, tickPosition + tickNormal * mTickLengthOut ) ); + const double r = coordToRadius(mTickVector.at(i)); + const QPointF tickPosition = mCenter+axisVector*r; + painter->drawLine(QLineF(tickPosition-tickNormal*mTickLengthIn, tickPosition+tickNormal*mTickLengthOut)); // possibly draw tick labels: - if( !mTickVectorLabels.isEmpty() ) + if (!mTickVectorLabels.isEmpty()) { - if( ( !mRangeReversed && ( i < mTickVectorLabels.count() - 1 || mRadius - r > 10 ) ) || - ( mRangeReversed && ( i > 0 || mRadius - r > 10 ) ) ) // skip last label if it's closer than 10 pixels to angular axis - mLabelPainter.drawTickLabel( painter, tickPosition + tickNormal * mSubTickLengthOut, mTickVectorLabels.at( i ) ); + if ((!mRangeReversed && (i < mTickVectorLabels.count()-1 || mRadius-r > 10)) || + (mRangeReversed && (i > 0 || mRadius-r > 10))) // skip last label if it's closer than 10 pixels to angular axis + mLabelPainter.drawTickLabel(painter, tickPosition+tickNormal*mSubTickLengthOut, mTickVectorLabels.at(i)); } } } @@ -32923,12 +32381,10 @@ void QCPPolarAxisRadial::draw( QCPPainter* painter ) */ void QCPPolarAxisRadial::setupTickVectors() { - if( !mParentPlot ) - return; - if( ( !mTicks && !mTickLabels ) || mRange.size() <= 0 ) - return; - - mTicker->generate( mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0 ); + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels) || mRange.size() <= 0) return; + + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); } /*! \internal @@ -32938,7 +32394,7 @@ void QCPPolarAxisRadial::setupTickVectors() */ QPen QCPPolarAxisRadial::getBasePen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedBasePen : mBasePen; + return mSelectedParts.testFlag(spAxis) ? mSelectedBasePen : mBasePen; } /*! \internal @@ -32948,7 +32404,7 @@ QPen QCPPolarAxisRadial::getBasePen() const */ QPen QCPPolarAxisRadial::getTickPen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedTickPen : mTickPen; + return mSelectedParts.testFlag(spAxis) ? mSelectedTickPen : mTickPen; } /*! \internal @@ -32958,7 +32414,7 @@ QPen QCPPolarAxisRadial::getTickPen() const */ QPen QCPPolarAxisRadial::getSubTickPen() const { - return mSelectedParts.testFlag( spAxis ) ? mSelectedSubTickPen : mSubTickPen; + return mSelectedParts.testFlag(spAxis) ? mSelectedSubTickPen : mSubTickPen; } /*! \internal @@ -32968,7 +32424,7 @@ QPen QCPPolarAxisRadial::getSubTickPen() const */ QFont QCPPolarAxisRadial::getTickLabelFont() const { - return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelFont : mTickLabelFont; + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelFont : mTickLabelFont; } /*! \internal @@ -32978,7 +32434,7 @@ QFont QCPPolarAxisRadial::getTickLabelFont() const */ QFont QCPPolarAxisRadial::getLabelFont() const { - return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelFont : mLabelFont; + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelFont : mLabelFont; } /*! \internal @@ -32988,7 +32444,7 @@ QFont QCPPolarAxisRadial::getLabelFont() const */ QColor QCPPolarAxisRadial::getTickLabelColor() const { - return mSelectedParts.testFlag( spTickLabels ) ? mSelectedTickLabelColor : mTickLabelColor; + return mSelectedParts.testFlag(spTickLabels) ? mSelectedTickLabelColor : mTickLabelColor; } /*! \internal @@ -32998,9 +32454,10 @@ QColor QCPPolarAxisRadial::getTickLabelColor() const */ QColor QCPPolarAxisRadial::getLabelColor() const { - return mSelectedParts.testFlag( spAxisLabel ) ? mSelectedLabelColor : mLabelColor; + return mSelectedParts.testFlag(spAxisLabel) ? mSelectedLabelColor : mLabelColor; } + /* inherits documentation from base class */ QCP::Interaction QCPPolarAxisRadial::selectionCategory() const { @@ -33008,8 +32465,10 @@ QCP::Interaction QCPPolarAxisRadial::selectionCategory() const } /* end of 'src/polar/radialaxis.cpp' */ + /* including file 'src/polar/layoutelement-angularaxis.cpp' */ -/* modified 2021-03-29T02:30:44, size 57266 */ +/* modified 2022-11-06T12:45:57, size 57266 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPolarAxisAngular @@ -33110,112 +32569,108 @@ QCP::Interaction QCPPolarAxisRadial::selectionCategory() const Creates a QCPPolarAxis instance and sets default values. An axis is added for each of the four sides, the top and right axes are set invisible initially. */ -QCPPolarAxisAngular::QCPPolarAxisAngular( QCustomPlot* parentPlot ) - : QCPLayoutElement( parentPlot ), mBackgroundBrush( Qt::NoBrush ), mBackgroundScaled( true ), mBackgroundScaledMode( Qt::KeepAspectRatioByExpanding ), mInsetLayout( new QCPLayoutInset ), mRangeDrag( false ), mRangeZoom( false ), mRangeZoomFactor( 0.85 ), - // axis base: - mAngle( -90 ) - , mAngleRad( mAngle / 180.0 * M_PI ) - , mSelectableParts( spAxis | spTickLabels | spAxisLabel ) - , mSelectedParts( spNone ) - , mBasePen( QPen( Qt::black, 0, Qt::SolidLine, Qt::SquareCap ) ) - , mSelectedBasePen( QPen( Qt::blue, 2 ) ) - , - // axis label: - mLabelPadding( 0 ) - , mLabel() - , mLabelFont( mParentPlot->font() ) - , mSelectedLabelFont( QFont( mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold ) ) - , mLabelColor( Qt::black ) - , mSelectedLabelColor( Qt::blue ) - , - // tick labels: - //mTickLabelPadding(0), in label painter - mTickLabels( true ) - , - //mTickLabelRotation(0), in label painter - mTickLabelFont( mParentPlot->font() ) - , mSelectedTickLabelFont( QFont( mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold ) ) - , mTickLabelColor( Qt::black ) - , mSelectedTickLabelColor( Qt::blue ) - , mNumberPrecision( 6 ) - , mNumberFormatChar( 'g' ) - , mNumberBeautifulPowers( true ) - , mNumberMultiplyCross( false ) - , - // ticks and subticks: - mTicks( true ) - , mSubTicks( true ) - , mTickLengthIn( 5 ) - , mTickLengthOut( 0 ) - , mSubTickLengthIn( 2 ) - , mSubTickLengthOut( 0 ) - , 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, 360 ) - , mRangeReversed( false ) - , - // internal members: - mRadius( 1 ) - , // non-zero initial value, will be overwritten in ::update() according to inner rect - mGrid( new QCPPolarGrid( this ) ) - , mTicker( new QCPAxisTickerFixed ) - , mDragging( false ) - , mLabelPainter( parentPlot ) +QCPPolarAxisAngular::QCPPolarAxisAngular(QCustomPlot *parentPlot) : + QCPLayoutElement(parentPlot), + mBackgroundBrush(Qt::NoBrush), + mBackgroundScaled(true), + mBackgroundScaledMode(Qt::KeepAspectRatioByExpanding), + mInsetLayout(new QCPLayoutInset), + mRangeDrag(false), + mRangeZoom(false), + mRangeZoomFactor(0.85), + // axis base: + mAngle(-90), + mAngleRad(mAngle/180.0*M_PI), + mSelectableParts(spAxis | spTickLabels | spAxisLabel), + mSelectedParts(spNone), + mBasePen(QPen(Qt::black, 0, Qt::SolidLine, Qt::SquareCap)), + mSelectedBasePen(QPen(Qt::blue, 2)), + // axis label: + mLabelPadding(0), + mLabel(), + mLabelFont(mParentPlot->font()), + mSelectedLabelFont(QFont(mLabelFont.family(), mLabelFont.pointSize(), QFont::Bold)), + mLabelColor(Qt::black), + mSelectedLabelColor(Qt::blue), + // tick labels: + //mTickLabelPadding(0), in label painter + mTickLabels(true), + //mTickLabelRotation(0), in label painter + mTickLabelFont(mParentPlot->font()), + mSelectedTickLabelFont(QFont(mTickLabelFont.family(), mTickLabelFont.pointSize(), QFont::Bold)), + mTickLabelColor(Qt::black), + mSelectedTickLabelColor(Qt::blue), + mNumberPrecision(6), + mNumberFormatChar('g'), + mNumberBeautifulPowers(true), + mNumberMultiplyCross(false), + // ticks and subticks: + mTicks(true), + mSubTicks(true), + mTickLengthIn(5), + mTickLengthOut(0), + mSubTickLengthIn(2), + mSubTickLengthOut(0), + 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, 360), + mRangeReversed(false), + // internal members: + mRadius(1), // non-zero initial value, will be overwritten in ::update() according to inner rect + mGrid(new QCPPolarGrid(this)), + mTicker(new QCPAxisTickerFixed), + mDragging(false), + mLabelPainter(parentPlot) { // TODO: //mInsetLayout->initializeParentPlot(mParentPlot); //mInsetLayout->setParentLayerable(this); //mInsetLayout->setParent(this); - - if( QCPAxisTickerFixed* fixedTicker = mTicker.dynamicCast().data() ) + + if (QCPAxisTickerFixed *fixedTicker = mTicker.dynamicCast().data()) { - fixedTicker->setTickStep( 30 ); + fixedTicker->setTickStep(30); } - setAntialiased( true ); - 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 - - setTickLabelPadding( 5 ); - setTickLabelRotation( 0 ); - setTickLabelMode( lmUpright ); - mLabelPainter.setAnchorReferenceType( QCPLabelPainterPrivate::artNormal ); - mLabelPainter.setAbbreviateDecimalPowers( false ); - mLabelPainter.setCacheSize( 24 ); // so we can cache up to 15-degree intervals, polar angular axis uses a bit larger cache than normal axes - - setMinimumSize( 50, 50 ); - setMinimumMargins( QMargins( 30, 30, 30, 30 ) ); - + setAntialiased(true); + 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 + + setTickLabelPadding(5); + setTickLabelRotation(0); + setTickLabelMode(lmUpright); + mLabelPainter.setAnchorReferenceType(QCPLabelPainterPrivate::artNormal); + mLabelPainter.setAbbreviateDecimalPowers(false); + mLabelPainter.setCacheSize(24); // so we can cache up to 15-degree intervals, polar angular axis uses a bit larger cache than normal axes + + setMinimumSize(50, 50); + setMinimumMargins(QMargins(30, 30, 30, 30)); + addRadialAxis(); - mGrid->setRadialAxis( radialAxis() ); + mGrid->setRadialAxis(radialAxis()); } QCPPolarAxisAngular::~QCPPolarAxisAngular() { - 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 mGrid = 0; - + delete mInsetLayout; mInsetLayout = 0; - + QList radialAxesList = radialAxes(); - for( int i = 0; i < radialAxesList.size(); ++i ) - removeRadialAxis( radialAxesList.at( i ) ); + for (int i=0; i= 0 && index < mRadialAxes.size() ) + if (index >= 0 && index < mRadialAxes.size()) { - return mRadialAxes.at( index ); - } - else + return mRadialAxes.at(index); + } else { qDebug() << Q_FUNC_INFO << "Axis index out of bounds:" << index; return 0; @@ -33275,6 +32729,7 @@ QList QCPPolarAxisAngular::radialAxes() const return mRadialAxes; } + /*! Adds a new axis to the axis rect side specified with \a type, and returns it. If \a axis is 0, a new QCPAxis instance is created internally. QCustomPlot owns the returned axis, so if you want to @@ -33295,27 +32750,26 @@ QList QCPPolarAxisAngular::radialAxes() const \see addAxes, setupFullAxesBox */ -QCPPolarAxisRadial* QCPPolarAxisAngular::addRadialAxis( QCPPolarAxisRadial* axis ) +QCPPolarAxisRadial *QCPPolarAxisAngular::addRadialAxis(QCPPolarAxisRadial *axis) { - QCPPolarAxisRadial* newAxis = axis; - if( !newAxis ) + QCPPolarAxisRadial *newAxis = axis; + if (!newAxis) { - newAxis = new QCPPolarAxisRadial( this ); - } - else // user provided existing axis instance, do some sanity checks + newAxis = new QCPPolarAxisRadial(this); + } else // user provided existing axis instance, do some sanity checks { - if( newAxis->angularAxis() != this ) + if (newAxis->angularAxis() != this) { qDebug() << Q_FUNC_INFO << "passed radial axis doesn't have this angular axis as parent angular axis"; return 0; } - if( radialAxes().contains( newAxis ) ) + if (radialAxes().contains(newAxis)) { qDebug() << Q_FUNC_INFO << "passed axis is already owned by this angular axis"; return 0; } } - mRadialAxes.append( newAxis ); + mRadialAxes.append(newAxis); return newAxis; } @@ -33326,24 +32780,23 @@ QCPPolarAxisRadial* QCPPolarAxisAngular::addRadialAxis( QCPPolarAxisRadial* axis \see addAxis */ -bool QCPPolarAxisAngular::removeRadialAxis( QCPPolarAxisRadial* radialAxis ) +bool QCPPolarAxisAngular::removeRadialAxis(QCPPolarAxisRadial *radialAxis) { - if( mRadialAxes.contains( radialAxis ) ) + if (mRadialAxes.contains(radialAxis)) { - mRadialAxes.removeOne( radialAxis ); + mRadialAxes.removeOne(radialAxis); delete radialAxis; return true; - } - else + } else { - qDebug() << Q_FUNC_INFO << "Radial axis isn't associated with this angular axis:" << reinterpret_cast( radialAxis ); + qDebug() << Q_FUNC_INFO << "Radial axis isn't associated with this angular axis:" << reinterpret_cast(radialAxis); return false; } } QRegion QCPPolarAxisAngular::exactClipRegion() const { - return QRegion( mCenter.x() - mRadius, mCenter.y() - mRadius, qRound( 2 * mRadius ), qRound( 2 * mRadius ), QRegion::Ellipse ); + return QRegion(mCenter.x()-mRadius, mCenter.y()-mRadius, qRound(2*mRadius), qRound(2*mRadius), QRegion::Ellipse); } /*! @@ -33353,13 +32806,13 @@ QRegion QCPPolarAxisAngular::exactClipRegion() const 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 QCPPolarAxisAngular::moveRange( double diff ) +void QCPPolarAxisAngular::moveRange(double diff) { QCPRange oldRange = mRange; mRange.lower += diff; mRange.upper += diff; - emit rangeChanged( mRange ); - emit rangeChanged( mRange, oldRange ); + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); } /*! @@ -33371,9 +32824,9 @@ void QCPPolarAxisAngular::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 QCPPolarAxisAngular::scaleRange( double factor ) +void QCPPolarAxisAngular::scaleRange(double factor) { - scaleRange( factor, range().center() ); + scaleRange(factor, range().center()); } /*! \overload @@ -33385,16 +32838,16 @@ void QCPPolarAxisAngular::scaleRange( double factor ) \see scaleRange(double factor) */ -void QCPPolarAxisAngular::scaleRange( double factor, double center ) +void QCPPolarAxisAngular::scaleRange(double factor, double center) { QCPRange oldRange = mRange; 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(); - emit rangeChanged( mRange ); - emit rangeChanged( mRange, oldRange ); + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); } /*! @@ -33403,48 +32856,48 @@ void QCPPolarAxisAngular::scaleRange( double factor, double center ) \see QCPAbstractPlottable::rescaleAxes, QCustomPlot::rescaleAxes */ -void QCPPolarAxisAngular::rescale( bool onlyVisiblePlottables ) +void QCPPolarAxisAngular::rescale(bool onlyVisiblePlottables) { QCPRange newRange; bool haveRange = false; - for( int i = 0; i < mGraphs.size(); ++i ) + for (int i=0; irealVisibility() && onlyVisiblePlottables ) + if (!mGraphs.at(i)->realVisibility() && onlyVisiblePlottables) continue; QCPRange range; bool currentFoundRange; - if( mGraphs.at( i )->keyAxis() == this ) - range = mGraphs.at( i )->getKeyRange( currentFoundRange, QCP::sdBoth ); + if (mGraphs.at(i)->keyAxis() == this) + range = mGraphs.at(i)->getKeyRange(currentFoundRange, QCP::sdBoth); else - range = mGraphs.at( i )->getValueRange( currentFoundRange, QCP::sdBoth ); - if( currentFoundRange ) + range = mGraphs.at(i)->getValueRange(currentFoundRange, QCP::sdBoth); + if (currentFoundRange) { - if( !haveRange ) + if (!haveRange) newRange = range; else - newRange.expand( range ); + newRange.expand(range); 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 - newRange.lower = center - mRange.size() / 2.0; - newRange.upper = center + mRange.size() / 2.0; + 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 + newRange.lower = center-mRange.size()/2.0; + newRange.upper = center+mRange.size()/2.0; } - setRange( newRange ); + setRange(newRange); } } /*! Transforms \a value, in pixel coordinates of the QCustomPlot widget, to axis coordinates. */ -void QCPPolarAxisAngular::pixelToCoord( QPointF pixelPos, double& angleCoord, double& radiusCoord ) const +void QCPPolarAxisAngular::pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const { - if( !mRadialAxes.isEmpty() ) - mRadialAxes.first()->pixelToCoord( pixelPos, angleCoord, radiusCoord ); + if (!mRadialAxes.isEmpty()) + mRadialAxes.first()->pixelToCoord(pixelPos, angleCoord, radiusCoord); else qDebug() << Q_FUNC_INFO << "no radial axis configured"; } @@ -33452,13 +32905,12 @@ void QCPPolarAxisAngular::pixelToCoord( QPointF pixelPos, double& angleCoord, do /*! Transforms \a value, in coordinates of the axis, to pixel coordinates of the QCustomPlot widget. */ -QPointF QCPPolarAxisAngular::coordToPixel( double angleCoord, double radiusCoord ) const +QPointF QCPPolarAxisAngular::coordToPixel(double angleCoord, double radiusCoord) const { - if( !mRadialAxes.isEmpty() ) + if (!mRadialAxes.isEmpty()) { - return mRadialAxes.first()->coordToPixel( angleCoord, radiusCoord ); - } - else + return mRadialAxes.first()->coordToPixel(angleCoord, radiusCoord); + } else { qDebug() << Q_FUNC_INFO << "no radial axis configured"; return QPointF(); @@ -33474,13 +32926,13 @@ QPointF QCPPolarAxisAngular::coordToPixel( double angleCoord, double radiusCoord \see setSelectedParts, setSelectableParts, QCustomPlot::setInteractions */ -QCPPolarAxisAngular::SelectablePart QCPPolarAxisAngular::getPartAt( const QPointF& pos ) const +QCPPolarAxisAngular::SelectablePart QCPPolarAxisAngular::getPartAt(const QPointF &pos) const { - Q_UNUSED( pos ) // TODO remove later - - if( !mVisible ) + Q_UNUSED(pos) // TODO remove later + + if (!mVisible) return spNone; - + /* TODO: if (mAxisPainter->axisSelectionBox().contains(pos.toPoint())) @@ -33490,11 +32942,11 @@ QCPPolarAxisAngular::SelectablePart QCPPolarAxisAngular::getPartAt( const QPoint else if (mAxisPainter->labelSelectionBox().contains(pos.toPoint())) return spAxisLabel; else */ - return spNone; + return spNone; } /* inherits documentation from base class */ -double QCPPolarAxisAngular::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const +double QCPPolarAxisAngular::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const { /* if (!mParentPlot) return -1; @@ -33506,23 +32958,22 @@ double QCPPolarAxisAngular::selectTest( const QPointF& pos, bool onlySelectable, details->setValue(part); return mParentPlot->selectionTolerance()*0.99; */ - - 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; } @@ -33536,109 +32987,109 @@ double QCPPolarAxisAngular::selectTest( const QPointF& pos, bool onlySelectable, \seebaseclassmethod */ -void QCPPolarAxisAngular::update( UpdatePhase phase ) +void QCPPolarAxisAngular::update(UpdatePhase phase) { - QCPLayoutElement::update( phase ); - - switch( phase ) + QCPLayoutElement::update(phase); + + switch (phase) { - case upPreparation: { - setupTickVectors(); - for( int i = 0; i < mRadialAxes.size(); ++i ) - mRadialAxes.at( i )->setupTickVectors(); - break; + case upPreparation: + { + setupTickVectors(); + for (int i=0; isetupTickVectors(); + break; + } + case upLayout: + { + mCenter = mRect.center(); + mRadius = 0.5*qMin(qAbs(mRect.width()), qAbs(mRect.height())); + if (mRadius < 1) mRadius = 1; // prevent cases where radius might become 0 which causes trouble + for (int i=0; iupdateGeometry(mCenter, mRadius); + + mInsetLayout->setOuterRect(rect()); + break; + } + default: break; } - case upLayout: { - mCenter = mRect.center(); - mRadius = 0.5 * qMin( qAbs( mRect.width() ), qAbs( mRect.height() ) ); - if( mRadius < 1 ) - mRadius = 1; // prevent cases where radius might become 0 which causes trouble - for( int i = 0; i < mRadialAxes.size(); ++i ) - mRadialAxes.at( i )->updateGeometry( mCenter, mRadius ); - - mInsetLayout->setOuterRect( rect() ); - break; - } - default: - break; - } - + // pass update call on to inset layout (doesn't happen automatically, because QCPPolarAxis doesn't derive from QCPLayout): - mInsetLayout->update( phase ); + mInsetLayout->update(phase); } /* inherits documentation from base class */ -QList QCPPolarAxisAngular::elements( bool recursive ) const +QList QCPPolarAxisAngular::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; } -bool QCPPolarAxisAngular::removeGraph( QCPPolarGraph* graph ) +bool QCPPolarAxisAngular::removeGraph(QCPPolarGraph *graph) { - if( !mGraphs.contains( graph ) ) + if (!mGraphs.contains(graph)) { - qDebug() << Q_FUNC_INFO << "graph not in list:" << reinterpret_cast( graph ); + qDebug() << Q_FUNC_INFO << "graph not in list:" << reinterpret_cast(graph); return false; } - + // remove plottable from legend: graph->removeFromLegend(); // remove plottable: delete graph; - mGraphs.removeOne( graph ); + mGraphs.removeOne(graph); return true; } /* inherits documentation from base class */ -void QCPPolarAxisAngular::applyDefaultAntialiasingHint( QCPPainter* painter ) const +void QCPPolarAxisAngular::applyDefaultAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiased, QCP::aeAxes ); + applyAntialiasingHint(painter, mAntialiased, QCP::aeAxes); } /* inherits documentation from base class */ -void QCPPolarAxisAngular::draw( QCPPainter* painter ) +void QCPPolarAxisAngular::draw(QCPPainter *painter) { - drawBackground( painter, mCenter, mRadius ); - + drawBackground(painter, mCenter, mRadius); + // draw baseline circle: - painter->setPen( getBasePen() ); - painter->drawEllipse( mCenter, mRadius, mRadius ); - + painter->setPen(getBasePen()); + painter->drawEllipse(mCenter, mRadius, mRadius); + // draw subticks: - if( !mSubTickVector.isEmpty() ) + if (!mSubTickVector.isEmpty()) { - painter->setPen( getSubTickPen() ); - for( int i = 0; i < mSubTickVector.size(); ++i ) + painter->setPen(getSubTickPen()); + for (int i=0; idrawLine( mCenter + mSubTickVectorCosSin.at( i ) * ( mRadius - mSubTickLengthIn ), - mCenter + mSubTickVectorCosSin.at( i ) * ( mRadius + mSubTickLengthOut ) ); + painter->drawLine(mCenter+mSubTickVectorCosSin.at(i)*(mRadius-mSubTickLengthIn), + mCenter+mSubTickVectorCosSin.at(i)*(mRadius+mSubTickLengthOut)); } } - + // draw ticks and labels: - if( !mTickVector.isEmpty() ) + if (!mTickVector.isEmpty()) { - mLabelPainter.setAnchorReference( mCenter ); - mLabelPainter.setFont( getTickLabelFont() ); - mLabelPainter.setColor( getTickLabelColor() ); + mLabelPainter.setAnchorReference(mCenter); + mLabelPainter.setFont(getTickLabelFont()); + mLabelPainter.setColor(getTickLabelColor()); const QPen ticksPen = getTickPen(); - painter->setPen( ticksPen ); - for( int i = 0; i < mTickVector.size(); ++i ) + painter->setPen(ticksPen); + for (int i=0; idrawLine( mCenter + mTickVectorCosSin.at( i ) * ( mRadius - mTickLengthIn ), outerTick ); + const QPointF outerTick = mCenter+mTickVectorCosSin.at(i)*(mRadius+mTickLengthOut); + painter->drawLine(mCenter+mTickVectorCosSin.at(i)*(mRadius-mTickLengthIn), outerTick); // draw tick labels: - if( !mTickVectorLabels.isEmpty() ) + if (!mTickVectorLabels.isEmpty()) { - if( i < mTickVectorLabels.count() - 1 || ( mTickVectorCosSin.at( i ) - mTickVectorCosSin.first() ).manhattanLength() > 5 / 180.0 * M_PI ) // skip last label if it's closer than approx 5 degrees to first - mLabelPainter.drawTickLabel( painter, outerTick, mTickVectorLabels.at( i ) ); + if (i < mTickVectorLabels.count()-1 || (mTickVectorCosSin.at(i)-mTickVectorCosSin.first()).manhattanLength() > 5/180.0*M_PI) // skip last label if it's closer than approx 5 degrees to first + mLabelPainter.drawTickLabel(painter, outerTick, mTickVectorLabels.at(i)); } } } @@ -33650,6 +33101,7 @@ QCP::Interaction QCPPolarAxisAngular::selectionCategory() const return QCP::iSelectAxes; } + /*! Sets \a pm as the axis background pixmap. The axis background pixmap will be drawn inside the axis rect. Since axis rects place themselves on the "background" layer by default, the axis rect @@ -33665,7 +33117,7 @@ QCP::Interaction QCPPolarAxisAngular::selectionCategory() const \see setBackgroundScaled, setBackgroundScaledMode, setBackground(const QBrush &brush) */ -void QCPPolarAxisAngular::setBackground( const QPixmap& pm ) +void QCPPolarAxisAngular::setBackground(const QPixmap &pm) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -33684,7 +33136,7 @@ void QCPPolarAxisAngular::setBackground( const QPixmap& pm ) \see setBackground(const QPixmap &pm) */ -void QCPPolarAxisAngular::setBackground( const QBrush& brush ) +void QCPPolarAxisAngular::setBackground(const QBrush &brush) { mBackgroundBrush = brush; } @@ -33696,7 +33148,7 @@ void QCPPolarAxisAngular::setBackground( const QBrush& brush ) \see setBackground(const QPixmap &pm), setBackgroundScaled, setBackgroundScaledMode */ -void QCPPolarAxisAngular::setBackground( const QPixmap& pm, bool scaled, Qt::AspectRatioMode mode ) +void QCPPolarAxisAngular::setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode) { mBackgroundPixmap = pm; mScaledBackgroundPixmap = QPixmap(); @@ -33714,7 +33166,7 @@ void QCPPolarAxisAngular::setBackground( const QPixmap& pm, bool scaled, Qt::Asp \see setBackground, setBackgroundScaledMode */ -void QCPPolarAxisAngular::setBackgroundScaled( bool scaled ) +void QCPPolarAxisAngular::setBackgroundScaled(bool scaled) { mBackgroundScaled = scaled; } @@ -33724,26 +33176,32 @@ void QCPPolarAxisAngular::setBackgroundScaled( bool scaled ) define whether and how the aspect ratio of the original pixmap passed to \ref setBackground is preserved. \see setBackground, setBackgroundScaled */ -void QCPPolarAxisAngular::setBackgroundScaledMode( Qt::AspectRatioMode mode ) +void QCPPolarAxisAngular::setBackgroundScaledMode(Qt::AspectRatioMode mode) { mBackgroundScaledMode = mode; } -void QCPPolarAxisAngular::setRangeDrag( bool enabled ) +void QCPPolarAxisAngular::setRangeDrag(bool enabled) { mRangeDrag = enabled; } -void QCPPolarAxisAngular::setRangeZoom( bool enabled ) +void QCPPolarAxisAngular::setRangeZoom(bool enabled) { mRangeZoom = enabled; } -void QCPPolarAxisAngular::setRangeZoomFactor( double factor ) +void QCPPolarAxisAngular::setRangeZoomFactor(double factor) { mRangeZoomFactor = factor; } + + + + + + /*! Sets the range of the axis. @@ -33752,17 +33210,16 @@ void QCPPolarAxisAngular::setRangeZoomFactor( double factor ) To invert the direction of an axis, use \ref setRangeReversed. */ -void QCPPolarAxisAngular::setRange( const QCPRange& range ) +void QCPPolarAxisAngular::setRange(const QCPRange &range) { - if( range.lower == mRange.lower && range.upper == mRange.upper ) - return; - - if( !QCPRange::validRange( range ) ) + if (range.lower == mRange.lower && range.upper == mRange.upper) return; + + if (!QCPRange::validRange(range)) return; QCPRange oldRange = mRange; mRange = range.sanitizedForLinScale(); - emit rangeChanged( mRange ); - emit rangeChanged( mRange, oldRange ); + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); } /*! @@ -33775,12 +33232,12 @@ void QCPPolarAxisAngular::setRange( const QCPRange& range ) \see SelectablePart, setSelectedParts */ -void QCPPolarAxisAngular::setSelectableParts( const SelectableParts& selectable ) +void QCPPolarAxisAngular::setSelectableParts(const SelectableParts &selectable) { - if( mSelectableParts != selectable ) + if (mSelectableParts != selectable) { mSelectableParts = selectable; - emit selectableChanged( mSelectableParts ); + emit selectableChanged(mSelectableParts); } } @@ -33799,12 +33256,12 @@ void QCPPolarAxisAngular::setSelectableParts( const SelectableParts& selectable \see SelectablePart, setSelectableParts, selectTest, setSelectedBasePen, setSelectedTickPen, setSelectedSubTickPen, setSelectedTickLabelFont, setSelectedLabelFont, setSelectedTickLabelColor, setSelectedLabelColor */ -void QCPPolarAxisAngular::setSelectedParts( const SelectableParts& selected ) +void QCPPolarAxisAngular::setSelectedParts(const SelectableParts &selected) { - if( mSelectedParts != selected ) + if (mSelectedParts != selected) { mSelectedParts = selected; - emit selectionChanged( mSelectedParts ); + emit selectionChanged(mSelectedParts); } } @@ -33817,19 +33274,18 @@ void QCPPolarAxisAngular::setSelectedParts( const SelectableParts& selected ) There is also a slot to set a range, see \ref setRange(const QCPRange &range). */ -void QCPPolarAxisAngular::setRange( double lower, double upper ) +void QCPPolarAxisAngular::setRange(double lower, double upper) { - if( lower == mRange.lower && upper == mRange.upper ) - return; - - if( !QCPRange::validRange( lower, upper ) ) + if (lower == mRange.lower && upper == mRange.upper) return; + + if (!QCPRange::validRange(lower, upper)) return; QCPRange oldRange = mRange; mRange.lower = lower; mRange.upper = upper; mRange = mRange.sanitizedForLinScale(); - emit rangeChanged( mRange ); - emit rangeChanged( mRange, oldRange ); + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); } /*! @@ -33843,46 +33299,46 @@ void QCPPolarAxisAngular::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 QCPPolarAxisAngular::setRange( double position, double size, Qt::AlignmentFlag alignment ) +void QCPPolarAxisAngular::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 QCPPolarAxisAngular::setRangeLower( double lower ) +void QCPPolarAxisAngular::setRangeLower(double lower) { - if( mRange.lower == lower ) + if (mRange.lower == lower) return; - + QCPRange oldRange = mRange; mRange.lower = lower; 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 QCPPolarAxisAngular::setRangeUpper( double upper ) +void QCPPolarAxisAngular::setRangeUpper(double upper) { - if( mRange.upper == upper ) + if (mRange.upper == upper) return; - + QCPRange oldRange = mRange; mRange.upper = upper; mRange = mRange.sanitizedForLinScale(); - emit rangeChanged( mRange ); - emit rangeChanged( mRange, oldRange ); + emit rangeChanged(mRange); + emit rangeChanged(mRange, oldRange); } /*! @@ -33894,15 +33350,15 @@ void QCPPolarAxisAngular::setRangeUpper( double upper ) of the \ref setRange interface will still reference the mathematically smaller number than the \a upper part. */ -void QCPPolarAxisAngular::setRangeReversed( bool reversed ) +void QCPPolarAxisAngular::setRangeReversed(bool reversed) { mRangeReversed = reversed; } -void QCPPolarAxisAngular::setAngle( double degrees ) +void QCPPolarAxisAngular::setAngle(double degrees) { mAngle = degrees; - mAngleRad = mAngle / 180.0 * M_PI; + mAngleRad = mAngle/180.0*M_PI; } /*! @@ -33918,9 +33374,9 @@ void QCPPolarAxisAngular::setAngle( double degrees ) \see ticker */ -void QCPPolarAxisAngular::setTicker( QSharedPointer ticker ) +void QCPPolarAxisAngular::setTicker(QSharedPointer ticker) { - if( ticker ) + if (ticker) mTicker = ticker; else qDebug() << Q_FUNC_INFO << "can not set 0 as axis ticker"; @@ -33935,9 +33391,9 @@ void QCPPolarAxisAngular::setTicker( QSharedPointer ticker ) \see setSubTicks */ -void QCPPolarAxisAngular::setTicks( bool show ) +void QCPPolarAxisAngular::setTicks(bool show) { - if( mTicks != show ) + if (mTicks != show) { mTicks = show; //mCachedMarginValid = false; @@ -33947,13 +33403,13 @@ void QCPPolarAxisAngular::setTicks( bool show ) /*! Sets whether tick labels are displayed. Tick labels are the numbers drawn next to tick marks. */ -void QCPPolarAxisAngular::setTickLabels( bool show ) +void QCPPolarAxisAngular::setTickLabels(bool show) { - if( mTickLabels != show ) + if (mTickLabels != show) { mTickLabels = show; //mCachedMarginValid = false; - if( !mTickLabels ) + if (!mTickLabels) mTickVectorLabels.clear(); } } @@ -33962,9 +33418,9 @@ void QCPPolarAxisAngular::setTickLabels( bool show ) Sets the distance between the axis base line (including any outward ticks) and the tick labels. \see setLabelPadding, setPadding */ -void QCPPolarAxisAngular::setTickLabelPadding( int padding ) +void QCPPolarAxisAngular::setTickLabelPadding(int padding) { - mLabelPainter.setPadding( padding ); + mLabelPainter.setPadding(padding); } /*! @@ -33972,7 +33428,7 @@ void QCPPolarAxisAngular::setTickLabelPadding( int padding ) \see setTickLabels, setTickLabelColor */ -void QCPPolarAxisAngular::setTickLabelFont( const QFont& font ) +void QCPPolarAxisAngular::setTickLabelFont(const QFont &font) { mTickLabelFont = font; } @@ -33982,7 +33438,7 @@ void QCPPolarAxisAngular::setTickLabelFont( const QFont& font ) \see setTickLabels, setTickLabelFont */ -void QCPPolarAxisAngular::setTickLabelColor( const QColor& color ) +void QCPPolarAxisAngular::setTickLabelColor(const QColor &color) { mTickLabelColor = color; } @@ -33996,21 +33452,17 @@ void QCPPolarAxisAngular::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 QCPPolarAxisAngular::setTickLabelRotation( double degrees ) +void QCPPolarAxisAngular::setTickLabelRotation(double degrees) { - mLabelPainter.setRotation( degrees ); + mLabelPainter.setRotation(degrees); } -void QCPPolarAxisAngular::setTickLabelMode( LabelMode mode ) +void QCPPolarAxisAngular::setTickLabelMode(LabelMode mode) { - switch( mode ) + switch (mode) { - case lmUpright: - mLabelPainter.setAnchorMode( QCPLabelPainterPrivate::amSkewedUpright ); - break; - case lmRotated: - mLabelPainter.setAnchorMode( QCPLabelPainterPrivate::amSkewedRotated ); - break; + case lmUpright: mLabelPainter.setAnchorMode(QCPLabelPainterPrivate::amSkewedUpright); break; + case lmRotated: mLabelPainter.setAnchorMode(QCPLabelPainterPrivate::amSkewedRotated); break; } } @@ -34044,57 +33496,54 @@ void QCPPolarAxisAngular::setTickLabelMode( LabelMode mode ) \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 QCPPolarAxisAngular::setNumberFormat( const QString& formatCode ) +void QCPPolarAxisAngular::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; mNumberMultiplyCross = false; - } - else + } else { // 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 qDebug() << Q_FUNC_INFO << "Invalid number format code (second char not 'b' or first char neither 'e' nor 'g'):" << formatCode; - - if( formatCode.length() < 3 ) + + if (formatCode.length() < 3) { mNumberMultiplyCross = false; - } - else + } else { // interpret third char as indicator for dot or cross multiplication symbol: - if( formatCode.at( 2 ) == QLatin1Char( 'c' ) ) + if (formatCode.at(2) == QLatin1Char('c')) mNumberMultiplyCross = true; - else if( formatCode.at( 2 ) == QLatin1Char( 'd' ) ) + else if (formatCode.at(2) == QLatin1Char('d')) mNumberMultiplyCross = false; else qDebug() << Q_FUNC_INFO << "Invalid number format code (third char neither 'c' nor 'd'):" << formatCode; } } - mLabelPainter.setSubstituteExponent( mNumberBeautifulPowers ); - mLabelPainter.setMultiplicationSymbol( mNumberMultiplyCross ? QCPLabelPainterPrivate::SymbolCross : QCPLabelPainterPrivate::SymbolDot ); + mLabelPainter.setSubstituteExponent(mNumberBeautifulPowers); + mLabelPainter.setMultiplicationSymbol(mNumberMultiplyCross ? QCPLabelPainterPrivate::SymbolCross : QCPLabelPainterPrivate::SymbolDot); } /*! @@ -34102,9 +33551,9 @@ void QCPPolarAxisAngular::setNumberFormat( const QString& formatCode ) for details. The effect of precisions are most notably for number Formats starting with 'e', see \ref setNumberFormat */ -void QCPPolarAxisAngular::setNumberPrecision( int precision ) +void QCPPolarAxisAngular::setNumberPrecision(int precision) { - if( mNumberPrecision != precision ) + if (mNumberPrecision != precision) { mNumberPrecision = precision; //mCachedMarginValid = false; @@ -34119,10 +33568,10 @@ void QCPPolarAxisAngular::setNumberPrecision( int precision ) \see setSubTickLength, setTickLengthIn, setTickLengthOut */ -void QCPPolarAxisAngular::setTickLength( int inside, int outside ) +void QCPPolarAxisAngular::setTickLength(int inside, int outside) { - setTickLengthIn( inside ); - setTickLengthOut( outside ); + setTickLengthIn(inside); + setTickLengthOut(outside); } /*! @@ -34131,9 +33580,9 @@ void QCPPolarAxisAngular::setTickLength( int inside, int outside ) \see setTickLengthOut, setTickLength, setSubTickLength */ -void QCPPolarAxisAngular::setTickLengthIn( int inside ) +void QCPPolarAxisAngular::setTickLengthIn(int inside) { - if( mTickLengthIn != inside ) + if (mTickLengthIn != inside) { mTickLengthIn = inside; } @@ -34146,9 +33595,9 @@ void QCPPolarAxisAngular::setTickLengthIn( int inside ) \see setTickLengthIn, setTickLength, setSubTickLength */ -void QCPPolarAxisAngular::setTickLengthOut( int outside ) +void QCPPolarAxisAngular::setTickLengthOut(int outside) { - if( mTickLengthOut != outside ) + if (mTickLengthOut != outside) { mTickLengthOut = outside; //mCachedMarginValid = false; // only outside tick length can change margin @@ -34162,9 +33611,9 @@ void QCPPolarAxisAngular::setTickLengthOut( int outside ) \see setTicks */ -void QCPPolarAxisAngular::setSubTicks( bool show ) +void QCPPolarAxisAngular::setSubTicks(bool show) { - if( mSubTicks != show ) + if (mSubTicks != show) { mSubTicks = show; //mCachedMarginValid = false; @@ -34179,10 +33628,10 @@ void QCPPolarAxisAngular::setSubTicks( bool show ) \see setTickLength, setSubTickLengthIn, setSubTickLengthOut */ -void QCPPolarAxisAngular::setSubTickLength( int inside, int outside ) +void QCPPolarAxisAngular::setSubTickLength(int inside, int outside) { - setSubTickLengthIn( inside ); - setSubTickLengthOut( outside ); + setSubTickLengthIn(inside); + setSubTickLengthOut(outside); } /*! @@ -34191,9 +33640,9 @@ void QCPPolarAxisAngular::setSubTickLength( int inside, int outside ) \see setSubTickLengthOut, setSubTickLength, setTickLength */ -void QCPPolarAxisAngular::setSubTickLengthIn( int inside ) +void QCPPolarAxisAngular::setSubTickLengthIn(int inside) { - if( mSubTickLengthIn != inside ) + if (mSubTickLengthIn != inside) { mSubTickLengthIn = inside; } @@ -34206,9 +33655,9 @@ void QCPPolarAxisAngular::setSubTickLengthIn( int inside ) \see setSubTickLengthIn, setSubTickLength, setTickLength */ -void QCPPolarAxisAngular::setSubTickLengthOut( int outside ) +void QCPPolarAxisAngular::setSubTickLengthOut(int outside) { - if( mSubTickLengthOut != outside ) + if (mSubTickLengthOut != outside) { mSubTickLengthOut = outside; //mCachedMarginValid = false; // only outside tick length can change margin @@ -34220,7 +33669,7 @@ void QCPPolarAxisAngular::setSubTickLengthOut( int outside ) \see setTickPen, setSubTickPen */ -void QCPPolarAxisAngular::setBasePen( const QPen& pen ) +void QCPPolarAxisAngular::setBasePen(const QPen &pen) { mBasePen = pen; } @@ -34230,7 +33679,7 @@ void QCPPolarAxisAngular::setBasePen( const QPen& pen ) \see setTickLength, setBasePen */ -void QCPPolarAxisAngular::setTickPen( const QPen& pen ) +void QCPPolarAxisAngular::setTickPen(const QPen &pen) { mTickPen = pen; } @@ -34240,7 +33689,7 @@ void QCPPolarAxisAngular::setTickPen( const QPen& pen ) \see setSubTickCount, setSubTickLength, setBasePen */ -void QCPPolarAxisAngular::setSubTickPen( const QPen& pen ) +void QCPPolarAxisAngular::setSubTickPen(const QPen &pen) { mSubTickPen = pen; } @@ -34250,9 +33699,9 @@ void QCPPolarAxisAngular::setSubTickPen( const QPen& pen ) \see setLabelColor */ -void QCPPolarAxisAngular::setLabelFont( const QFont& font ) +void QCPPolarAxisAngular::setLabelFont(const QFont &font) { - if( mLabelFont != font ) + if (mLabelFont != font) { mLabelFont = font; //mCachedMarginValid = false; @@ -34264,7 +33713,7 @@ void QCPPolarAxisAngular::setLabelFont( const QFont& font ) \see setLabelFont */ -void QCPPolarAxisAngular::setLabelColor( const QColor& color ) +void QCPPolarAxisAngular::setLabelColor(const QColor &color) { mLabelColor = color; } @@ -34273,9 +33722,9 @@ void QCPPolarAxisAngular::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 QCPPolarAxisAngular::setLabel( const QString& str ) +void QCPPolarAxisAngular::setLabel(const QString &str) { - if( mLabel != str ) + if (mLabel != str) { mLabel = str; //mCachedMarginValid = false; @@ -34287,9 +33736,9 @@ void QCPPolarAxisAngular::setLabel( const QString& str ) \see setTickLabelPadding, setPadding */ -void QCPPolarAxisAngular::setLabelPadding( int padding ) +void QCPPolarAxisAngular::setLabelPadding(int padding) { - if( mLabelPadding != padding ) + if (mLabelPadding != padding) { mLabelPadding = padding; //mCachedMarginValid = false; @@ -34301,9 +33750,9 @@ void QCPPolarAxisAngular::setLabelPadding( int padding ) \see setTickLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedTickLabelFont( const QFont& font ) +void QCPPolarAxisAngular::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 @@ -34315,7 +33764,7 @@ void QCPPolarAxisAngular::setSelectedTickLabelFont( const QFont& font ) \see setLabelFont, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedLabelFont( const QFont& font ) +void QCPPolarAxisAngular::setSelectedLabelFont(const QFont &font) { mSelectedLabelFont = font; // don't set mCachedMarginValid to false here because margin calculation is always done with non-selected fonts @@ -34326,9 +33775,9 @@ void QCPPolarAxisAngular::setSelectedLabelFont( const QFont& font ) \see setTickLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedTickLabelColor( const QColor& color ) +void QCPPolarAxisAngular::setSelectedTickLabelColor(const QColor &color) { - if( color != mSelectedTickLabelColor ) + if (color != mSelectedTickLabelColor) { mSelectedTickLabelColor = color; } @@ -34339,7 +33788,7 @@ void QCPPolarAxisAngular::setSelectedTickLabelColor( const QColor& color ) \see setLabelColor, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedLabelColor( const QColor& color ) +void QCPPolarAxisAngular::setSelectedLabelColor(const QColor &color) { mSelectedLabelColor = color; } @@ -34349,7 +33798,7 @@ void QCPPolarAxisAngular::setSelectedLabelColor( const QColor& color ) \see setBasePen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedBasePen( const QPen& pen ) +void QCPPolarAxisAngular::setSelectedBasePen(const QPen &pen) { mSelectedBasePen = pen; } @@ -34359,7 +33808,7 @@ void QCPPolarAxisAngular::setSelectedBasePen( const QPen& pen ) \see setTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedTickPen( const QPen& pen ) +void QCPPolarAxisAngular::setSelectedTickPen(const QPen &pen) { mSelectedTickPen = pen; } @@ -34369,7 +33818,7 @@ void QCPPolarAxisAngular::setSelectedTickPen( const QPen& pen ) \see setSubTickPen, setSelectableParts, setSelectedParts, QCustomPlot::setInteractions */ -void QCPPolarAxisAngular::setSelectedSubTickPen( const QPen& pen ) +void QCPPolarAxisAngular::setSelectedSubTickPen(const QPen &pen) { mSelectedSubTickPen = pen; } @@ -34392,36 +33841,35 @@ void QCPPolarAxisAngular::setSelectedSubTickPen( const QPen& pen ) \see setBackground, setBackgroundScaled, setBackgroundScaledMode */ -void QCPPolarAxisAngular::drawBackground( QCPPainter* painter, const QPointF& center, double radius ) +void QCPPolarAxisAngular::drawBackground(QCPPainter *painter, const QPointF ¢er, double radius) { // draw background fill (don't use circular clip, looks bad): - if( mBackgroundBrush != Qt::NoBrush ) + if (mBackgroundBrush != Qt::NoBrush) { QPainterPath ellipsePath; - ellipsePath.addEllipse( center, radius, radius ); - painter->fillPath( ellipsePath, mBackgroundBrush ); + ellipsePath.addEllipse(center, radius, radius); + painter->fillPath(ellipsePath, mBackgroundBrush); } - + // draw background pixmap (on top of fill, if brush specified): - if( !mBackgroundPixmap.isNull() ) + if (!mBackgroundPixmap.isNull()) { - QRegion clipCircle( center.x() - radius, center.y() - radius, qRound( 2 * radius ), qRound( 2 * radius ), QRegion::Ellipse ); + QRegion clipCircle(center.x()-radius, center.y()-radius, qRound(2*radius), qRound(2*radius), QRegion::Ellipse); QRegion originalClip = painter->clipRegion(); - painter->setClipRegion( clipCircle ); - if( mBackgroundScaled ) + painter->setClipRegion(clipCircle); + 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())); } - painter->setClipRegion( originalClip ); + painter->setClipRegion(originalClip); } } @@ -34435,26 +33883,24 @@ void QCPPolarAxisAngular::drawBackground( QCPPainter* painter, const QPointF& ce */ void QCPPolarAxisAngular::setupTickVectors() { - if( !mParentPlot ) - return; - if( ( !mTicks && !mTickLabels && !mGrid->visible() ) || mRange.size() <= 0 ) - return; - - mSubTickVector.clear(); // since we might not pass it to mTicker->generate(), and we don't want old data in there - mTicker->generate( mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0 ); - + if (!mParentPlot) return; + if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return; + + mSubTickVector.clear(); // since we might not pass it to mTicker->generate(), and we don't want old data in there + mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : 0, mTickLabels ? &mTickVectorLabels : 0); + // fill cos/sin buffers which will be used by draw() and QCPPolarGrid::draw(), so we don't have to calculate it twice: - mTickVectorCosSin.resize( mTickVector.size() ); - for( int i = 0; i < mTickVector.size(); ++i ) + mTickVectorCosSin.resize(mTickVector.size()); + for (int i=0; ibuttons() & 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)) { mDragAngularStart = range(); mDragRadialStart.clear(); - for( int i = 0; i < mRadialAxes.size(); ++i ) - mDragRadialStart.append( mRadialAxes.at( i )->range() ); + for (int i=0; irange()); } } } @@ -34569,68 +34015,67 @@ void QCPPolarAxisAngular::mousePressEvent( QMouseEvent* event, const QVariant& d \see mousePressEvent, mouseReleaseEvent */ -void QCPPolarAxisAngular::mouseMoveEvent( QMouseEvent* event, const QPointF& startPos ) +void QCPPolarAxisAngular::mouseMoveEvent(QMouseEvent *event, const QPointF &startPos) { - Q_UNUSED( startPos ) + Q_UNUSED(startPos) bool doReplot = false; // Mouse range dragging interaction: - if( mDragging && mParentPlot->interactions().testFlag( QCP::iRangeDrag ) ) + if (mDragging && mParentPlot->interactions().testFlag(QCP::iRangeDrag)) { - if( mRangeDrag ) + if (mRangeDrag) { doReplot = true; double angleCoordStart, radiusCoordStart; double angleCoord, radiusCoord; - pixelToCoord( startPos, angleCoordStart, radiusCoordStart ); - pixelToCoord( event->pos(), angleCoord, radiusCoord ); + pixelToCoord(startPos, angleCoordStart, radiusCoordStart); + pixelToCoord(event->pos(), angleCoord, radiusCoord); double diff = angleCoordStart - angleCoord; - setRange( mDragAngularStart.lower + diff, mDragAngularStart.upper + diff ); + setRange(mDragAngularStart.lower+diff, mDragAngularStart.upper+diff); } - - for( int i = 0; i < mRadialAxes.size(); ++i ) + + for (int i=0; irangeDrag() ) + QCPPolarAxisRadial *ax = mRadialAxes.at(i); + if (!ax->rangeDrag()) continue; doReplot = true; double angleCoordStart, radiusCoordStart; double angleCoord, radiusCoord; - ax->pixelToCoord( startPos, angleCoordStart, radiusCoordStart ); - ax->pixelToCoord( event->pos(), angleCoord, radiusCoord ); - if( ax->scaleType() == QCPPolarAxisRadial::stLinear ) + ax->pixelToCoord(startPos, angleCoordStart, radiusCoordStart); + ax->pixelToCoord(event->pos(), angleCoord, radiusCoord); + if (ax->scaleType() == QCPPolarAxisRadial::stLinear) { double diff = radiusCoordStart - radiusCoord; - ax->setRange( mDragRadialStart.at( i ).lower + diff, mDragRadialStart.at( i ).upper + diff ); - } - else if( ax->scaleType() == QCPPolarAxisRadial::stLogarithmic ) + ax->setRange(mDragRadialStart.at(i).lower+diff, mDragRadialStart.at(i).upper+diff); + } else if (ax->scaleType() == QCPPolarAxisRadial::stLogarithmic) { - if( radiusCoord != 0 ) + if (radiusCoord != 0) { - double diff = radiusCoordStart / radiusCoord; - ax->setRange( mDragRadialStart.at( i ).lower * diff, mDragRadialStart.at( i ).upper * diff ); + double diff = radiusCoordStart/radiusCoord; + ax->setRange(mDragRadialStart.at(i).lower*diff, mDragRadialStart.at(i).upper*diff); } } } - - if( doReplot ) // if either vertical or horizontal drag was enabled, do a replot + + if (doReplot) // 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 QCPPolarAxisAngular::mouseReleaseEvent( QMouseEvent* event, const QPointF& startPos ) +void QCPPolarAxisAngular::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); } } @@ -34648,71 +34093,73 @@ void QCPPolarAxisAngular::mouseReleaseEvent( QMouseEvent* event, const QPointF& 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 QCPPolarAxisAngular::wheelEvent( QWheelEvent* event ) +void QCPPolarAxisAngular::wheelEvent(QWheelEvent *event) { bool doReplot = false; // Mouse range zooming interaction: - if( mParentPlot->interactions().testFlag( QCP::iRangeZoom ) ) + if (mParentPlot->interactions().testFlag(QCP::iRangeZoom)) { -#if QT_VERSION < QT_VERSION_CHECK( 5, 0, 0 ) +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) const double delta = event->delta(); #else const double delta = event->angleDelta().y(); #endif -#if QT_VERSION < QT_VERSION_CHECK( 5, 14, 0 ) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) const QPointF pos = event->pos(); #else const QPointF pos = event->position(); #endif - const double wheelSteps = delta / 120.0; // a single step delta is +/-120 usually - if( mRangeZoom ) + const double wheelSteps = delta/120.0; // a single step delta is +/-120 usually + if (mRangeZoom) { double angleCoord, radiusCoord; - pixelToCoord( pos, angleCoord, radiusCoord ); - scaleRange( qPow( mRangeZoomFactor, wheelSteps ), angleCoord ); + pixelToCoord(pos, angleCoord, radiusCoord); + scaleRange(qPow(mRangeZoomFactor, wheelSteps), angleCoord); } - for( int i = 0; i < mRadialAxes.size(); ++i ) + for (int i=0; irangeZoom() ) + QCPPolarAxisRadial *ax = mRadialAxes.at(i); + if (!ax->rangeZoom()) continue; doReplot = true; double angleCoord, radiusCoord; - ax->pixelToCoord( pos, angleCoord, radiusCoord ); - ax->scaleRange( qPow( ax->rangeZoomFactor(), wheelSteps ), radiusCoord ); + ax->pixelToCoord(pos, angleCoord, radiusCoord); + ax->scaleRange(qPow(ax->rangeZoomFactor(), wheelSteps), radiusCoord); } } - if( doReplot ) + if (doReplot) mParentPlot->replot(); } -bool QCPPolarAxisAngular::registerPolarGraph( QCPPolarGraph* graph ) +bool QCPPolarAxisAngular::registerPolarGraph(QCPPolarGraph *graph) { - if( mGraphs.contains( graph ) ) + if (mGraphs.contains(graph)) { - qDebug() << Q_FUNC_INFO << "plottable already added:" << reinterpret_cast( graph ); + qDebug() << Q_FUNC_INFO << "plottable already added:" << reinterpret_cast(graph); return false; } - if( graph->keyAxis() != this ) + if (graph->keyAxis() != this) { - qDebug() << Q_FUNC_INFO << "plottable not created with this as axis:" << reinterpret_cast( graph ); + qDebug() << Q_FUNC_INFO << "plottable not created with this as axis:" << reinterpret_cast(graph); return false; } - - mGraphs.append( graph ); + + mGraphs.append(graph); // possibly add plottable to legend: - if( mParentPlot->autoAddPlottableToLegend() ) + if (mParentPlot->autoAddPlottableToLegend()) graph->addToLegend(); - if( !graph->layer() ) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) - graph->setLayer( mParentPlot->currentLayer() ); + if (!graph->layer()) // usually the layer is already set in the constructor of the plottable (via QCPLayerable constructor) + graph->setLayer(mParentPlot->currentLayer()); return true; } /* end of 'src/polar/layoutelement-angularaxis.cpp' */ + /* including file 'src/polar/polargrid.cpp' */ -/* modified 2021-03-29T02:30:44, size 7493 */ +/* modified 2022-11-06T12:45:57, size 7493 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPolarGrid @@ -34730,35 +34177,40 @@ bool QCPPolarAxisAngular::registerPolarGraph( QCPPolarGraph* graph ) You shouldn't instantiate grids on their own, since every axis brings its own grid. */ -QCPPolarGrid::QCPPolarGrid( QCPPolarAxisAngular* parentAxis ) - : QCPLayerable( parentAxis->parentPlot(), QString(), parentAxis ), mType( gtNone ), mSubGridType( gtNone ), mAntialiasedSubGrid( true ), mAntialiasedZeroLine( true ), mParentAxis( parentAxis ) +QCPPolarGrid::QCPPolarGrid(QCPPolarAxisAngular *parentAxis) : + QCPLayerable(parentAxis->parentPlot(), QString(), parentAxis), + mType(gtNone), + mSubGridType(gtNone), + mAntialiasedSubGrid(true), + mAntialiasedZeroLine(true), + mParentAxis(parentAxis) { // warning: this is called in QCPPolarAxisAngular constructor, so parentAxis members should not be accessed/called - setParent( parentAxis ); - setType( gtAll ); - setSubGridType( gtNone ); - - setAngularPen( QPen( QColor( 200, 200, 200 ), 0, Qt::DotLine ) ); - setAngularSubGridPen( QPen( QColor( 220, 220, 220 ), 0, Qt::DotLine ) ); - - setRadialPen( QPen( QColor( 200, 200, 200 ), 0, Qt::DotLine ) ); - setRadialSubGridPen( QPen( QColor( 220, 220, 220 ), 0, Qt::DotLine ) ); - setRadialZeroLinePen( QPen( QColor( 200, 200, 200 ), 0, Qt::SolidLine ) ); - - setAntialiased( true ); + setParent(parentAxis); + setType(gtAll); + setSubGridType(gtNone); + + setAngularPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setAngularSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + + setRadialPen(QPen(QColor(200,200,200), 0, Qt::DotLine)); + setRadialSubGridPen(QPen(QColor(220,220,220), 0, Qt::DotLine)); + setRadialZeroLinePen(QPen(QColor(200,200,200), 0, Qt::SolidLine)); + + setAntialiased(true); } -void QCPPolarGrid::setRadialAxis( QCPPolarAxisRadial* axis ) +void QCPPolarGrid::setRadialAxis(QCPPolarAxisRadial *axis) { mRadialAxis = axis; } -void QCPPolarGrid::setType( GridTypes type ) +void QCPPolarGrid::setType(GridTypes type) { mType = type; } -void QCPPolarGrid::setSubGridType( GridTypes type ) +void QCPPolarGrid::setSubGridType(GridTypes type) { mSubGridType = type; } @@ -34766,7 +34218,7 @@ void QCPPolarGrid::setSubGridType( GridTypes type ) /*! Sets whether sub grid lines are drawn antialiased. */ -void QCPPolarGrid::setAntialiasedSubGrid( bool enabled ) +void QCPPolarGrid::setAntialiasedSubGrid(bool enabled) { mAntialiasedSubGrid = enabled; } @@ -34774,7 +34226,7 @@ void QCPPolarGrid::setAntialiasedSubGrid( bool enabled ) /*! Sets whether zero lines are drawn antialiased. */ -void QCPPolarGrid::setAntialiasedZeroLine( bool enabled ) +void QCPPolarGrid::setAntialiasedZeroLine(bool enabled) { mAntialiasedZeroLine = enabled; } @@ -34782,7 +34234,7 @@ void QCPPolarGrid::setAntialiasedZeroLine( bool enabled ) /*! Sets the pen with which (major) grid lines are drawn. */ -void QCPPolarGrid::setAngularPen( const QPen& pen ) +void QCPPolarGrid::setAngularPen(const QPen &pen) { mAngularPen = pen; } @@ -34790,22 +34242,22 @@ void QCPPolarGrid::setAngularPen( const QPen& pen ) /*! Sets the pen with which sub grid lines are drawn. */ -void QCPPolarGrid::setAngularSubGridPen( const QPen& pen ) +void QCPPolarGrid::setAngularSubGridPen(const QPen &pen) { mAngularSubGridPen = pen; } -void QCPPolarGrid::setRadialPen( const QPen& pen ) +void QCPPolarGrid::setRadialPen(const QPen &pen) { mRadialPen = pen; } -void QCPPolarGrid::setRadialSubGridPen( const QPen& pen ) +void QCPPolarGrid::setRadialSubGridPen(const QPen &pen) { mRadialSubGridPen = pen; } -void QCPPolarGrid::setRadialZeroLinePen( const QPen& pen ) +void QCPPolarGrid::setRadialZeroLinePen(const QPen &pen) { mRadialZeroLinePen = pen; } @@ -34823,9 +34275,9 @@ void QCPPolarGrid::setRadialZeroLinePen( const QPen& pen ) \see setAntialiased */ -void QCPPolarGrid::applyDefaultAntialiasingHint( QCPPainter* painter ) const +void QCPPolarGrid::applyDefaultAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiased, QCP::aeGrid ); + applyAntialiasingHint(painter, mAntialiased, QCP::aeGrid); } /*! \internal @@ -34833,75 +34285,69 @@ void QCPPolarGrid::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 QCPPolarGrid::draw( QCPPainter* painter ) +void QCPPolarGrid::draw(QCPPainter *painter) { - if( !mParentAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid parent axis"; - return; - } - + if (!mParentAxis) { qDebug() << Q_FUNC_INFO << "invalid parent axis"; return; } + const QPointF center = mParentAxis->mCenter; const double radius = mParentAxis->mRadius; - - painter->setBrush( Qt::NoBrush ); + + painter->setBrush(Qt::NoBrush); // draw main angular grid: - if( mType.testFlag( gtAngular ) ) - drawAngularGrid( painter, center, radius, mParentAxis->mTickVectorCosSin, mAngularPen ); + if (mType.testFlag(gtAngular)) + drawAngularGrid(painter, center, radius, mParentAxis->mTickVectorCosSin, mAngularPen); // draw main radial grid: - if( mType.testFlag( gtRadial ) && mRadialAxis ) - drawRadialGrid( painter, center, mRadialAxis->tickVector(), mRadialPen, mRadialZeroLinePen ); - - applyAntialiasingHint( painter, mAntialiasedSubGrid, QCP::aeGrid ); + if (mType.testFlag(gtRadial) && mRadialAxis) + drawRadialGrid(painter, center, mRadialAxis->tickVector(), mRadialPen, mRadialZeroLinePen); + + applyAntialiasingHint(painter, mAntialiasedSubGrid, QCP::aeGrid); // draw sub angular grid: - if( mSubGridType.testFlag( gtAngular ) ) - drawAngularGrid( painter, center, radius, mParentAxis->mSubTickVectorCosSin, mAngularSubGridPen ); + if (mSubGridType.testFlag(gtAngular)) + drawAngularGrid(painter, center, radius, mParentAxis->mSubTickVectorCosSin, mAngularSubGridPen); // draw sub radial grid: - if( mSubGridType.testFlag( gtRadial ) && mRadialAxis ) - drawRadialGrid( painter, center, mRadialAxis->subTickVector(), mRadialSubGridPen ); + if (mSubGridType.testFlag(gtRadial) && mRadialAxis) + drawRadialGrid(painter, center, mRadialAxis->subTickVector(), mRadialSubGridPen); } -void QCPPolarGrid::drawRadialGrid( QCPPainter* painter, const QPointF& center, const QVector& coords, const QPen& pen, const QPen& zeroPen ) +void QCPPolarGrid::drawRadialGrid(QCPPainter *painter, const QPointF ¢er, const QVector &coords, const QPen &pen, const QPen &zeroPen) { - if( !mRadialAxis ) - return; - if( coords.isEmpty() ) - return; + if (!mRadialAxis) return; + if (coords.isEmpty()) return; const bool drawZeroLine = zeroPen != Qt::NoPen; - const double zeroLineEpsilon = qAbs( coords.last() - coords.first() ) * 1e-6; - - painter->setPen( pen ); - for( int i = 0; i < coords.size(); ++i ) + const double zeroLineEpsilon = qAbs(coords.last()-coords.first())*1e-6; + + painter->setPen(pen); + for (int i=0; icoordToRadius( coords.at( i ) ); - if( drawZeroLine && qAbs( coords.at( i ) ) < zeroLineEpsilon ) + const double r = mRadialAxis->coordToRadius(coords.at(i)); + if (drawZeroLine && qAbs(coords.at(i)) < zeroLineEpsilon) { - applyAntialiasingHint( painter, mAntialiasedZeroLine, QCP::aeZeroLine ); - painter->setPen( zeroPen ); - painter->drawEllipse( center, r, r ); - painter->setPen( pen ); - applyDefaultAntialiasingHint( painter ); - } - else + applyAntialiasingHint(painter, mAntialiasedZeroLine, QCP::aeZeroLine); + painter->setPen(zeroPen); + painter->drawEllipse(center, r, r); + painter->setPen(pen); + applyDefaultAntialiasingHint(painter); + } else { - painter->drawEllipse( center, r, r ); + painter->drawEllipse(center, r, r); } } } -void QCPPolarGrid::drawAngularGrid( QCPPainter* painter, const QPointF& center, double radius, const QVector& ticksCosSin, const QPen& pen ) +void QCPPolarGrid::drawAngularGrid(QCPPainter *painter, const QPointF ¢er, double radius, const QVector &ticksCosSin, const QPen &pen) { - if( ticksCosSin.isEmpty() ) - return; - - painter->setPen( pen ); - for( int i = 0; i < ticksCosSin.size(); ++i ) - painter->drawLine( center, center + ticksCosSin.at( i ) * radius ); + if (ticksCosSin.isEmpty()) return; + + painter->setPen(pen); + for (int i=0; idrawLine(center, center+ticksCosSin.at(i)*radius); } /* end of 'src/polar/polargrid.cpp' */ + /* including file 'src/polar/polargraph.cpp' */ -/* modified 2021-03-29T02:30:44, size 44035 */ +/* modified 2022-11-06T12:45:57, size 44035 */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPolarLegendItem @@ -34913,52 +34359,51 @@ void QCPPolarGrid::drawAngularGrid( QCPPainter* painter, const QPointF& center, \warning In this QCustomPlot version, polar plots are a tech preview. Expect documentation and functionality to be incomplete, as well as changing public interfaces in the future. */ -QCPPolarLegendItem::QCPPolarLegendItem( QCPLegend* parent, QCPPolarGraph* graph ) - : QCPAbstractLegendItem( parent ), mPolarGraph( graph ) +QCPPolarLegendItem::QCPPolarLegendItem(QCPLegend *parent, QCPPolarGraph *graph) : + QCPAbstractLegendItem(parent), + mPolarGraph(graph) { - setAntialiased( false ); + setAntialiased(false); } -void QCPPolarLegendItem::draw( QCPPainter* painter ) +void QCPPolarLegendItem::draw(QCPPainter *painter) { - if( !mPolarGraph ) - return; - painter->setFont( getFont() ); - painter->setPen( QPen( getTextColor() ) ); + if (!mPolarGraph) return; + painter->setFont(getFont()); + painter->setPen(QPen(getTextColor())); QSizeF iconSize = mParentLegend->iconSize(); - QRectF textRect = painter->fontMetrics().boundingRect( 0, 0, 0, iconSize.height(), Qt::TextDontClip, mPolarGraph->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, mPolarGraph->name() ); + QRectF textRect = painter->fontMetrics().boundingRect(0, 0, 0, iconSize.height(), Qt::TextDontClip, mPolarGraph->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, mPolarGraph->name()); // draw icon: painter->save(); - painter->setClipRect( iconRect, Qt::IntersectClip ); - mPolarGraph->drawLegendIcon( painter, iconRect ); + painter->setClipRect(iconRect, Qt::IntersectClip); + mPolarGraph->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); } } QSize QCPPolarLegendItem::minimumOuterSizeHint() const { - if( !mPolarGraph ) - return QSize(); - QSize result( 0, 0 ); + if (!mPolarGraph) 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, mPolarGraph->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, mPolarGraph->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; } @@ -34977,6 +34422,7 @@ QFont QCPPolarLegendItem::getFont() const return mSelected ? mSelectedFont : mFont; } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPolarGraph //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -35007,20 +34453,30 @@ QFont QCPPolarLegendItem::getFont() const To directly create a QCPPolarGraph inside a plot, you shoud use the QCPPolarAxisAngular::addGraph method. */ -QCPPolarGraph::QCPPolarGraph( QCPPolarAxisAngular* keyAxis, QCPPolarAxisRadial* valueAxis ) - : QCPLayerable( keyAxis->parentPlot(), QString(), keyAxis ), mDataContainer( new QCPGraphDataContainer ), mName(), mAntialiasedFill( true ), mAntialiasedScatters( true ), mPen( Qt::black ), mBrush( Qt::NoBrush ), mPeriodic( true ), mKeyAxis( keyAxis ), mValueAxis( valueAxis ), mSelectable( QCP::stWhole ) -//mSelectionDecorator(0) // TODO +QCPPolarGraph::QCPPolarGraph(QCPPolarAxisAngular *keyAxis, QCPPolarAxisRadial *valueAxis) : + QCPLayerable(keyAxis->parentPlot(), QString(), keyAxis), + mDataContainer(new QCPGraphDataContainer), + mName(), + mAntialiasedFill(true), + mAntialiasedScatters(true), + mPen(Qt::black), + mBrush(Qt::NoBrush), + mPeriodic(true), + mKeyAxis(keyAxis), + mValueAxis(valueAxis), + mSelectable(QCP::stWhole) + //mSelectionDecorator(0) // TODO { - 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."; - - mKeyAxis->registerPolarGraph( this ); - + + mKeyAxis->registerPolarGraph(this); + //setSelectionDecorator(new QCPSelectionDecorator); // TODO - - setPen( QPen( Qt::blue, 0 ) ); - setBrush( Qt::NoBrush ); - setLineStyle( lsLine ); + + setPen(QPen(Qt::blue, 0)); + setBrush(Qt::NoBrush); + setLineStyle(lsLine); } QCPPolarGraph::~QCPPolarGraph() @@ -35038,7 +34494,7 @@ QCPPolarGraph::~QCPPolarGraph() 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 QCPPolarGraph::setName( const QString& name ) +void QCPPolarGraph::setName(const QString &name) { mName = name; } @@ -35049,7 +34505,7 @@ void QCPPolarGraph::setName( const QString& name ) Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref QCustomPlot::setNotAntialiasedElements. */ -void QCPPolarGraph::setAntialiasedFill( bool enabled ) +void QCPPolarGraph::setAntialiasedFill(bool enabled) { mAntialiasedFill = enabled; } @@ -35060,7 +34516,7 @@ void QCPPolarGraph::setAntialiasedFill( bool enabled ) Note that this setting may be overridden by \ref QCustomPlot::setAntialiasedElements and \ref QCustomPlot::setNotAntialiasedElements. */ -void QCPPolarGraph::setAntialiasedScatters( bool enabled ) +void QCPPolarGraph::setAntialiasedScatters(bool enabled) { mAntialiasedScatters = enabled; } @@ -35073,7 +34529,7 @@ void QCPPolarGraph::setAntialiasedScatters( bool enabled ) \see setBrush */ -void QCPPolarGraph::setPen( const QPen& pen ) +void QCPPolarGraph::setPen(const QPen &pen) { mPen = pen; } @@ -35087,12 +34543,12 @@ void QCPPolarGraph::setPen( const QPen& pen ) \see setPen */ -void QCPPolarGraph::setBrush( const QBrush& brush ) +void QCPPolarGraph::setBrush(const QBrush &brush) { mBrush = brush; } -void QCPPolarGraph::setPeriodic( bool enabled ) +void QCPPolarGraph::setPeriodic(bool enabled) { mPeriodic = enabled; } @@ -35108,7 +34564,7 @@ void QCPPolarGraph::setPeriodic( bool enabled ) \see setValueAxis */ -void QCPPolarGraph::setKeyAxis( QCPPolarAxisAngular* axis ) +void QCPPolarGraph::setKeyAxis(QCPPolarAxisAngular *axis) { mKeyAxis = axis; } @@ -35124,7 +34580,7 @@ void QCPPolarGraph::setKeyAxis( QCPPolarAxisAngular* axis ) \see setKeyAxis */ -void QCPPolarGraph::setValueAxis( QCPPolarAxisRadial* axis ) +void QCPPolarGraph::setValueAxis(QCPPolarAxisRadial *axis) { mValueAxis = axis; } @@ -35139,18 +34595,18 @@ void QCPPolarGraph::setValueAxis( QCPPolarAxisRadial* axis ) \see setSelection, QCP::SelectionType */ -void QCPPolarGraph::setSelectable( QCP::SelectionType selectable ) +void QCPPolarGraph::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); } } } @@ -35173,14 +34629,14 @@ void QCPPolarGraph::setSelectable( QCP::SelectionType selectable ) \see setSelectable, selectTest */ -void QCPPolarGraph::setSelection( QCPDataSelection selection ) +void QCPPolarGraph::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); } } @@ -35199,7 +34655,7 @@ void QCPPolarGraph::setSelection( QCPDataSelection selection ) \see addData */ -void QCPPolarGraph::setData( QSharedPointer data ) +void QCPPolarGraph::setData(QSharedPointer data) { mDataContainer = data; } @@ -35215,10 +34671,10 @@ void QCPPolarGraph::setData( QSharedPointer data ) \see addData */ -void QCPPolarGraph::setData( const QVector& keys, const QVector& values, bool alreadySorted ) +void QCPPolarGraph::setData(const QVector &keys, const QVector &values, bool alreadySorted) { mDataContainer->clear(); - addData( keys, values, alreadySorted ); + addData(keys, values, alreadySorted); } /*! @@ -35227,7 +34683,7 @@ void QCPPolarGraph::setData( const QVector& keys, const QVector& \see setScatterStyle */ -void QCPPolarGraph::setLineStyle( LineStyle ls ) +void QCPPolarGraph::setLineStyle(LineStyle ls) { mLineStyle = ls; } @@ -35238,33 +34694,33 @@ void QCPPolarGraph::setLineStyle( LineStyle ls ) \see QCPScatterStyle, setLineStyle */ -void QCPPolarGraph::setScatterStyle( const QCPScatterStyle& style ) +void QCPPolarGraph::setScatterStyle(const QCPScatterStyle &style) { mScatterStyle = style; } -void QCPPolarGraph::addData( const QVector& keys, const QVector& values, bool alreadySorted ) +void QCPPolarGraph::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 } -void QCPPolarGraph::addData( double key, double value ) +void QCPPolarGraph::addData(double key, double value) { - mDataContainer->add( QCPGraphData( key, value ) ); + mDataContainer->add(QCPGraphData(key, value)); } /*! @@ -35295,302 +34751,283 @@ void QCPPolarGraph::setSelectionDecorator(QCPSelectionDecorator *decorator) } */ -void QCPPolarGraph::coordsToPixels( double key, double value, double& x, double& y ) const +void QCPPolarGraph::coordsToPixels(double key, double value, double &x, double &y) const { - if( mValueAxis ) + if (mValueAxis) { - const QPointF point = mValueAxis->coordToPixel( key, value ); + const QPointF point = mValueAxis->coordToPixel(key, value); x = point.x(); y = point.y(); - } - else + } else { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; } } -const QPointF QCPPolarGraph::coordsToPixels( double key, double value ) const +const QPointF QCPPolarGraph::coordsToPixels(double key, double value) const { - if( mValueAxis ) + if (mValueAxis) { - return mValueAxis->coordToPixel( key, value ); - } - else + return mValueAxis->coordToPixel(key, value); + } else { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return QPointF(); } } -void QCPPolarGraph::pixelsToCoords( double x, double y, double& key, double& value ) const +void QCPPolarGraph::pixelsToCoords(double x, double y, double &key, double &value) const { - if( mValueAxis ) + if (mValueAxis) { - mValueAxis->pixelToCoord( QPointF( x, y ), key, value ); - } - else + mValueAxis->pixelToCoord(QPointF(x, y), key, value); + } else { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; } } -void QCPPolarGraph::pixelsToCoords( const QPointF& pixelPos, double& key, double& value ) const +void QCPPolarGraph::pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const { - if( mValueAxis ) + if (mValueAxis) { - mValueAxis->pixelToCoord( pixelPos, key, value ); - } - else + mValueAxis->pixelToCoord(pixelPos, key, value); + } else { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; } } -void QCPPolarGraph::rescaleAxes( bool onlyEnlarge ) const +void QCPPolarGraph::rescaleAxes(bool onlyEnlarge) const { - rescaleKeyAxis( onlyEnlarge ); - rescaleValueAxis( onlyEnlarge ); + rescaleKeyAxis(onlyEnlarge); + rescaleValueAxis(onlyEnlarge); } -void QCPPolarGraph::rescaleKeyAxis( bool onlyEnlarge ) const +void QCPPolarGraph::rescaleKeyAxis(bool onlyEnlarge) const { - QCPPolarAxisAngular* keyAxis = mKeyAxis.data(); - if( !keyAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key axis"; - return; - } - + QCPPolarAxisAngular *keyAxis = mKeyAxis.data(); + if (!keyAxis) { qDebug() << Q_FUNC_INFO << "invalid key axis"; return; } + bool foundRange; - QCPRange newRange = getKeyRange( foundRange, QCP::sdBoth ); - if( foundRange ) + QCPRange newRange = getKeyRange(foundRange, QCP::sdBoth); + 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 + 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 - newRange.lower = center - keyAxis->range().size() / 2.0; - newRange.upper = center + keyAxis->range().size() / 2.0; + 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 + newRange.lower = center-keyAxis->range().size()/2.0; + newRange.upper = center+keyAxis->range().size()/2.0; } - keyAxis->setRange( newRange ); + keyAxis->setRange(newRange); } } -void QCPPolarGraph::rescaleValueAxis( bool onlyEnlarge, bool inKeyRange ) const +void QCPPolarGraph::rescaleValueAxis(bool onlyEnlarge, bool inKeyRange) const { - QCPPolarAxisAngular* keyAxis = mKeyAxis.data(); - QCPPolarAxisRadial* valueAxis = mValueAxis.data(); - if( !keyAxis || !valueAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - + QCPPolarAxisAngular *keyAxis = mKeyAxis.data(); + QCPPolarAxisRadial *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + QCP::SignDomain signDomain = QCP::sdBoth; - if( valueAxis->scaleType() == QCPPolarAxisRadial::stLogarithmic ) - signDomain = ( valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive ); - + if (valueAxis->scaleType() == QCPPolarAxisRadial::stLogarithmic) + signDomain = (valueAxis->range().upper < 0 ? QCP::sdNegative : QCP::sdPositive); + bool foundRange; - QCPRange newRange = getValueRange( foundRange, signDomain, inKeyRange ? keyAxis->range() : QCPRange() ); - if( 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 + 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() == QCPPolarAxisRadial::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() == QCPPolarAxisRadial::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); } } -bool QCPPolarGraph::addToLegend( QCPLegend* legend ) +bool QCPPolarGraph::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)) // TODO //{ - legend->addItem( new QCPPolarLegendItem( legend, this ) ); - return true; + legend->addItem(new QCPPolarLegendItem(legend, this)); + return true; //} else // return false; } bool QCPPolarGraph::addToLegend() { - if( !mParentPlot || !mParentPlot->legend ) + if (!mParentPlot || !mParentPlot->legend) return false; else - return addToLegend( mParentPlot->legend ); + return addToLegend(mParentPlot->legend); } -bool QCPPolarGraph::removeFromLegend( QCPLegend* legend ) const +bool QCPPolarGraph::removeFromLegend(QCPLegend *legend) const { - if( !legend ) + if (!legend) { qDebug() << Q_FUNC_INFO << "passed legend is null"; return false; } - - QCPPolarLegendItem* removableItem = 0; - for( int i = 0; i < legend->itemCount(); ++i ) // TODO: reduce this to code in QCPAbstractPlottable::removeFromLegend once unified + + + QCPPolarLegendItem *removableItem = 0; + for (int i=0; iitemCount(); ++i) // TODO: reduce this to code in QCPAbstractPlottable::removeFromLegend once unified { - if( QCPPolarLegendItem* pli = qobject_cast( legend->item( i ) ) ) + if (QCPPolarLegendItem *pli = qobject_cast(legend->item(i))) { - if( pli->polarGraph() == this ) + if (pli->polarGraph() == this) { removableItem = pli; break; } } } - - if( removableItem ) - return legend->removeItem( removableItem ); + + if (removableItem) + return legend->removeItem(removableItem); else return false; } bool QCPPolarGraph::removeFromLegend() const { - if( !mParentPlot || !mParentPlot->legend ) + if (!mParentPlot || !mParentPlot->legend) return false; else - return removeFromLegend( mParentPlot->legend ); + return removeFromLegend(mParentPlot->legend); } -double QCPPolarGraph::selectTest( const QPointF& pos, bool onlySelectable, QVariant* details ) const +double QCPPolarGraph::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->rect().contains( pos.toPoint() ) ) + + if (mKeyAxis->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 QCPPolarGraph::getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain ) const +QCPRange QCPPolarGraph::getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain) const { - return mDataContainer->keyRange( foundRange, inSignDomain ); + return mDataContainer->keyRange(foundRange, inSignDomain); } /* inherits documentation from base class */ -QCPRange QCPPolarGraph::getValueRange( bool& foundRange, QCP::SignDomain inSignDomain, const QCPRange& inKeyRange ) const +QCPRange QCPPolarGraph::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 */ QRect QCPPolarGraph::clipRect() const { - if( mKeyAxis ) + if (mKeyAxis) return mKeyAxis.data()->rect(); else return QRect(); } -void QCPPolarGraph::draw( QCPPainter* painter ) +void QCPPolarGraph::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; - - painter->setClipRegion( mKeyAxis->exactClipRegion() ); - - 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; + + painter->setClipRegion(mKeyAxis->exactClipRegion()); + + 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 < allSegments.size(); ++i ) + 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); //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); //else - painter->setPen( mPen ); - painter->setBrush( Qt::NoBrush ); - drawLinePlot( painter, lines ); + painter->setPen(mPen); + painter->setBrush(Qt::NoBrush); + drawLinePlot(painter, lines); } - + // draw scatters: - + QCPScatterStyle finalScatterStyle = mScatterStyle; //if (isSelectedSegment && mSelectionDecorator) // finalScatterStyle = mSelectionDecorator->getFinalScatterStyle(mScatterStyle); - if( !finalScatterStyle.isNone() ) + 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()); @@ -35601,52 +35038,50 @@ QCP::Interaction QCPPolarGraph::selectionCategory() const return QCP::iSelectPlottables; } -void QCPPolarGraph::applyDefaultAntialiasingHint( QCPPainter* painter ) const +void QCPPolarGraph::applyDefaultAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiased, QCP::aePlottables ); + applyAntialiasingHint(painter, mAntialiased, QCP::aePlottables); } /* inherits documentation from base class */ -void QCPPolarGraph::selectEvent( QMouseEvent* event, bool additive, const QVariant& details, bool* selectionStateChanged ) +void QCPPolarGraph::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 + 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 ); + if (mSelection.contains(newSelection)) // if entire newSelection is already selected, toggle selection + setSelection(mSelection-newSelection); else - setSelection( mSelection + newSelection ); + setSelection(mSelection+newSelection); } - } - else - setSelection( newSelection ); - if( selectionStateChanged ) + } else + setSelection(newSelection); + if (selectionStateChanged) *selectionStateChanged = mSelection != selectionBefore; } } /* inherits documentation from base class */ -void QCPPolarGraph::deselectEvent( bool* selectionStateChanged ) +void QCPPolarGraph::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; } } @@ -35657,12 +35092,12 @@ void QCPPolarGraph::deselectEvent( bool* selectionStateChanged ) \see drawScatterPlot, drawImpulsePlot, QCPAbstractPlottable1D::drawPolyline */ -void QCPPolarGraph::drawLinePlot( QCPPainter* painter, const QVector& lines ) const +void QCPPolarGraph::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); } } @@ -35683,11 +35118,11 @@ void QCPPolarGraph::drawLinePlot( QCPPainter* painter, const QVector& l \see drawLinePlot, drawImpulsePlot, drawScatterPlot */ -void QCPPolarGraph::drawFill( QCPPainter* painter, QVector* lines ) const +void QCPPolarGraph::drawFill(QCPPainter *painter, QVector *lines) const { - applyFillAntialiasingHint( painter ); - if( painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0 ) - painter->drawPolygon( QPolygonF( *lines ) ); + applyFillAntialiasingHint(painter); + if (painter->brush().style() != Qt::NoBrush && painter->brush().color().alpha() != 0) + painter->drawPolygon(QPolygonF(*lines)); } /*! \internal @@ -35697,104 +35132,103 @@ void QCPPolarGraph::drawFill( QCPPainter* painter, QVector* lines ) con \see drawLinePlot, drawImpulsePlot */ -void QCPPolarGraph::drawScatterPlot( QCPPainter* painter, const QVector& scatters, const QCPScatterStyle& style ) const +void QCPPolarGraph::drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const { - applyScattersAntialiasingHint( painter ); - style.applyTo( painter, mPen ); - for( int i = 0; i < scatters.size(); ++i ) - style.drawShape( painter, scatters.at( i ).x(), scatters.at( i ).y() ); + applyScattersAntialiasingHint(painter); + style.applyTo(painter, mPen); + for (int i=0; ifillRect( 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()); } } } -void QCPPolarGraph::applyFillAntialiasingHint( QCPPainter* painter ) const +void QCPPolarGraph::applyFillAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiasedFill, QCP::aeFills ); + applyAntialiasingHint(painter, mAntialiasedFill, QCP::aeFills); } -void QCPPolarGraph::applyScattersAntialiasingHint( QCPPainter* painter ) const +void QCPPolarGraph::applyScattersAntialiasingHint(QCPPainter *painter) const { - applyAntialiasingHint( painter, mAntialiasedScatters, QCP::aeScatters ); + applyAntialiasingHint(painter, mAntialiasedScatters, QCP::aeScatters); } -double QCPPolarGraph::pointDistance( const QPointF& pixelPoint, QCPGraphDataContainer::const_iterator& closestData ) const +double QCPPolarGraph::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)(); // 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 ); - for( int i = 0; i < lineData.size() - 1; ++i ) + getLines(&lineData, QCPDataRange(0, dataCount())); + QCPVector2D p(pixelPoint); + for (int i=0; isize(); } -void QCPPolarGraph::getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const +void QCPPolarGraph::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(); } } -void QCPPolarGraph::drawPolyline( QCPPainter* painter, const QVector& lineData ) const +void QCPPolarGraph::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); } } -void QCPPolarGraph::getVisibleDataBounds( QCPGraphDataContainer::const_iterator& begin, QCPGraphDataContainer::const_iterator& end, const QCPDataRange& rangeRestriction ) const +void QCPPolarGraph::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 { - QCPPolarAxisAngular* keyAxis = mKeyAxis.data(); - QCPPolarAxisRadial* valueAxis = mValueAxis.data(); - if( !keyAxis || !valueAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } + QCPPolarAxisAngular *keyAxis = mKeyAxis.data(); + QCPPolarAxisRadial *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } // get visible data range: - if( mPeriodic ) + if (mPeriodic) { begin = mDataContainer->constBegin(); end = mDataContainer->constEnd(); - } - else + } else { - 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 } } @@ -35921,169 +35346,157 @@ void QCPPolarGraph::getVisibleDataBounds( QCPGraphDataContainer::const_iterator& \see getScatters */ -void QCPPolarGraph::getLines( QVector* lines, const QCPDataRange& dataRange ) const +void QCPPolarGraph::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 (mLineStyle != lsNone) + getOptimizedLineData(&lineData, begin, end); - switch( mLineStyle ) + switch (mLineStyle) { - case lsNone: - lines->clear(); - break; - case lsLine: - *lines = dataToLines( lineData ); - break; + case lsNone: lines->clear(); break; + case lsLine: *lines = dataToLines(lineData); break; } } -void QCPPolarGraph::getScatters( QVector* scatters, const QCPDataRange& dataRange ) const +void QCPPolarGraph::getScatters(QVector *scatters, const QCPDataRange &dataRange) const { - QCPPolarAxisAngular* keyAxis = mKeyAxis.data(); - QCPPolarAxisRadial* valueAxis = mValueAxis.data(); - if( !keyAxis || !valueAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return; - } - - if( !scatters ) - return; + QCPPolarAxisAngular *keyAxis = mKeyAxis.data(); + QCPPolarAxisRadial *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return; } + + if (!scatters) 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 ); - - scatters->resize( data.size() ); - for( int i = 0; i < data.size(); ++i ) + getOptimizedScatterData(&data, begin, end); + + scatters->resize(data.size()); + for (int i=0; icoordToPixel( data.at( i ).key, data.at( i ).value ); + if (!qIsNaN(data.at(i).value)) + (*scatters)[i] = valueAxis->coordToPixel(data.at(i).key, data.at(i).value); } } -void QCPPolarGraph::getOptimizedLineData( QVector* lineData, const QCPGraphDataContainer::const_iterator& begin, const QCPGraphDataContainer::const_iterator& end ) const +void QCPPolarGraph::getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const { lineData->clear(); - + // TODO: fix for log axes and thick line style - + const QCPRange range = mValueAxis->range(); bool reversed = mValueAxis->rangeReversed(); - const double clipMargin = range.size() * 0.05; // extra distance from visible circle, so optimized outside lines can cover more angle before having to place a dummy point to prevent tangents - const double upperClipValue = range.upper + ( reversed ? 0 : range.size() * 0.05 + clipMargin ); // clip slightly outside of actual range to avoid line thicknesses to peek into visible circle - const double lowerClipValue = range.lower - ( reversed ? range.size() * 0.05 + clipMargin : 0 ); // clip slightly outside of actual range to avoid line thicknesses to peek into visible circle - const double maxKeySkip = qAsin( qSqrt( clipMargin * ( clipMargin + 2 * range.size() ) ) / ( range.size() + clipMargin ) ) / M_PI * mKeyAxis->range().size(); // the maximum angle between two points on outer circle (r=clipValue+clipMargin) before connecting line becomes tangent to inner circle (r=clipValue) + const double clipMargin = range.size()*0.05; // extra distance from visible circle, so optimized outside lines can cover more angle before having to place a dummy point to prevent tangents + const double upperClipValue = range.upper + (reversed ? 0 : range.size()*0.05+clipMargin); // clip slightly outside of actual range to avoid line thicknesses to peek into visible circle + const double lowerClipValue = range.lower - (reversed ? range.size()*0.05+clipMargin : 0); // clip slightly outside of actual range to avoid line thicknesses to peek into visible circle + const double maxKeySkip = qAsin(qSqrt(clipMargin*(clipMargin+2*range.size()))/(range.size()+clipMargin))/M_PI*mKeyAxis->range().size(); // the maximum angle between two points on outer circle (r=clipValue+clipMargin) before connecting line becomes tangent to inner circle (r=clipValue) double skipBegin = 0; bool belowRange = false; bool aboveRange = false; QCPGraphDataContainer::const_iterator it = begin; - while( it != end ) + while (it != end) { - if( it->value < lowerClipValue ) + if (it->value < lowerClipValue) { - if( aboveRange ) // jumped directly from above to below visible range, draw previous point so entry angle is correct + if (aboveRange) // jumped directly from above to below visible range, draw previous point so entry angle is correct { aboveRange = false; - if( !reversed ) // TODO: with inner radius, we'll need else case here with projected border point - lineData->append( *( it - 1 ) ); + if (!reversed) // TODO: with inner radius, we'll need else case here with projected border point + lineData->append(*(it-1)); } - if( !belowRange ) + if (!belowRange) { skipBegin = it->key; - lineData->append( QCPGraphData( it->key, lowerClipValue ) ); + lineData->append(QCPGraphData(it->key, lowerClipValue)); belowRange = true; } - if( it->key - skipBegin > maxKeySkip ) // add dummy point if we're exceeding the maximum skippable angle (to prevent unintentional intersections with visible circle) + if (it->key-skipBegin > maxKeySkip) // add dummy point if we're exceeding the maximum skippable angle (to prevent unintentional intersections with visible circle) { skipBegin += maxKeySkip; - lineData->append( QCPGraphData( skipBegin, lowerClipValue ) ); + lineData->append(QCPGraphData(skipBegin, lowerClipValue)); } - } - else if( it->value > upperClipValue ) + } else if (it->value > upperClipValue) { - if( belowRange ) // jumped directly from below to above visible range, draw previous point so entry angle is correct (if lower means outer, so if reversed axis) + if (belowRange) // jumped directly from below to above visible range, draw previous point so entry angle is correct (if lower means outer, so if reversed axis) { belowRange = false; - if( reversed ) - lineData->append( *( it - 1 ) ); + if (reversed) + lineData->append(*(it-1)); } - if( !aboveRange ) + if (!aboveRange) { skipBegin = it->key; - lineData->append( QCPGraphData( it->key, upperClipValue ) ); + lineData->append(QCPGraphData(it->key, upperClipValue)); aboveRange = true; } - if( it->key - skipBegin > maxKeySkip ) // add dummy point if we're exceeding the maximum skippable angle (to prevent unintentional intersections with visible circle) + if (it->key-skipBegin > maxKeySkip) // add dummy point if we're exceeding the maximum skippable angle (to prevent unintentional intersections with visible circle) { skipBegin += maxKeySkip; - lineData->append( QCPGraphData( skipBegin, upperClipValue ) ); + lineData->append(QCPGraphData(skipBegin, upperClipValue)); } - } - else // value within bounds where we don't optimize away points + } else // value within bounds where we don't optimize away points { - if( aboveRange ) + if (aboveRange) { aboveRange = false; - if( !reversed ) - lineData->append( *( it - 1 ) ); // just entered from above, draw previous point so entry angle is correct (if above means outer, so if not reversed axis) + if (!reversed) + lineData->append(*(it-1)); // just entered from above, draw previous point so entry angle is correct (if above means outer, so if not reversed axis) } - if( belowRange ) + if (belowRange) { belowRange = false; - if( reversed ) - lineData->append( *( it - 1 ) ); // just entered from below, draw previous point so entry angle is correct (if below means outer, so if reversed axis) + if (reversed) + lineData->append(*(it-1)); // just entered from below, draw previous point so entry angle is correct (if below means outer, so if reversed axis) } - lineData->append( *it ); // inside visible circle, add point normally + lineData->append(*it); // inside visible circle, add point normally } ++it; } // to make fill not erratic, add last point normally if it was outside visible circle: - if( aboveRange ) + if (aboveRange) { aboveRange = false; - if( !reversed ) - lineData->append( *( it - 1 ) ); // just entered from above, draw previous point so entry angle is correct (if above means outer, so if not reversed axis) + if (!reversed) + lineData->append(*(it-1)); // just entered from above, draw previous point so entry angle is correct (if above means outer, so if not reversed axis) } - if( belowRange ) + if (belowRange) { belowRange = false; - if( reversed ) - lineData->append( *( it - 1 ) ); // just entered from below, draw previous point so entry angle is correct (if below means outer, so if reversed axis) + if (reversed) + lineData->append(*(it-1)); // just entered from below, draw previous point so entry angle is correct (if below means outer, so if reversed axis) } } -void QCPPolarGraph::getOptimizedScatterData( QVector* scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end ) const +void QCPPolarGraph::getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const { scatterData->clear(); - + const QCPRange range = mValueAxis->range(); bool reversed = mValueAxis->rangeReversed(); - const double clipMargin = range.size() * 0.05; - const double upperClipValue = range.upper + ( reversed ? 0 : clipMargin ); // clip slightly outside of actual range to avoid scatter size to peek into visible circle - const double lowerClipValue = range.lower - ( reversed ? clipMargin : 0 ); // clip slightly outside of actual range to avoid scatter size to peek into visible circle + const double clipMargin = range.size()*0.05; + const double upperClipValue = range.upper + (reversed ? 0 : clipMargin); // clip slightly outside of actual range to avoid scatter size to peek into visible circle + const double lowerClipValue = range.lower - (reversed ? clipMargin : 0); // clip slightly outside of actual range to avoid scatter size to peek into visible circle QCPGraphDataContainer::const_iterator it = begin; - while( it != end ) + while (it != end) { - if( it->value > lowerClipValue && it->value < upperClipValue ) - scatterData->append( *it ); + if (it->value > lowerClipValue && it->value < upperClipValue) + scatterData->append(*it); ++it; } } @@ -36098,21 +35511,19 @@ void QCPPolarGraph::getOptimizedScatterData( QVector* scatterData, \see dataToStepLeftLines, dataToStepRightLines, dataToStepCenterLines, dataToImpulseLines, getLines, drawLinePlot */ -QVector QCPPolarGraph::dataToLines( const QVector& data ) const +QVector QCPPolarGraph::dataToLines(const QVector &data) const { QVector result; - QCPPolarAxisAngular* keyAxis = mKeyAxis.data(); - QCPPolarAxisRadial* valueAxis = mValueAxis.data(); - if( !keyAxis || !valueAxis ) - { - qDebug() << Q_FUNC_INFO << "invalid key or value axis"; - return result; - } + QCPPolarAxisAngular *keyAxis = mKeyAxis.data(); + QCPPolarAxisRadial *valueAxis = mValueAxis.data(); + if (!keyAxis || !valueAxis) { qDebug() << Q_FUNC_INFO << "invalid key or value axis"; return result; } // transform data points to pixels: - result.resize( data.size() ); - for( int i = 0; i < data.size(); ++i ) - result[i] = mValueAxis->coordToPixel( data.at( i ).key, data.at( i ).value ); + result.resize(data.size()); + for (int i=0; icoordToPixel(data.at(i).key, data.at(i).value); return result; } /* end of 'src/polar/polargraph.cpp' */ + + diff --git a/app/external/qcustomplot/qcustomplot.h b/app/external/qcustomplot/qcustomplot.h index 54ad96a..02ed8fb 100644 --- a/app/external/qcustomplot/qcustomplot.h +++ b/app/external/qcustomplot/qcustomplot.h @@ -1,7 +1,7 @@ /*************************************************************************** ** ** ** QCustomPlot, an easy to use, modern plotting widget for Qt ** -** Copyright (C) 2011-2021 Emanuel Eichhammer ** +** Copyright (C) 2011-2022 Emanuel Eichhammer ** ** ** ** This program is free software: you can redistribute it and/or modify ** ** it under the terms of the GNU General Public License as published by ** @@ -18,9 +18,9 @@ ** ** **************************************************************************** ** Author: Emanuel Eichhammer ** -** Website/Contact: http://www.qcustomplot.com/ ** -** Date: 29.03.21 ** -** Version: 2.1.0 ** +** Website/Contact: https://www.qcustomplot.com/ ** +** Date: 06.11.22 ** +** Version: 2.1.1 ** ****************************************************************************/ #ifndef QCUSTOMPLOT_H @@ -30,79 +30,77 @@ // 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 #ifdef QCP_OPENGL_FBO -#include -#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) -#include -#else -#include -#include -#endif -#ifdef QCP_OPENGL_OFFSCREENSURFACE -#include -#else -#include -#endif +# include +# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +# include +# else +# include +# include +# endif +# 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 -#if QT_VERSION >= QT_VERSION_CHECK( 4, 8, 0 ) -#include +#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) +# include #endif -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) -#include +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) +# include #endif class QCPPainter; @@ -131,25 +129,25 @@ class QCPPolarGrid; class QCPPolarGraph; /* including file 'src/global.h' */ -/* modified 2021-03-29T02:30:44, size 16981 */ +/* modified 2022-11-06T12:45:57, size 18102 */ -#define QCUSTOMPLOT_VERSION_STR "2.1.0" -#define QCUSTOMPLOT_VERSION 0x020100 +#define QCUSTOMPLOT_VERSION_STR "2.1.1" +#define QCUSTOMPLOT_VERSION 0x020101 // 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 /*! @@ -158,55 +156,55 @@ class QCPPolarGraph; It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject. */ -#ifndef Q_MOC_RUN -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 + +// Qt version < 6.2.0: to get metatypes Q_GADGET/Q_ENUMS/Q_FLAGS in namespace we have to make it look like a class during moc-run +#if QT_VERSION >= 0x060200 // don't use QT_VERSION_CHECK here, some moc versions don't understand it +namespace QCP { + Q_NAMESPACE // this is how to add the staticMetaObject to namespaces in newer Qt versions +#else // Qt version older than 6.2.0 +# ifndef Q_MOC_RUN +namespace QCP { +# else // not in moc run +class QCP { 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_ENUMS(AntialiasedElement) + Q_ENUMS(PlottingHint) + Q_ENUMS(Interaction) + Q_ENUMS(SelectionRectMode) + Q_ENUMS(SelectionType) + + Q_FLAGS(AntialiasedElements) + Q_FLAGS(PlottingHints) + Q_FLAGS(MarginSides) + Q_FLAGS(Interactions) public: +# endif #endif + /*! Defines the different units in which the image resolution can be specified in the export functions. \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 @@ -215,35 +213,24 @@ enum ExportPen 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 @@ -254,54 +241,35 @@ 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. @@ -310,45 +278,29 @@ Q_DECLARE_FLAGS( PlottingHints, PlottingHint ) \see QCustomPlot::setInteractions */ -enum Interaction -{ - iNone = 0x000 ///< 0x000 None of the interactions are possible - , - 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,...) - , - iSelectPlottablesBeyondAxisRect = 0x100 ///< 0x100 When performing plottable selection/hit tests, this flag extends the sensitive area beyond the axis rect -}; -Q_DECLARE_FLAGS( Interactions, Interaction ) +enum Interaction { iNone = 0x000 ///< 0x000 None of the interactions are possible + ,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,...) + ,iSelectPlottablesBeyondAxisRect = 0x100 ///< 0x100 When performing plottable selection/hit tests, this flag extends the sensitive area beyond the axis rect + }; +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 @@ -368,18 +320,12 @@ enum SelectionRectMode \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 @@ -387,9 +333,9 @@ enum SelectionType 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 @@ -397,9 +343,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 @@ -408,27 +354,16 @@ 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; } } @@ -439,137 +374,143 @@ 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 +// for newer Qt versions we have to declare the enums/flags as metatypes inside the namespace using Q_ENUM_NS/Q_FLAG_NS: +// if you change anything here, don't forget to change it for older Qt versions below, too, +// and at the start of the namespace in the fake moc-run class +#if QT_VERSION >= 0x060200 +Q_ENUM_NS(ExportPen) +Q_ENUM_NS(ResolutionUnit) +Q_ENUM_NS(SignDomain) +Q_ENUM_NS(MarginSide) +Q_ENUM_NS(AntialiasedElement) +Q_ENUM_NS(PlottingHint) +Q_ENUM_NS(Interaction) +Q_ENUM_NS(SelectionRectMode) +Q_ENUM_NS(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 ) +Q_FLAG_NS(AntialiasedElements) +Q_FLAG_NS(PlottingHints) +Q_FLAG_NS(MarginSides) +Q_FLAG_NS(Interactions) +#else +extern const QMetaObject staticMetaObject; +#endif + +} // 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) + +// for older Qt versions we have to declare the enums/flags as metatypes outside the namespace using Q_DECLARE_METATYPE: +// if you change anything here, don't forget to change it for newer Qt versions above, too, +// and at the start of the namespace in the fake moc-run class +#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0) +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) +#endif /* end of 'src/global.h' */ + /* including file 'src/vector2d.h' */ -/* modified 2021-03-29T02:30:44, size 4988 */ +/* modified 2022-11-06T12:45:56, size 4988 */ 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; } - double angle() const { return qAtan2( mY, mX ); } - QPoint toPoint() const { return QPoint( int( mX ), int( 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; } + double angle() const { return qAtan2(mY, mX); } + QPoint toPoint() const { return QPoint(int(mX), int(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 ); + + 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 ); +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 ); -} +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' */ -/* modified 2021-03-29T02:30:44, size 4035 */ +/* modified 2022-11-06T12:45:56, size 4035 */ class QCP_LIB_DECL QCPPainter : public QPainter { @@ -579,177 +520,178 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 5006 */ +/* modified 2022-11-06T12:45:56, size 5006 */ 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() Q_DECL_OVERRIDE; - + // 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() Q_DECL_OVERRIDE; - + // 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() Q_DECL_OVERRIDE; - + // 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' */ -/* modified 2021-03-29T02:30:44, size 7038 */ +/* modified 2022-11-06T12:45:56, size 7038 */ 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 @@ -757,127 +699,124 @@ 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 = nullptr ); + QCPLayerable(QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr); 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 = nullptr ) const; + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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; @@ -885,90 +824,68 @@ private: /* end of 'src/layer.h' */ + /* including file 'src/axis/range.h' */ -/* modified 2021-03-29T02:30:44, size 5280 */ +/* modified 2022-11-06T12:45:56, size 5280 */ 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; } @@ -976,9 +893,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; } @@ -986,9 +903,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; } @@ -996,9 +913,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; } @@ -1006,9 +923,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; } @@ -1016,107 +933,111 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 8569 */ +/* modified 2022-11-06T12:45:56, size 8569 */ 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; } @@ -1125,9 +1046,9 @@ inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDat 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; } @@ -1136,9 +1057,9 @@ inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataSel 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; } @@ -1147,9 +1068,9 @@ inline const QCPDataSelection operator+( const QCPDataSelection& a, const QCPDat 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; } @@ -1157,9 +1078,9 @@ inline const QCPDataSelection operator+( const QCPDataRange& a, const QCPDataRan /*! 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; } @@ -1167,9 +1088,9 @@ inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDat /*! 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; } @@ -1177,9 +1098,9 @@ inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataSel /*! 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; } @@ -1187,9 +1108,9 @@ inline const QCPDataSelection operator-( const QCPDataSelection& a, const QCPDat /*! 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; } @@ -1198,7 +1119,7 @@ inline const QCPDataSelection operator-( const QCPDataRange& a, const QCPDataRan 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; @@ -1208,51 +1129,54 @@ 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 < selection.dataRangeCount(); ++i ) - { - if( i != 0 ) - d << ", "; - d << selection.dataRange( i ); - } - d << ")"; - return d; + 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 @@ -1345,19 +1267,16 @@ 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 = nullptr ); + explicit QCPLayoutElement(QCustomPlot *parentPlot=nullptr); virtual ~QCPLayoutElement() Q_DECL_OVERRIDE; - + // 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; } @@ -1366,111 +1285,114 @@ 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, nullptr ); } + QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, nullptr); } 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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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 @@ -1478,17 +1400,14 @@ 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() Q_DECL_OVERRIDE; - + // getters: int rowCount() const { return mElements.size(); } int columnCount() const { return mElements.size() > 0 ? mElements.first().size() : 0; } @@ -1498,39 +1417,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; @@ -1539,15 +1458,16 @@ 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; - + void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const; + void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const; + private: - Q_DISABLE_COPY( QCPLayoutGrid ) + Q_DISABLE_COPY(QCPLayoutGrid) }; -Q_DECLARE_METATYPE( QCPLayoutGrid::FillOrder ) +Q_DECLARE_METATYPE(QCPLayoutGrid::FillOrder) + class QCP_LIB_DECL QCPLayoutInset : public QCPLayout { @@ -1556,56 +1476,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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 4426 */ +/* modified 2022-11-06T12:45:56, size 4426 */ class QCP_LIB_DECL QCPLineEnding { @@ -1622,64 +1540,54 @@ 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/labelpainter.h' */ -/* modified 2021-03-29T02:30:44, size 7086 */ +/* modified 2022-11-06T12:45:56, size 7086 */ class QCPLabelPainterPrivate { @@ -1688,64 +1596,51 @@ public: /*! TODO */ - enum AnchorMode - { - amRectangular ///< - , - amSkewedUpright ///< - , - amSkewedRotated ///< - }; - Q_ENUMS( AnchorMode ) - + enum AnchorMode { amRectangular ///< + ,amSkewedUpright ///< + ,amSkewedRotated ///< + }; + Q_ENUMS(AnchorMode) + /*! TODO */ - enum AnchorReferenceType - { - artNormal ///< - , - artTangent ///< - }; - Q_ENUMS( AnchorReferenceType ) - + enum AnchorReferenceType { artNormal ///< + ,artTangent ///< + }; + Q_ENUMS(AnchorReferenceType) + /*! TODO */ - enum AnchorSide - { - asLeft ///< - , - asRight ///< - , - asTop ///< - , - asBottom ///< - , - asTopLeft, - asTopRight, - asBottomRight, - asBottomLeft - }; - Q_ENUMS( AnchorSide ) - - explicit QCPLabelPainterPrivate( QCustomPlot* parentPlot ); + enum AnchorSide { asLeft ///< + ,asRight ///< + ,asTop ///< + ,asBottom ///< + ,asTopLeft + ,asTopRight + ,asBottomRight + ,asBottomLeft + }; + Q_ENUMS(AnchorSide) + + explicit QCPLabelPainterPrivate(QCustomPlot *parentPlot); virtual ~QCPLabelPainterPrivate(); - + // setters: - void setAnchorSide( AnchorSide side ); - void setAnchorMode( AnchorMode mode ); - void setAnchorReference( const QPointF& pixelPoint ); - void setAnchorReferenceType( AnchorReferenceType type ); - void setFont( const QFont& font ); - void setColor( const QColor& color ); - void setPadding( int padding ); - void setRotation( double rotation ); - void setSubstituteExponent( bool enabled ); - void setMultiplicationSymbol( QChar symbol ); - void setAbbreviateDecimalPowers( bool enabled ); - void setCacheSize( int labelCount ); - + void setAnchorSide(AnchorSide side); + void setAnchorMode(AnchorMode mode); + void setAnchorReference(const QPointF &pixelPoint); + void setAnchorReferenceType(AnchorReferenceType type); + void setFont(const QFont &font); + void setColor(const QColor &color); + void setPadding(int padding); + void setRotation(double rotation); + void setSubstituteExponent(bool enabled); + void setMultiplicationSymbol(QChar symbol); + void setAbbreviateDecimalPowers(bool enabled); + void setCacheSize(int labelCount); + // getters: AnchorMode anchorMode() const { return mAnchorMode; } AnchorSide anchorSide() const { return mAnchorSide; } @@ -1759,17 +1654,17 @@ public: QChar multiplicationSymbol() const { return mMultiplicationSymbol; } bool abbreviateDecimalPowers() const { return mAbbreviateDecimalPowers; } int cacheSize() const; - + //virtual int size() const; - - // non-property methods: - void drawTickLabel( QCPPainter* painter, const QPointF& tickPos, const QString& text ); + + // non-property methods: + void drawTickLabel(QCPPainter *painter, const QPointF &tickPos, const QString &text); void clearCache(); - + // constants that may be used with setMultiplicationSymbol: static const QChar SymbolDot; static const QChar SymbolCross; - + protected: struct CachedLabel { @@ -1779,16 +1674,16 @@ protected: struct LabelData { AnchorSide side; - double rotation; // angle in degrees - QTransform transform; // the transform about the label anchor which is at (0, 0). Does not contain final absolute x/y positioning on the plot/axis + double rotation; // angle in degrees + QTransform transform; // the transform about the label anchor which is at (0, 0). Does not contain final absolute x/y positioning on the plot/axis QString basePart, expPart, suffixPart; QRect baseBounds, expBounds, suffixBounds; - QRect totalBounds; // is in a coordinate system where label top left is at (0, 0) - QRect rotatedTotalBounds; // is in a coordinate system where the label anchor is at (0, 0) + QRect totalBounds; // is in a coordinate system where label top left is at (0, 0) + QRect rotatedTotalBounds; // is in a coordinate system where the label anchor is at (0, 0) QFont baseFont, expFont; QColor color; }; - + // property members: AnchorMode mAnchorMode; AnchorSide mAnchorSide; @@ -1797,40 +1692,42 @@ protected: QFont mFont; QColor mColor; int mPadding; - double mRotation; // this is the rotation applied uniformly to all labels, not the heterogeneous rotation in amCircularRotated mode + double mRotation; // this is the rotation applied uniformly to all labels, not the heterogeneous rotation in amCircularRotated mode bool mSubstituteExponent; QChar mMultiplicationSymbol; bool mAbbreviateDecimalPowers; // non-property members: - 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; int mLetterCapHeight, mLetterDescent; - + // introduced virtual methods: - virtual void drawLabelMaybeCached( QCPPainter* painter, const QFont& font, const QColor& color, const QPointF& pos, AnchorSide side, double rotation, const QString& text ); - virtual QByteArray generateLabelParameterHash() const; // TODO: get rid of this in favor of invalidation flag upon setters? + virtual void drawLabelMaybeCached(QCPPainter *painter, const QFont &font, const QColor &color, const QPointF &pos, AnchorSide side, double rotation, const QString &text); + virtual QByteArray generateLabelParameterHash() const; // TODO: get rid of this in favor of invalidation flag upon setters? // non-virtual methods: - QPointF getAnchorPos( const QPointF& tickPos ); - void drawText( QCPPainter* painter, const QPointF& pos, const LabelData& labelData ) const; - LabelData getTickLabelData( const QFont& font, const QColor& color, double rotation, AnchorSide side, const QString& text ) const; - void applyAnchorTransform( LabelData& labelData ) const; + QPointF getAnchorPos(const QPointF &tickPos); + void drawText(QCPPainter *painter, const QPointF &pos, const LabelData &labelData) const; + LabelData getTickLabelData(const QFont &font, const QColor &color, double rotation, AnchorSide side, const QString &text) const; + void applyAnchorTransform(LabelData &labelData) const; //void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const; - CachedLabel* createCachedLabel( const LabelData& labelData ) const; - QByteArray cacheKey( const QString& text, const QColor& color, double rotation, AnchorSide side ) const; - AnchorSide skewedAnchorSide( const QPointF& tickPos, double sideExpandHorz, double sideExpandVert ) const; - AnchorSide rotationCorrectedSide( AnchorSide side, double rotation ) const; + CachedLabel *createCachedLabel(const LabelData &labelData) const; + QByteArray cacheKey(const QString &text, const QColor &color, double rotation, AnchorSide side) const; + AnchorSide skewedAnchorSide(const QPointF &tickPos, double sideExpandHorz, double sideExpandVert) const; + AnchorSide rotationCorrectedSide(AnchorSide side, double rotation) const; void analyzeFontMetrics(); }; -Q_DECLARE_METATYPE( QCPLabelPainterPrivate::AnchorMode ) -Q_DECLARE_METATYPE( QCPLabelPainterPrivate::AnchorSide ) +Q_DECLARE_METATYPE(QCPLabelPainterPrivate::AnchorMode) +Q_DECLARE_METATYPE(QCPLabelPainterPrivate::AnchorSide) + /* end of 'src/axis/labelpainter.h' */ + /* including file 'src/axis/axisticker.h' */ -/* modified 2021-03-29T02:30:44, size 4230 */ +/* modified 2022-11-06T12:45:56, size 4230 */ class QCP_LIB_DECL QCPAxisTicker { @@ -1843,114 +1740,108 @@ 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 = nullptr ) 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=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 3600 */ +/* modified 2022-11-06T12:45:56, size 3600 */ class QCP_LIB_DECL QCPAxisTickerDateTime : public QCPAxisTicker { public: QCPAxisTickerDateTime(); - + // getters: QString dateTimeFormat() const { return mDateTimeFormat; } Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; } -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) - QTimeZone timeZone() const - { - return mTimeZone; - } +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + QTimeZone timeZone() const { return mTimeZone; } #endif - + // setters: - void setDateTimeFormat( const QString& format ); - void setDateTimeSpec( Qt::TimeSpec spec ); -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) - void setTimeZone( const QTimeZone& zone ); -#endif - 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); +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) + void setTimeZone(const QTimeZone &zone); +# endif + 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, Qt::TimeSpec timeSpec = Qt::LocalTime ); - + static QDateTime keyToDateTime(double key); + static double dateTimeToKey(const QDateTime &dateTime); + static double dateTimeToKey(const QDate &date, Qt::TimeSpec timeSpec=Qt::LocalTime); + protected: // property members: QString mDateTimeFormat; Qt::TimeSpec mDateTimeSpec; -#if QT_VERSION >= QT_VERSION_CHECK( 5, 2, 0 ) +# if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) QTimeZone mTimeZone; -#endif +# endif // 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' */ -/* modified 2021-03-29T02:30:44, size 3542 */ +/* modified 2022-11-06T12:45:56, size 3542 */ class QCP_LIB_DECL QCPAxisTickerTime : public QCPAxisTicker { @@ -1961,53 +1852,48 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 3308 */ +/* modified 2022-11-06T12:45:56, size 3308 */ class QCP_LIB_DECL QCPAxisTickerFixed : public QCPAxisTicker { @@ -2019,77 +1905,75 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 3090 */ +/* modified 2022-11-06T12:45:56, size 3090 */ 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' */ -/* modified 2021-03-29T02:30:44, size 3911 */ +/* modified 2022-11-06T12:45:56, size 3911 */ class QCP_LIB_DECL QCPAxisTickerPi : public QCPAxisTicker { @@ -2100,104 +1984,102 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 2594 */ +/* modified 2022-11-06T12:45:56, size 2594 */ 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 int getSubTickCount( double tickStep ) Q_DECL_OVERRIDE; - virtual QVector createTickVector( double tickStep, 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' */ -/* modified 2021-03-29T02:30:44, size 20913 */ -class QCP_LIB_DECL QCPGrid : public QCPLayerable +/* including file 'src/axis/axis.h' */ +/* modified 2022-11-06T12:45:56, size 20913 */ + +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; } @@ -2205,148 +2087,133 @@ 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() Q_DECL_OVERRIDE; - + // 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; } @@ -2387,88 +2254,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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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; @@ -2500,10 +2367,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; @@ -2513,23 +2380,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; @@ -2539,61 +2406,62 @@ 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(); 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; - int offset; // directly accessed by QCPAxis setters/getters + int offset; // directly accessed by QCPAxis setters/getters bool abbreviateDecimalPowers; bool reversedEndings; - + QVector subTickPositions; QVector tickPositions; QVector tickLabels; - + protected: struct CachedLabel { @@ -2606,24 +2474,25 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7275 */ +/* modified 2022-11-06T12:45:56, size 7275 */ class QCP_LIB_DECL QCPScatterStyle { @@ -2637,23 +2506,16 @@ 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. @@ -2662,54 +2524,35 @@ 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; } @@ -2719,21 +2562,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: @@ -2743,19 +2586,20 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 34070 */ +/* modified 2022-11-06T12:45:56, size 34305 */ /*! \relates QCPDataContainer Returns whether the sort key of \a a is less than the sort key of \a b. @@ -2763,68 +2607,67 @@ 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(); }; + + // include implementation in header since it is a class template: //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPDataContainer @@ -2960,8 +2803,10 @@ protected: data */ template -QCPDataContainer::QCPDataContainer() - : mAutoSqueeze( true ), mPreallocSize( 0 ), mPreallocIteration( 0 ) +QCPDataContainer::QCPDataContainer() : + mAutoSqueeze(true), + mPreallocSize(0), + mPreallocIteration(0) { } @@ -2974,12 +2819,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(); } } @@ -2991,10 +2836,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 @@ -3007,12 +2852,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(); } @@ -3023,27 +2868,26 @@ void QCPDataContainer::set( const QVector& data, bool alread \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); } } @@ -3056,34 +2900,33 @@ 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); } } @@ -3094,23 +2937,21 @@ void QCPDataContainer::add( const QVector& data, bool alread \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); } } @@ -3120,12 +2961,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 += int( 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 += int(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(); } @@ -3135,12 +2976,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(); } @@ -3152,15 +2993,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(); } @@ -3174,17 +3015,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(); } @@ -3215,7 +3056,7 @@ void QCPDataContainer::clear() template void QCPDataContainer::sort() { - std::sort( begin(), end(), qcpLessThanSortKey ); + std::sort(begin(), end(), qcpLessThanSortKey); } /*! @@ -3229,19 +3070,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(); } @@ -3261,13 +3102,13 @@ void QCPDataContainer::squeeze( bool preAllocation, bool postAllocatio \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; } @@ -3288,13 +3129,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; } @@ -3315,9 +3156,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(); @@ -3326,16 +3167,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; @@ -3344,30 +3185,29 @@ 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; @@ -3376,20 +3216,39 @@ 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 ) + 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) { range.upper = current; haveUpper = true; @@ -3398,28 +3257,7 @@ 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; } @@ -3430,6 +3268,8 @@ QCPRange QCPDataContainer::keyRange( bool& foundRange, QCP::SignDomain output parameter \a foundRange indicates whether a sensible range was found. If this is false, you should not use the returned QCPRange (e.g. the data container is empty or all points have the same value). + + Inf and -Inf data values are ignored. If \a inKeyRange has both lower and upper bound set to zero (is equal to QCPRange()), all data points are considered, without any restriction on the keys. @@ -3441,9 +3281,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(); @@ -3455,69 +3295,67 @@ QCPRange QCPDataContainer::valueRange( bool& foundRange, QCP::SignDoma QCPRange current; QCPDataContainer::const_iterator itBegin = constBegin(); QCPDataContainer::const_iterator itEnd = constEnd(); - if( DataType::sortKeyIsMainKey() && restrictKeyRange ) + if (DataType::sortKeyIsMainKey() && restrictKeyRange) { - itBegin = findBegin( inKeyRange.lower, false ); - itEnd = findEnd( inKeyRange.upper, false ); + itBegin = findBegin(inKeyRange.lower, false); + itEnd = findEnd(inKeyRange.upper, false); } - 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) && std::isfinite(current.lower)) { range.lower = current.lower; haveLower = true; } - if( ( current.upper > range.upper || !haveUpper ) && !qIsNaN( current.upper ) ) + if ((current.upper > range.upper || !haveUpper) && !qIsNaN(current.upper) && std::isfinite(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) && std::isfinite(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper < 0 && !qIsNaN(current.upper) && std::isfinite(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) && std::isfinite(current.lower)) + { + range.lower = current.lower; + haveLower = true; + } + if ((current.upper > range.upper || !haveUpper) && current.upper > 0 && !qIsNaN(current.upper) && std::isfinite(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; } @@ -3531,12 +3369,12 @@ QCPRange QCPDataContainer::valueRange( bool& foundRange, QCP::SignDoma 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( int( begin - constBegin() ), int( end - constBegin() ) ); - iteratorRange = iteratorRange.bounded( dataRange.bounded( this->dataRange() ) ); - begin = constBegin() + iteratorRange.begin(); - end = constBegin() + iteratorRange.end(); + QCPDataRange iteratorRange(int(begin-constBegin()), int(end-constBegin())); + iteratorRange = iteratorRange.bounded(dataRange.bounded(this->dataRange())); + begin = constBegin()+iteratorRange.begin(); + end = constBegin()+iteratorRange.end(); } /*! \internal @@ -3549,18 +3387,18 @@ void QCPDataContainer::limitIteratorsToDataRange( const_iterator& begi 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 << qBound( 4, mPreallocIteration + 4, 15 ) ) - 12; // do 4 up to 32768-12 preallocation, doubling in each intermediate iteration + 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*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*5; + shrinkPreAllocation = mPreallocSize > usedSize*1.5; // preallocation can grow into postallocation, so can be smaller } - - if( shrinkPreAllocation || shrinkPostAllocation ) - squeeze( shrinkPreAllocation, shrinkPostAllocation ); + + if (shrinkPreAllocation || shrinkPostAllocation) + squeeze(shrinkPreAllocation, shrinkPostAllocation); } + /* end of 'src/datacontainer.h' */ + /* including file 'src/plottable.h' */ -/* modified 2021-03-29T02:30:44, size 8461 */ +/* modified 2022-11-06T12:45:56, size 8461 */ class QCP_LIB_DECL QCPSelectionDecorator { @@ -3612,28 +3451,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; @@ -3641,85 +3480,86 @@ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE = 0; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables - virtual QCPPlottableInterface1D* interface1D() { return nullptr; } - 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=nullptr) const Q_DECL_OVERRIDE = 0; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables + virtual QCPPlottableInterface1D *interface1D() { return nullptr; } + 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; @@ -3729,73 +3569,77 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 9425 */ +/* modified 2022-11-06T12:45:56, size 9425 */ 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 nullptr; } - + virtual QCPItemPosition *toQCPItemPosition() { return nullptr; } + // 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 @@ -3806,53 +3650,48 @@ 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() Q_DECL_OVERRIDE; - + // 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& pos ); - 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 &pos); + void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis); + void setAxisRect(QCPAxisRect *axisRect); + void setPixelPosition(const QPointF &pixelPosition); + protected: // property members: PositionType mPositionTypeX, mPositionTypeY; @@ -3860,54 +3699,56 @@ protected: QPointer mAxisRect; double mKey, mValue; QCPItemAnchor *mParentAnchorX, *mParentAnchorY; - + // reimplemented virtual methods: - virtual QCPItemPosition* toQCPItemPosition() Q_DECL_OVERRIDE { return this; } - + virtual QCPItemPosition *toQCPItemPosition() Q_DECL_OVERRIDE { return this; } + private: - Q_DISABLE_COPY( QCPItemPosition ) + Q_DISABLE_COPY(QCPItemPosition) + }; -Q_DECLARE_METATYPE( QCPItemPosition::PositionType ) +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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE = 0; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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; @@ -3915,50 +3756,51 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 19304 */ +/* modified 2022-11-06T12:45:56, size 19304 */ 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: /*! @@ -3966,41 +3808,33 @@ 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 = nullptr ); + 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 = nullptr); virtual ~QCustomPlot() Q_DECL_OVERRIDE; - + // 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; } @@ -4010,135 +3844,135 @@ 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& 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 ); - + 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); + // 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; - template - PlottableType* plottableAt( const QPointF& pos, bool onlySelectable = false, int* dataIndex = nullptr ) const; - QCPAbstractPlottable* plottableAt( const QPointF& pos, bool onlySelectable = false, int* dataIndex = nullptr ) const; - bool hasPlottable( QCPAbstractPlottable* plottable ) const; - + template + PlottableType *plottableAt(const QPointF &pos, bool onlySelectable=false, int *dataIndex=nullptr) const; + QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false, int *dataIndex=nullptr) const; + bool hasPlottable(QCPAbstractPlottable *plottable) const; + // specialized interface for QCPGraph: - QCPGraph* graph( int index ) const; - QCPGraph* graph() const; - QCPGraph* addGraph( QCPAxis* keyAxis = nullptr, QCPAxis* valueAxis = nullptr ); - bool removeGraph( QCPGraph* graph ); - bool removeGraph( int index ); + QCPGraph *graph(int index) const; + QCPGraph *graph() const; + QCPGraph *addGraph(QCPAxis *keyAxis=nullptr, QCPAxis *valueAxis=nullptr); + 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; - template - ItemType* itemAt( const QPointF& pos, bool onlySelectable = false ) const; - QCPAbstractItem* itemAt( const QPointF& pos, bool onlySelectable = false ) const; - bool hasItem( QCPAbstractItem* item ) const; - + template + ItemType *itemAt(const QPointF &pos, bool onlySelectable=false) 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 = nullptr, LayerInsertMode insertMode = limAbove ); - bool removeLayer( QCPLayer* layer ); - bool moveLayer( QCPLayer* layer, QCPLayer* otherLayer, LayerInsertMode insertMode = limAbove ); - + bool addLayer(const QString &name, QCPLayer *otherLayer=nullptr, 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 ); - double replotTime( bool average = false ) const; - + + 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); + double replotTime(bool average=false) const; + 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 afterLayout(); 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; @@ -4150,13 +3984,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; @@ -4176,41 +4010,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 = nullptr ) const; - QList layerableListAt( const QPointF& pos, bool onlySelectable, QList* selectionDetails = nullptr ) const; - void drawBackground( QCPPainter* painter ); + QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=nullptr) const; + QList layerableListAt(const QPointF &pos, bool onlySelectable, QList *selectionDetails=nullptr) 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; @@ -4219,8 +4053,9 @@ 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) + // implementation of template functions: @@ -4242,23 +4077,23 @@ Q_DECLARE_METATYPE( QCustomPlot::RefreshPriority ) \see itemAt, layoutElementAt */ -template -PlottableType* QCustomPlot::plottableAt( const QPointF& pos, bool onlySelectable, int* dataIndex ) const +template +PlottableType *QCustomPlot::plottableAt(const QPointF &pos, bool onlySelectable, int *dataIndex) const { - PlottableType* resultPlottable = 0; + PlottableType *resultPlottable = 0; QVariant resultDetails; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach( QCPAbstractPlottable* plottable, mPlottables ) + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach (QCPAbstractPlottable *plottable, mPlottables) { - PlottableType* currentPlottable = qobject_cast( plottable ); - if( !currentPlottable || ( onlySelectable && !currentPlottable->selectable() ) ) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractPlottable::selectable + PlottableType *currentPlottable = qobject_cast(plottable); + if (!currentPlottable || (onlySelectable && !currentPlottable->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( currentPlottable->clipRect().contains( pos.toPoint() ) ) // only consider clicks where the plottable is actually visible + if (currentPlottable->clipRect().contains(pos.toPoint())) // only consider clicks where the plottable is actually visible { QVariant details; - double currentDistance = currentPlottable->selectTest( pos, false, dataIndex ? &details : nullptr ); - if( currentDistance >= 0 && currentDistance < resultDistance ) + double currentDistance = currentPlottable->selectTest(pos, false, dataIndex ? &details : nullptr); + if (currentDistance >= 0 && currentDistance < resultDistance) { resultPlottable = currentPlottable; resultDetails = details; @@ -4266,12 +4101,12 @@ PlottableType* QCustomPlot::plottableAt( const QPointF& pos, bool onlySelectable } } } - - if( resultPlottable && dataIndex ) + + if (resultPlottable && dataIndex) { QCPDataSelection sel = resultDetails.value(); - if( !sel.isEmpty() ) - *dataIndex = sel.dataRange( 0 ).begin(); + if (!sel.isEmpty()) + *dataIndex = sel.dataRange(0).begin(); } return resultPlottable; } @@ -4289,35 +4124,38 @@ PlottableType* QCustomPlot::plottableAt( const QPointF& pos, bool onlySelectable \see plottableAt, layoutElementAt */ -template -ItemType* QCustomPlot::itemAt( const QPointF& pos, bool onlySelectable ) const +template +ItemType *QCustomPlot::itemAt(const QPointF &pos, bool onlySelectable) const { - ItemType* resultItem = 0; - double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value - - foreach( QCPAbstractItem* item, mItems ) + ItemType *resultItem = 0; + double resultDistance = mSelectionTolerance; // only regard clicks with distances smaller than mSelectionTolerance as selections, so initialize with that value + + foreach (QCPAbstractItem *item, mItems) { - ItemType* currentItem = qobject_cast( item ); - if( !currentItem || ( onlySelectable && !currentItem->selectable() ) ) // we could have also passed onlySelectable to the selectTest function, but checking here is faster, because we have access to QCPAbstractItem::selectable + ItemType *currentItem = qobject_cast(item); + if (!currentItem || (onlySelectable && !currentItem->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( !currentItem->clipToAxisRect() || currentItem->clipRect().contains( pos.toPoint() ) ) // only consider clicks inside axis cliprect of the item if actually clipped to it + if (!currentItem->clipToAxisRect() || currentItem->clipRect().contains(pos.toPoint())) // only consider clicks inside axis cliprect of the item if actually clipped to it { - double currentDistance = currentItem->selectTest( pos, false ); - if( currentDistance >= 0 && currentDistance < resultDistance ) + double currentDistance = currentItem->selectTest(pos, false); + if (currentDistance >= 0 && currentDistance < resultDistance) { resultItem = currentItem; resultDistance = currentDistance; } } } - + return resultItem; } + + /* end of 'src/core.h' */ + /* including file 'src/plottable1d.h' */ -/* modified 2021-03-29T02:30:44, size 25638 */ +/* modified 2022-11-06T12:45:56, size 25638 */ class QCPPlottableInterface1D { @@ -4325,54 +4163,57 @@ public: virtual ~QCPPlottableInterface1D() = default; // 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D* interface1D() Q_DECL_OVERRIDE { return this; } - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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: //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPPlottableInterface1D @@ -4514,6 +4355,7 @@ private: /* end documentation of pure virtual functions */ + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////// QCPAbstractPlottable1D //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4559,8 +4401,9 @@ 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) { } @@ -4582,13 +4425,12 @@ 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; @@ -4599,13 +4441,12 @@ 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; @@ -4616,13 +4457,12 @@ 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; @@ -4633,16 +4473,15 @@ 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); } } @@ -4650,14 +4489,13 @@ 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(); @@ -4681,48 +4519,47 @@ 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 = int( 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 = int(it-mDataContainer->constBegin()); + } else if (!valueRange.contains(it->mainValue()) || !keyRange.contains(it->mainKey())) // segment just ended { - result.addDataRange( QCPDataRange( currentSegmentBegin, int( it - mDataContainer->constBegin() ) ), false ); + result.addDataRange(QCPDataRange(currentSegmentBegin, int(it-mDataContainer->constBegin())), false); currentSegmentBegin = -1; } } // process potential last segment: - if( currentSegmentBegin != -1 ) - result.addDataRange( QCPDataRange( currentSegmentBegin, int( end - mDataContainer->constBegin() ) ), false ); - + if (currentSegmentBegin != -1) + result.addDataRange(QCPDataRange(currentSegmentBegin, int(end-mDataContainer->constBegin())), false); + result.simplify(); return result; } @@ -4731,18 +4568,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 int( mDataContainer->findBegin( sortKey, expandedRange ) - mDataContainer->constBegin() ); + return int(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 int( mDataContainer->findEnd( sortKey, expandedRange ) - mDataContainer->constBegin() ); + return int(mDataContainer->findEnd(sortKey, expandedRange)-mDataContainer->constBegin()); } /*! @@ -4756,55 +4593,55 @@ int QCPAbstractPlottable1D::findEnd( double sortKey, bool expandedRang \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)(); 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 = int( it - mDataContainer->constBegin() ); + minDistIndex = int(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); } /*! @@ -4818,23 +4655,22 @@ double QCPAbstractPlottable1D::selectTest( const QPointF& pos, bool on \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(); } } @@ -4849,69 +4685,69 @@ void QCPAbstractPlottable1D::getDataSegments( QList& sel style allows. */ template -void QCPAbstractPlottable1D::drawPolyline( QCPPainter* painter, const QVector& lineData ) const +void QCPAbstractPlottable1D::drawPolyline(QCPPainter *painter, const QVector &lineData) const { // if drawing lines in plot (instead of PDF), reduce 1px lines to cosmetic, because at least in // Qt6 drawing of "1px" width lines is much slower even though it has same appearance apart from // High-DPI. In High-DPI cases people must set a pen width slightly larger than 1.0 to get // correct DPI scaling of width, but of course with performance penalty. - if( !painter->modes().testFlag( QCPPainter::pmVectorized ) && - qFuzzyCompare( painter->pen().widthF(), 1.0 ) ) + if (!painter->modes().testFlag(QCPPainter::pmVectorized) && + qFuzzyCompare(painter->pen().widthF(), 1.0)) { QPen newPen = painter->pen(); - newPen.setWidth( 0 ); - painter->setPen( newPen ); + newPen.setWidth(0); + painter->setPen(newPen); } // 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.h' */ + /* including file 'src/colorgradient.h' */ -/* modified 2021-03-29T02:30:44, size 7262 */ +/* modified 2022-11-06T12:45:56, size 7262 */ class QCP_LIB_DECL QCPColorGradient { @@ -4922,70 +4758,48 @@ 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 how NaN data points shall appear in the plot. \see setNanHandling, setNanColor */ - enum NanHandling - { - nhNone ///< NaN data points are not explicitly handled and shouldn't occur in the data (this gives slight performance improvement) - , - nhLowestColor ///< NaN data points appear as the lowest color defined in this QCPColorGradient - , - nhHighestColor ///< NaN data points appear as the highest color defined in this QCPColorGradient - , - nhTransparent ///< NaN data points appear transparent - , - nhNanColor ///< NaN data points appear as the color defined with \ref setNanColor - }; - Q_ENUMS( NanHandling ) - + enum NanHandling { nhNone ///< NaN data points are not explicitly handled and shouldn't occur in the data (this gives slight performance improvement) + ,nhLowestColor ///< NaN data points appear as the lowest color defined in this QCPColorGradient + ,nhHighestColor ///< NaN data points appear as the highest color defined in this QCPColorGradient + ,nhTransparent ///< NaN data points appear transparent + ,nhNanColor ///< NaN data points appear as the color defined with \ref setNanColor + }; + Q_ENUMS(NanHandling) + /*! 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; } @@ -4993,24 +4807,24 @@ public: NanHandling nanHandling() const { return mNanHandling; } QColor nanColor() const { return mNanColor; } 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 setNanHandling( NanHandling handling ); - void setNanColor( const QColor& color ); - 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 setNanHandling(NanHandling handling); + void setNanColor(const QColor &color); + 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; @@ -5019,51 +4833,47 @@ protected: NanHandling mNanHandling; QColor mNanColor; 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::NanHandling ) -Q_DECLARE_METATYPE( QCPColorGradient::GradientPreset ) +Q_DECLARE_METATYPE(QCPColorGradient::ColorInterpolation) +Q_DECLARE_METATYPE(QCPColorGradient::NanHandling) +Q_DECLARE_METATYPE(QCPColorGradient::GradientPreset) /* end of 'src/colorgradient.h' */ + /* including file 'src/selectiondecorator-bracket.h' */ -/* modified 2021-03-29T02:30:44, size 4458 */ +/* modified 2022-11-06T12:45:56, size 4458 */ 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() Q_DECL_OVERRIDE; - + // getters: QPen bracketPen() const { return mBracketPen; } QBrush bracketBrush() const { return mBracketBrush; } @@ -5072,22 +4882,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; @@ -5097,32 +4907,34 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7529 */ +/* modified 2022-11-06T12:45:56, size 7529 */ 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() Q_DECL_OVERRIDE; - + // getters: QPixmap background() const { return mBackgroundPixmap; } QBrush backgroundBrush() const { return mBackgroundBrush; } @@ -5130,46 +4942,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 = nullptr ); - 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=nullptr); + 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(); } @@ -5183,10 +4995,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: @@ -5195,148 +5007,152 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 10425 */ +/* modified 2022-11-06T12:45:56, size 10425 */ 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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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: /*! @@ -5344,21 +5160,17 @@ 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() Q_DECL_OVERRIDE; - + // getters: QPen borderPen() const { return mBorderPen; } QBrush brush() const { return mBrush; } @@ -5374,43 +5186,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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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; @@ -5424,53 +5236,54 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 5359 */ +/* modified 2022-11-06T12:45:56, size 5359 */ 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; } @@ -5480,29 +5293,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 = nullptr ) 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=nullptr) 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; @@ -5513,102 +5326,106 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 5939 */ +/* modified 2022-11-06T12:45:56, size 5939 */ + 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::mouseMoveEvent; using QCPAxisRect::mousePressEvent; + using QCPAxisRect::mouseMoveEvent; using QCPAxisRect::mouseReleaseEvent; - using QCPAxisRect::update; using QCPAxisRect::wheelEvent; - virtual void draw( QCPPainter* painter ) Q_DECL_OVERRIDE; + using QCPAxisRect::update; + 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() Q_DECL_OVERRIDE; - + // 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: @@ -5617,48 +5434,51 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 9316 */ +/* modified 2022-11-06T12:45:56, size 9316 */ 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 @@ -5675,11 +5495,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: /*! @@ -5687,52 +5507,45 @@ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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; @@ -5740,69 +5553,71 @@ 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* thisData, 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 *thisData, 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' */ -/* modified 2021-03-29T02:30:44, size 7434 */ +/* modified 2022-11-06T12:45:56, size 7434 */ 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 @@ -5820,9 +5635,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: /*! @@ -5830,83 +5645,81 @@ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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 otherRegion, double otherKey, double otherValue, 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 otherRegion, double otherKey, double otherValue, 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' */ -/* modified 2021-03-29T02:30:44, size 8955 */ +/* modified 2022-11-06T12:45:56, size 8955 */ 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: /*! @@ -5915,78 +5728,76 @@ 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 @@ -6003,13 +5814,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: /*! @@ -6018,107 +5829,105 @@ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 7522 */ +/* modified 2022-11-06T12:45:56, size 7522 */ 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 @@ -6136,17 +5945,17 @@ class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable1D data() const { return mDataContainer; } double width() const { return mWidth; } @@ -6158,26 +5967,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 = nullptr ) 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=nullptr) 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; @@ -6186,181 +5995,185 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7092 */ +/* modified 2022-11-06T12:45:56, size 7092 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 8644 */ +/* modified 2022-11-06T12:45:56, size 8644 */ 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 @@ -6377,14 +6190,14 @@ class QCP_LIB_DECL QCPFinancial : public QCPAbstractPlottable1D data() const { return mDataContainer; } ChartStyle chartStyle() const { return mChartStyle; } @@ -6429,32 +6235,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 = nullptr ) 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=nullptr) 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; @@ -6463,40 +6269,42 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 7749 */ +/* modified 2022-11-06T12:45:56, size 7749 */ 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 @@ -6519,67 +6327,65 @@ 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() Q_DECL_OVERRIDE; // 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 = nullptr ) const Q_DECL_OVERRIDE; - virtual QCPPlottableInterface1D* interface1D() Q_DECL_OVERRIDE { return this; } - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE; + virtual QCPPlottableInterface1D *interface1D() Q_DECL_OVERRIDE { return this; } + protected: // property members: QSharedPointer mDataContainer; @@ -6587,228 +6393,224 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 3137 */ +/* modified 2022-11-06T12:45:56, size 3137 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE; - - QCPItemPosition* const point1; - QCPItemPosition* const point2; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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& base, const QCPVector2D& vec, const QRect& rect ) const; + QLineF getRectClippedStraightLine(const QCPVector2D &base, const QCPVector2D &vec, const QRect &rect) const; QPen mainPen() const; }; /* end of 'src/items/item-straightline.h' */ + /* including file 'src/items/item-line.h' */ -/* modified 2021-03-29T02:30:44, size 3429 */ +/* modified 2022-11-06T12:45:56, size 3429 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE; - - QCPItemPosition* const start; - QCPItemPosition* const end; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 3401 */ +/* modified 2022-11-06T12:45:56, size 3401 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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' */ -/* modified 2021-03-29T02:30:44, size 3710 */ +/* modified 2022-11-06T12:45:56, size 3710 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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; @@ -6816,31 +6618,32 @@ protected: /* end of 'src/items/item-rect.h' */ + /* including file 'src/items/item-text.h' */ -/* modified 2021-03-29T02:30:44, size 5576 */ +/* modified 2022-11-06T12:45:56, size 5576 */ 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() Q_DECL_OVERRIDE; - + // getters: QColor color() const { return mColor; } QColor selectedColor() const { return mSelectedColor; } @@ -6855,48 +6658,38 @@ 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 = nullptr ) 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=nullptr) 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; @@ -6907,13 +6700,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; @@ -6922,71 +6715,61 @@ protected: /* end of 'src/items/item-text.h' */ + /* including file 'src/items/item-ellipse.h' */ -/* modified 2021-03-29T02:30:44, size 3890 */ +/* modified 2022-11-06T12:45:56, size 3890 */ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) 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=nullptr) 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; @@ -6994,24 +6777,25 @@ protected: /* end of 'src/items/item-ellipse.h' */ + /* including file 'src/items/item-pixmap.h' */ -/* modified 2021-03-29T02:30:44, size 4407 */ +/* modified 2022-11-06T12:45:56, size 4407 */ 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() Q_DECL_OVERRIDE; - + // getters: QPixmap pixmap() const { return mPixmap; } bool scaled() const { return mScaled; } @@ -7019,36 +6803,28 @@ 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 = nullptr ) 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=nullptr) 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; @@ -7057,35 +6833,36 @@ 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 = nullptr, bool* flippedVert = nullptr ) const; + void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false); + QRect getFinalRect(bool *flippedHorz=nullptr, bool *flippedVert=nullptr) const; QPen mainPen() const; }; /* end of 'src/items/item-pixmap.h' */ + /* including file 'src/items/item-tracer.h' */ -/* modified 2021-03-29T02:30:44, size 4811 */ +/* modified 2022-11-06T12:45:56, size 4811 */ 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: /*! @@ -7093,21 +6870,15 @@ 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() Q_DECL_OVERRIDE; // getters: @@ -7117,28 +6888,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 = nullptr ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const Q_DECL_OVERRIDE; + // non-virtual methods: void updatePosition(); - QCPItemPosition* const position; + QCPItemPosition * const position; protected: // property members: @@ -7146,32 +6917,33 @@ 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' */ -/* modified 2021-03-29T02:30:44, size 3991 */ +/* modified 2022-11-06T12:45:56, size 3991 */ 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: /*! @@ -7180,127 +6952,107 @@ 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() Q_DECL_OVERRIDE; - + // 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 = nullptr ) const Q_DECL_OVERRIDE; - - QCPItemPosition* const left; - QCPItemPosition* const right; - QCPItemAnchor* const center; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) 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' */ + /* including file 'src/polar/radialaxis.h' */ -/* modified 2021-03-29T02:30:44, size 12227 */ +/* modified 2022-11-06T12:45:56, size 12227 */ + class QCP_LIB_DECL QCPPolarAxisRadial : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - + /// \endcond public: /*! Defines the reference of the angle at which a radial axis is tilted (\ref setAngle). */ - enum AngleReference - { - arAbsolute ///< The axis tilt is given in absolute degrees. The zero is to the right and positive angles are measured counter-clockwise. - , - arAngularAxis ///< The axis tilt is measured in the angular coordinate system given by the parent angular axis. - }; - Q_ENUMS( AngleReference ) + enum AngleReference { arAbsolute ///< The axis tilt is given in absolute degrees. The zero is to the right and positive angles are measured counter-clockwise. + ,arAngularAxis ///< The axis tilt is measured in the angular coordinate system given by the parent angular axis. + }; + Q_ENUMS(AngleReference) /*! 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 ) - - enum LabelMode - { - lmUpright ///< - , - lmRotated ///< - }; - Q_ENUMS( LabelMode ) - - explicit QCPPolarAxisRadial( QCPPolarAxisAngular* parent ); + 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) + + enum LabelMode { lmUpright ///< + ,lmRotated ///< + }; + Q_ENUMS(LabelMode) + + explicit QCPPolarAxisRadial(QCPPolarAxisAngular *parent); virtual ~QCPPolarAxisRadial(); - + // getters: bool rangeDrag() const { return mRangeDrag; } bool rangeZoom() const { return mRangeZoom; } double rangeZoomFactor() const { return mRangeZoomFactor; } - - QCPPolarAxisAngular* angularAxis() const { return mAngularAxis; } + + QCPPolarAxisAngular *angularAxis() const { return mAngularAxis; } ScaleType scaleType() const { return mScaleType; } const QCPRange range() const { return mRange; } bool rangeReversed() const { return mRangeReversed; } @@ -7340,84 +7092,84 @@ public: QPen selectedBasePen() const { return mSelectedBasePen; } QPen selectedTickPen() const { return mSelectedTickPen; } QPen selectedSubTickPen() const { return mSelectedSubTickPen; } - + // setters: - void setRangeDrag( bool enabled ); - void setRangeZoom( bool enabled ); - void setRangeZoomFactor( double factor ); - - Q_SLOT void setScaleType( QCPPolarAxisRadial::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 setAngle( double degrees ); - void setAngleReference( AngleReference reference ); - 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 setTickLabelMode( LabelMode mode ); - 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 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 QCPPolarAxisRadial::SelectableParts& selectableParts ); - Q_SLOT void setSelectedParts( const QCPPolarAxisRadial::SelectableParts& selectedParts ); - + void setRangeDrag(bool enabled); + void setRangeZoom(bool enabled); + void setRangeZoomFactor(double factor); + + Q_SLOT void setScaleType(QCPPolarAxisRadial::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 setAngle(double degrees); + void setAngleReference(AngleReference reference); + 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 setTickLabelMode(LabelMode mode); + 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 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 QCPPolarAxisRadial::SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const QCPPolarAxisRadial::SelectableParts &selectedParts); + // 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: - void moveRange( double diff ); - void scaleRange( double factor ); - void scaleRange( double factor, double center ); - void rescale( bool onlyVisiblePlottables = false ); - void pixelToCoord( QPointF pixelPos, double& angleCoord, double& radiusCoord ) const; - QPointF coordToPixel( double angleCoord, double radiusCoord ) const; - double coordToRadius( double coord ) const; - double radiusToCoord( double radius ) const; - SelectablePart getPartAt( const QPointF& pos ) const; - + void moveRange(double diff); + void scaleRange(double factor); + void scaleRange(double factor, double center); + void rescale(bool onlyVisiblePlottables=false); + void pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const; + QPointF coordToPixel(double angleCoord, double radiusCoord) const; + double coordToRadius(double coord) const; + double radiusToCoord(double radius) const; + SelectablePart getPartAt(const QPointF &pos) const; + signals: - void rangeChanged( const QCPRange& newRange ); - void rangeChanged( const QCPRange& newRange, const QCPRange& oldRange ); - void scaleTypeChanged( QCPPolarAxisRadial::ScaleType scaleType ); - void selectionChanged( const QCPPolarAxisRadial::SelectableParts& parts ); - void selectableChanged( const QCPPolarAxisRadial::SelectableParts& parts ); + void rangeChanged(const QCPRange &newRange); + void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); + void scaleTypeChanged(QCPPolarAxisRadial::ScaleType scaleType); + void selectionChanged(const QCPPolarAxisRadial::SelectableParts &parts); + void selectableChanged(const QCPPolarAxisRadial::SelectableParts &parts); protected: // property members: bool mRangeDrag; bool mRangeZoom; double mRangeZoomFactor; - + // axis base: - QCPPolarAxisAngular* mAngularAxis; + QCPPolarAxisAngular *mAngularAxis; double mAngle; AngleReference mAngleReference; SelectableParts mSelectableParts, mSelectedParts; @@ -7447,7 +7199,7 @@ protected: QCPRange mRange; bool mRangeReversed; ScaleType mScaleType; - + // non-property members: QPointF mCenter; double mRadius; @@ -7459,22 +7211,22 @@ protected: QCPRange mDragStartRange; QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; QCPLabelPainterPrivate mLabelPainter; - + // 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 updateGeometry( const QPointF& center, double radius ); + void updateGeometry(const QPointF ¢er, double radius); void setupTickVectors(); QPen getBasePen() const; QPen getTickPen() const; @@ -7483,62 +7235,57 @@ protected: QFont getLabelFont() const; QColor getTickLabelColor() const; QColor getLabelColor() const; - + private: - Q_DISABLE_COPY( QCPPolarAxisRadial ) - + Q_DISABLE_COPY(QCPPolarAxisRadial) + friend class QCustomPlot; friend class QCPPolarAxisAngular; }; -Q_DECLARE_OPERATORS_FOR_FLAGS( QCPPolarAxisRadial::SelectableParts ) -Q_DECLARE_METATYPE( QCPPolarAxisRadial::AngleReference ) -Q_DECLARE_METATYPE( QCPPolarAxisRadial::ScaleType ) -Q_DECLARE_METATYPE( QCPPolarAxisRadial::SelectablePart ) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarAxisRadial::SelectableParts) +Q_DECLARE_METATYPE(QCPPolarAxisRadial::AngleReference) +Q_DECLARE_METATYPE(QCPPolarAxisRadial::ScaleType) +Q_DECLARE_METATYPE(QCPPolarAxisRadial::SelectablePart) + + /* end of 'src/polar/radialaxis.h' */ + /* including file 'src/polar/layoutelement-angularaxis.h' */ -/* modified 2021-03-29T02:30:44, size 13461 */ +/* modified 2022-11-06T12:45:56, size 13461 */ class QCP_LIB_DECL QCPPolarAxisAngular : public QCPLayoutElement { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - + /// \endcond public: /*! 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 ) - + 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) + /*! TODO */ - enum LabelMode - { - lmUpright ///< - , - lmRotated ///< - }; - Q_ENUMS( LabelMode ) - - explicit QCPPolarAxisAngular( QCustomPlot* parentPlot ); + enum LabelMode { lmUpright ///< + ,lmRotated ///< + }; + Q_ENUMS(LabelMode) + + explicit QCPPolarAxisAngular(QCustomPlot *parentPlot); virtual ~QCPPolarAxisAngular(); - + // getters: QPixmap background() const { return mBackgroundPixmap; } QBrush backgroundBrush() const { return mBackgroundBrush; } @@ -7547,7 +7294,7 @@ public: bool rangeDrag() const { return mRangeDrag; } bool rangeZoom() const { return mRangeZoom; } double rangeZoomFactor() const { return mRangeZoomFactor; } - + const QCPRange range() const { return mRange; } bool rangeReversed() const { return mRangeReversed; } double angle() const { return mAngle; } @@ -7584,85 +7331,85 @@ public: QPen selectedBasePen() const { return mSelectedBasePen; } QPen selectedTickPen() const { return mSelectedTickPen; } QPen selectedSubTickPen() const { return mSelectedSubTickPen; } - QCPPolarGrid* grid() const { return mGrid; } - + QCPPolarGrid *grid() const { return mGrid; } + // 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( bool enabled ); - void setRangeZoom( bool enabled ); - void setRangeZoomFactor( double factor ); - - 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 setAngle( double degrees ); - 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 setTickLabelMode( LabelMode mode ); - 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 setLabelPosition( Qt::AlignmentFlag position ); - 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 QCPPolarAxisAngular::SelectableParts& selectableParts ); - Q_SLOT void setSelectedParts( const QCPPolarAxisAngular::SelectableParts& selectedParts ); - + 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(bool enabled); + void setRangeZoom(bool enabled); + void setRangeZoomFactor(double factor); + + 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 setAngle(double degrees); + 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 setTickLabelMode(LabelMode mode); + 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 setLabelPosition(Qt::AlignmentFlag position); + 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 QCPPolarAxisAngular::SelectableParts &selectableParts); + Q_SLOT void setSelectedParts(const QCPPolarAxisAngular::SelectableParts &selectedParts); + // reimplemented virtual methods: - virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const Q_DECL_OVERRIDE; - virtual void update( UpdatePhase phase ) Q_DECL_OVERRIDE; - virtual QList elements( bool recursive ) const Q_DECL_OVERRIDE; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const Q_DECL_OVERRIDE; + virtual void update(UpdatePhase phase) Q_DECL_OVERRIDE; + virtual QList elements(bool recursive) const Q_DECL_OVERRIDE; + // non-property methods: - bool removeGraph( QCPPolarGraph* graph ); + bool removeGraph(QCPPolarGraph *graph); int radialAxisCount() const; - QCPPolarAxisRadial* radialAxis( int index = 0 ) const; + QCPPolarAxisRadial *radialAxis(int index=0) const; QList radialAxes() const; - QCPPolarAxisRadial* addRadialAxis( QCPPolarAxisRadial* axis = 0 ); - bool removeRadialAxis( QCPPolarAxisRadial* axis ); - QCPLayoutInset* insetLayout() const { return mInsetLayout; } + QCPPolarAxisRadial *addRadialAxis(QCPPolarAxisRadial *axis=0); + bool removeRadialAxis(QCPPolarAxisRadial *axis); + QCPLayoutInset *insetLayout() const { return mInsetLayout; } QRegion exactClipRegion() const; - - void moveRange( double diff ); - void scaleRange( double factor ); - void scaleRange( double factor, double center ); - void rescale( bool onlyVisiblePlottables = false ); - double coordToAngleRad( double coord ) const { return mAngleRad + ( coord - mRange.lower ) / mRange.size() * ( mRangeReversed ? -2.0 * M_PI : 2.0 * M_PI ); } // mention in doc that return doesn't wrap - double angleRadToCoord( double angleRad ) const { return mRange.lower + ( angleRad - mAngleRad ) / ( mRangeReversed ? -2.0 * M_PI : 2.0 * M_PI ) * mRange.size(); } - void pixelToCoord( QPointF pixelPos, double& angleCoord, double& radiusCoord ) const; - QPointF coordToPixel( double angleCoord, double radiusCoord ) const; - SelectablePart getPartAt( const QPointF& pos ) const; - + + void moveRange(double diff); + void scaleRange(double factor); + void scaleRange(double factor, double center); + void rescale(bool onlyVisiblePlottables=false); + double coordToAngleRad(double coord) const { return mAngleRad+(coord-mRange.lower)/mRange.size()*(mRangeReversed ? -2.0*M_PI : 2.0*M_PI); } // mention in doc that return doesn't wrap + double angleRadToCoord(double angleRad) const { return mRange.lower+(angleRad-mAngleRad)/(mRangeReversed ? -2.0*M_PI : 2.0*M_PI)*mRange.size(); } + void pixelToCoord(QPointF pixelPos, double &angleCoord, double &radiusCoord) const; + QPointF coordToPixel(double angleCoord, double radiusCoord) const; + SelectablePart getPartAt(const QPointF &pos) const; + // read-only interface imitating a QRect: int left() const { return mRect.left(); } int right() const { return mRect.right(); } @@ -7677,13 +7424,13 @@ public: QPoint bottomRight() const { return mRect.bottomRight(); } QPointF center() const { return mCenter; } double radius() const { return mRadius; } - + signals: - void rangeChanged( const QCPRange& newRange ); - void rangeChanged( const QCPRange& newRange, const QCPRange& oldRange ); - void selectionChanged( const QCPPolarAxisAngular::SelectableParts& parts ); - void selectableChanged( const QCPPolarAxisAngular::SelectableParts& parts ); - + void rangeChanged(const QCPRange &newRange); + void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange); + void selectionChanged(const QCPPolarAxisAngular::SelectableParts &parts); + void selectableChanged(const QCPPolarAxisAngular::SelectableParts &parts); + protected: // property members: QBrush mBackgroundBrush; @@ -7691,11 +7438,11 @@ protected: QPixmap mScaledBackgroundPixmap; bool mBackgroundScaled; Qt::AspectRatioMode mBackgroundScaledMode; - QCPLayoutInset* mInsetLayout; + QCPLayoutInset *mInsetLayout; bool mRangeDrag; bool mRangeZoom; double mRangeZoomFactor; - + // axis base: double mAngle, mAngleRad; SelectableParts mSelectableParts, mSelectedParts; @@ -7724,12 +7471,12 @@ protected: // scale and range: QCPRange mRange; bool mRangeReversed; - + // non-property members: QPointF mCenter; double mRadius; QList mRadialAxes; - QCPPolarGrid* mGrid; + QCPPolarGrid *mGrid; QList mGraphs; QSharedPointer mTicker; QVector mTickVector; @@ -7742,20 +7489,20 @@ protected: QList mDragRadialStart; QCP::AntialiasedElements mAADragBackup, mNotAADragBackup; QCPLabelPainterPrivate mLabelPainter; - + // 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 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: - bool registerPolarGraph( QCPPolarGraph* graph ); - void drawBackground( QCPPainter* painter, const QPointF& center, double radius ); + bool registerPolarGraph(QCPPolarGraph *graph); + void drawBackground(QCPPainter *painter, const QPointF ¢er, double radius); void setupTickVectors(); QPen getBasePen() const; QPen getTickPen() const; @@ -7764,50 +7511,46 @@ protected: QFont getLabelFont() const; QColor getTickLabelColor() const; QColor getLabelColor() const; - + private: - Q_DISABLE_COPY( QCPPolarAxisAngular ) - + Q_DISABLE_COPY(QCPPolarAxisAngular) + friend class QCustomPlot; friend class QCPPolarGrid; friend class QCPPolarGraph; }; -Q_DECLARE_OPERATORS_FOR_FLAGS( QCPPolarAxisAngular::SelectableParts ) -Q_DECLARE_METATYPE( QCPPolarAxisAngular::SelectablePart ) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarAxisAngular::SelectableParts) +Q_DECLARE_METATYPE(QCPPolarAxisAngular::SelectablePart) /* end of 'src/polar/layoutelement-angularaxis.h' */ -/* including file 'src/polar/polargrid.h' */ -/* modified 2021-03-29T02:30:44, size 4506 */ -class QCP_LIB_DECL QCPPolarGrid : public QCPLayerable +/* including file 'src/polar/polargrid.h' */ +/* modified 2022-11-06T12:45:56, size 4506 */ + +class QCP_LIB_DECL QCPPolarGrid :public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - + /// \endcond public: /*! TODO */ - enum GridType - { - gtAngular = 0x01 ///< - , - gtRadial = 0x02 ///< - , - gtAll = 0xFF ///< - , - gtNone = 0x00 ///< - }; - Q_ENUMS( GridType ) - Q_FLAGS( GridTypes ) - Q_DECLARE_FLAGS( GridTypes, GridType ) - - explicit QCPPolarGrid( QCPPolarAxisAngular* parentAxis ); - + enum GridType { gtAngular = 0x01 ///< + ,gtRadial = 0x02 ///< + ,gtAll = 0xFF ///< + ,gtNone = 0x00 ///< + }; + Q_ENUMS(GridType) + Q_FLAGS(GridTypes) + Q_DECLARE_FLAGS(GridTypes, GridType) + + explicit QCPPolarGrid(QCPPolarAxisAngular *parentAxis); + // getters: - QCPPolarAxisRadial* radialAxis() const { return mRadialAxis.data(); } + QCPPolarAxisRadial *radialAxis() const { return mRadialAxis.data(); } GridTypes type() const { return mType; } GridTypes subGridType() const { return mSubGridType; } bool antialiasedSubGrid() const { return mAntialiasedSubGrid; } @@ -7817,19 +7560,19 @@ public: QPen radialPen() const { return mRadialPen; } QPen radialSubGridPen() const { return mRadialSubGridPen; } QPen radialZeroLinePen() const { return mRadialZeroLinePen; } - + // setters: - void setRadialAxis( QCPPolarAxisRadial* axis ); - void setType( GridTypes type ); - void setSubGridType( GridTypes type ); - void setAntialiasedSubGrid( bool enabled ); - void setAntialiasedZeroLine( bool enabled ); - void setAngularPen( const QPen& pen ); - void setAngularSubGridPen( const QPen& pen ); - void setRadialPen( const QPen& pen ); - void setRadialSubGridPen( const QPen& pen ); - void setRadialZeroLinePen( const QPen& pen ); - + void setRadialAxis(QCPPolarAxisRadial *axis); + void setType(GridTypes type); + void setSubGridType(GridTypes type); + void setAntialiasedSubGrid(bool enabled); + void setAntialiasedZeroLine(bool enabled); + void setAngularPen(const QPen &pen); + void setAngularSubGridPen(const QPen &pen); + void setRadialPen(const QPen &pen); + void setRadialSubGridPen(const QPen &pen); + void setRadialZeroLinePen(const QPen &pen); + protected: // property members: GridTypes mType; @@ -7837,59 +7580,64 @@ protected: bool mAntialiasedSubGrid, mAntialiasedZeroLine; QPen mAngularPen, mAngularSubGridPen; QPen mRadialPen, mRadialSubGridPen, mRadialZeroLinePen; - + // non-property members: - QCPPolarAxisAngular* mParentAxis; + QCPPolarAxisAngular *mParentAxis; QPointer mRadialAxis; - + // 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 drawRadialGrid( QCPPainter* painter, const QPointF& center, const QVector& coords, const QPen& pen, const QPen& zeroPen = Qt::NoPen ); - void drawAngularGrid( QCPPainter* painter, const QPointF& center, double radius, const QVector& ticksCosSin, const QPen& pen ); - + void drawRadialGrid(QCPPainter *painter, const QPointF ¢er, const QVector &coords, const QPen &pen, const QPen &zeroPen=Qt::NoPen); + void drawAngularGrid(QCPPainter *painter, const QPointF ¢er, double radius, const QVector &ticksCosSin, const QPen &pen); + private: - Q_DISABLE_COPY( QCPPolarGrid ) + Q_DISABLE_COPY(QCPPolarGrid) + }; -Q_DECLARE_OPERATORS_FOR_FLAGS( QCPPolarGrid::GridTypes ) -Q_DECLARE_METATYPE( QCPPolarGrid::GridType ) +Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPolarGrid::GridTypes) +Q_DECLARE_METATYPE(QCPPolarGrid::GridType) + /* end of 'src/polar/polargrid.h' */ + /* including file 'src/polar/polargraph.h' */ -/* modified 2021-03-29T02:30:44, size 9606 */ +/* modified 2022-11-06T12:45:56, size 9606 */ + class QCP_LIB_DECL QCPPolarLegendItem : public QCPAbstractLegendItem { Q_OBJECT public: - QCPPolarLegendItem( QCPLegend* parent, QCPPolarGraph* graph ); - + QCPPolarLegendItem(QCPLegend *parent, QCPPolarGraph *graph); + // getters: - QCPPolarGraph* polarGraph() { return mPolarGraph; } - + QCPPolarGraph *polarGraph() { return mPolarGraph; } + protected: // property members: - QCPPolarGraph* mPolarGraph; - + QCPPolarGraph *mPolarGraph; + // 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 QCPPolarGraph : public QCPLayerable { Q_OBJECT /// \cond INCLUDE_QPROPERTIES - + /// \endcond public: /*! @@ -7897,18 +7645,15 @@ 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 - }; - Q_ENUMS( LineStyle ) - - QCPPolarGraph( QCPPolarAxisAngular* keyAxis, QCPPolarAxisRadial* 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 + }; + Q_ENUMS(LineStyle) + + QCPPolarGraph(QCPPolarAxisAngular *keyAxis, QCPPolarAxisRadial *valueAxis); virtual ~QCPPolarGraph(); - + // getters: QString name() const { return mName; } bool antialiasedFill() const { return mAntialiasedFill; } @@ -7916,8 +7661,8 @@ public: QPen pen() const { return mPen; } QBrush brush() const { return mBrush; } bool periodic() const { return mPeriodic; } - QCPPolarAxisAngular* keyAxis() const { return mKeyAxis.data(); } - QCPPolarAxisRadial* valueAxis() const { return mValueAxis.data(); } + QCPPolarAxisAngular *keyAxis() const { return mKeyAxis.data(); } + QCPPolarAxisRadial *valueAxis() const { return mValueAxis.data(); } QCP::SelectionType selectable() const { return mSelectable; } bool selected() const { return !mSelection.isEmpty(); } QCPDataSelection selection() const { return mSelection; } @@ -7925,50 +7670,50 @@ public: QSharedPointer data() const { return mDataContainer; } LineStyle lineStyle() const { return mLineStyle; } QCPScatterStyle scatterStyle() const { return mScatterStyle; } - + // 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 setPeriodic( bool enabled ); - void setKeyAxis( QCPPolarAxisAngular* axis ); - void setValueAxis( QCPPolarAxisRadial* axis ); - Q_SLOT void setSelectable( QCP::SelectionType selectable ); - Q_SLOT void setSelection( QCPDataSelection selection ); + void setName(const QString &name); + void setAntialiasedFill(bool enabled); + void setAntialiasedScatters(bool enabled); + void setPen(const QPen &pen); + void setBrush(const QBrush &brush); + void setPeriodic(bool enabled); + void setKeyAxis(QCPPolarAxisAngular *axis); + void setValueAxis(QCPPolarAxisRadial *axis); + Q_SLOT void setSelectable(QCP::SelectionType selectable); + Q_SLOT void setSelection(QCPDataSelection selection); //void setSelectionDecorator(QCPSelectionDecorator *decorator); - 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 setData(QSharedPointer data); + void setData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void setLineStyle(LineStyle ls); + void setScatterStyle(const QCPScatterStyle &style); // non-property methods: - void addData( const QVector& keys, const QVector& values, bool alreadySorted = false ); - void addData( double key, double value ); - 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 addData(const QVector &keys, const QVector &values, bool alreadySorted=false); + void addData(double key, double value); + 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; - + // introduced virtual methods: - virtual double selectTest( const QPointF& pos, bool onlySelectable, QVariant* details = 0 ) const; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables - virtual QCPPlottableInterface1D* interface1D() { return 0; } // TODO: return this later, when QCPAbstractPolarPlottable is created - virtual QCPRange getKeyRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth ) const; - virtual QCPRange getValueRange( bool& foundRange, QCP::SignDomain inSignDomain = QCP::sdBoth, const QCPRange& inKeyRange = QCPRange() ) const; - + virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const; // actually introduced in QCPLayerable as non-pure, but we want to force reimplementation for plottables + virtual QCPPlottableInterface1D *interface1D() { return 0; } // TODO: return this later, when QCPAbstractPolarPlottable is created + virtual QCPRange getKeyRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth) const; + virtual QCPRange getValueRange(bool &foundRange, QCP::SignDomain inSignDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) 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: QSharedPointer mDataContainer; @@ -7984,44 +7729,46 @@ protected: QCP::SelectionType mSelectable; QCPDataSelection mSelection; //QCPSelectionDecorator *mSelectionDecorator; - + // introduced virtual methods (later reimplemented TODO from QCPAbstractPolarPlottable): virtual QRect clipRect() const; - virtual void draw( QCPPainter* painter ); + virtual void draw(QCPPainter *painter); virtual QCP::Interaction selectionCategory() const; - void applyDefaultAntialiasingHint( QCPPainter* painter ) const; + void applyDefaultAntialiasingHint(QCPPainter *painter) const; // 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); // virtual drawing helpers: - virtual void drawLinePlot( QCPPainter* painter, const QVector& lines ) 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 drawFill(QCPPainter *painter, QVector *lines) const; + virtual void drawScatterPlot(QCPPainter *painter, const QVector &scatters, const QCPScatterStyle &style) const; + // introduced virtual methods: - virtual void drawLegendIcon( QCPPainter* painter, const QRectF& rect ) const; - + virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const; + // non-virtual methods: - void applyFillAntialiasingHint( QCPPainter* painter ) const; - void applyScattersAntialiasingHint( QCPPainter* painter ) const; - double pointDistance( const QPointF& pixelPoint, QCPGraphDataContainer::const_iterator& closestData ) const; + void applyFillAntialiasingHint(QCPPainter *painter) const; + void applyScattersAntialiasingHint(QCPPainter *painter) const; + double pointDistance(const QPointF &pixelPoint, QCPGraphDataContainer::const_iterator &closestData) const; // drawing helpers: virtual int dataCount() const; - void getDataSegments( QList& selectedSegments, QList& unselectedSegments ) const; - void drawPolyline( QCPPainter* painter, const QVector& lineData ) 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; - void getOptimizedLineData( QVector* lineData, const QCPGraphDataContainer::const_iterator& begin, const QCPGraphDataContainer::const_iterator& end ) const; - void getOptimizedScatterData( QVector* scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end ) const; - QVector dataToLines( const QVector& data ) const; + void getDataSegments(QList &selectedSegments, QList &unselectedSegments) const; + void drawPolyline(QCPPainter *painter, const QVector &lineData) 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; + void getOptimizedLineData(QVector *lineData, const QCPGraphDataContainer::const_iterator &begin, const QCPGraphDataContainer::const_iterator &end) const; + void getOptimizedScatterData(QVector *scatterData, QCPGraphDataContainer::const_iterator begin, QCPGraphDataContainer::const_iterator end) const; + QVector dataToLines(const QVector &data) const; private: - Q_DISABLE_COPY( QCPPolarGraph ) - + Q_DISABLE_COPY(QCPPolarGraph) + friend class QCPPolarLegendItem; }; /* end of 'src/polar/polargraph.h' */ -#endif // QCUSTOMPLOT_H + +#endif // QCUSTOMPLOT_H + diff --git a/app/main.cpp b/app/main.cpp index 6988a59..8dd03cb 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -22,6 +22,10 @@ * \brief main file */ +#include +#include +#include + #include "CommonDefs.h" #include "ConfigureFormatDialog.h" #include "MainWindow.h" @@ -30,8 +34,7 @@ #ifdef USE_QTDBUS #include "DBusAppAdaptor.h" #endif -#include -#include + #ifdef USE_FERVOR #include "fvupdater.h" #endif @@ -43,10 +46,11 @@ int main( int argc, char* argv[] ) { qRegisterMetaType(); - qRegisterMetaTypeStreamOperators(); qRegisterMetaType(); +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) + qRegisterMetaTypeStreamOperators(); qRegisterMetaTypeStreamOperators(); - +#endif QApplication application( argc, argv ); QApplication::setApplicationName( QStringLiteral( "Calyp" ) ); QApplication::setApplicationVersion( QStringLiteral( CALYP_VERSION_STRING ) ); diff --git a/lib/StreamHandlerLibav.cpp b/lib/StreamHandlerLibav.cpp index 93e4157..9c9daaf 100644 --- a/lib/StreamHandlerLibav.cpp +++ b/lib/StreamHandlerLibav.cpp @@ -298,10 +298,10 @@ bool StreamHandlerLibav::openHandler( std::string strFilename, bool bInput ) m_uiFrameBufferSize = av_image_get_buffer_size( AVPixelFormat( m_ffPixFmt ), m_uiWidth, m_uiHeight, 1 ); /* initialize packet, set data to NULL, let the demuxer fill it */ - av_init_packet( &m_cPacket ); - m_cPacket.data = NULL; - m_cPacket.size = 0; - m_cOrgPacket = m_cPacket; + m_cPacket = av_packet_alloc(); + m_cPacket->data = NULL; + m_cPacket->size = 0; + m_cOrgPacket = *m_cPacket; m_bHasStream = true; return true; @@ -318,6 +318,7 @@ void StreamHandlerLibav::closeHandler() avformat_close_input( &m_cFmtCtx ); av_free( m_cFrame ); + av_packet_free( &m_cPacket ); } m_bHasStream = false; } @@ -375,13 +376,13 @@ bool StreamHandlerLibav::read( CalypFrame& pcFrame ) bGotFrame = 1; } #else - if( m_cPacket.stream_index == m_iStreamIdx ) + if( m_cPacket->stream_index == m_iStreamIdx ) { - if( ( iRet = avcodec_decode_video2( m_cCodedCtx, m_cFrame, &bGotFrame, &m_cPacket ) ) < 0 ) + if( ( iRet = avcodec_decode_video2( m_cCodedCtx, m_cFrame, &bGotFrame, m_cPacket ) ) < 0 ) return false; - m_cPacket.data += iRet; - m_cPacket.size -= iRet; - if( m_cPacket.size <= 0 ) + m_cPacket->data += iRet; + m_cPacket->size -= iRet; + if( m_cPacket->size <= 0 ) { bReadPkt = true; av_packet_unref( &m_cOrgPacket ); @@ -394,7 +395,7 @@ bool StreamHandlerLibav::read( CalypFrame& pcFrame ) { bReadPkt = false; av_packet_unref( &m_cOrgPacket ); - if( ( iRet = av_read_frame( m_cFmtCtx, &m_cPacket ) ) < 0 ) + if( ( iRet = av_read_frame( m_cFmtCtx, m_cPacket ) ) < 0 ) { if( iRet == AVERROR_EOF ) { @@ -403,10 +404,10 @@ bool StreamHandlerLibav::read( CalypFrame& pcFrame ) } return false; } - m_cOrgPacket = m_cPacket; + m_cOrgPacket = *m_cPacket; #ifdef FF_SEND_RECEIVE_API - if( m_cPacket.stream_index == m_iStreamIdx ) - if( ( iRet = avcodec_send_packet( m_cCodedCtx, &m_cPacket ) ) < 0 ) + if( m_cPacket->stream_index == m_iStreamIdx ) + if( ( iRet = avcodec_send_packet( m_cCodedCtx, m_cPacket ) ) < 0 ) return false; #endif } diff --git a/lib/StreamHandlerLibav.h b/lib/StreamHandlerLibav.h index d148c71..97c5be8 100644 --- a/lib/StreamHandlerLibav.h +++ b/lib/StreamHandlerLibav.h @@ -88,7 +88,7 @@ private: int m_ffPixFmt; AVFrame* m_cFrame; AVPacket m_cOrgPacket; - AVPacket m_cPacket; + AVPacket* m_cPacket; bool m_bHasStream; diff --git a/modules/ShapeDetection.h b/modules/ShapeDetection.h index 6e89894..2f90245 100644 --- a/modules/ShapeDetection.h +++ b/modules/ShapeDetection.h @@ -36,7 +36,6 @@ class ShapeDetection : public CalypOpenCVModuleIf, public CalypModuleInstance m_resultImage; cv::RNG m_rng; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5edd12d..f4a5e34 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -8,6 +8,6 @@ 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) +TARGET_LINK_LIBRARIES(${PROJECT_NAME}Tools ${PROJECT_LIBRARY} CalypModules fmt::fmt) INSTALL(TARGETS ${PROJECT_NAME}Tools DESTINATION bin) diff --git a/tools/CalypTools.cpp b/tools/CalypTools.cpp index f34b2cb..2fdb8cd 100644 --- a/tools/CalypTools.cpp +++ b/tools/CalypTools.cpp @@ -24,6 +24,8 @@ #include "CalypTools.h" +#include + #include #include #include @@ -52,8 +54,10 @@ CalypTools::~CalypTools() = default; void CalypTools::reportStreamInfo( const CalypStream* stream, std::string strPrefix ) { log( CLP_LOG_INFO, "%sStream name: %s \n", strPrefix.c_str(), stream->getFileName().c_str() ); - log( CLP_LOG_INFO, "%sResolution: %dx%d@%d \n", strPrefix.c_str(), stream->getWidth(), stream->getHeight(), stream->getFrameRate() ); - log( CLP_LOG_INFO, "%sBits/pel: %d (%s)\n", strPrefix.c_str(), stream->getBitsPerPixel(), stream->getEndianess() == CLP_BIG_ENDIAN ? "BE" : "LE" ); + log( CLP_LOG_INFO, "%sResolution: %dx%d@%d \n", strPrefix.c_str(), stream->getWidth(), stream->getHeight(), + stream->getFrameRate() ); + log( CLP_LOG_INFO, "%sBits/pel: %d (%s)\n", strPrefix.c_str(), stream->getBitsPerPixel(), + stream->getEndianess() == CLP_BIG_ENDIAN ? "BE" : "LE" ); } int CalypTools::openInputs() @@ -104,7 +108,8 @@ int CalypTools::openInputs() pcStream = new CalypStream; try { - if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, hasNegativeValues, 1, CalypStream::Type::Input ) ) + if( !pcStream->open( inputFileNames[i], resolutionString, fmtString, uiBitsPerPixel, uiEndianness, + hasNegativeValues, 1, CalypStream::Type::Input ) ) { log( CLP_LOG_ERROR, "Cannot open input stream %s! ", inputFileNames[i].c_str() ); return -1; @@ -115,7 +120,8 @@ int CalypTools::openInputs() } catch( const char* msg ) { - log( CLP_LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), msg ); + log( CLP_LOG_ERROR, "Cannot open input stream %s with the following error: \n%s\n", inputFileNames[i].c_str(), + msg ); return -1; } } @@ -374,7 +380,8 @@ int CalypTools::Open( int argc, char* argv[] ) try { pcModStream->open( outputFileNames[0], pcModFrame->getWidth(), pcModFrame->getHeight(), - pcModFrame->getPelFormat(), pcModFrame->getBitsPel(), m_uiOutEndianness, 1, CalypStream::Type::Output ); + pcModFrame->getPelFormat(), pcModFrame->getBitsPel(), m_uiOutEndianness, 1, + CalypStream::Type::Output ); log( CLP_LOG_INFO, "Output stream from module!\n" ); reportStreamInfo( pcModStream, "Module Output " ); } @@ -680,7 +687,8 @@ int CalypTools::ListStatistics() { log( CLP_LOG_RESULT, "\x1B[32mInput:\t\t\t%d\x1B[0m\n", input ); log( CLP_LOG_RESULT, "No. Frames:\t\t%d\n", m_apcInputStreams[input]->getFrameNum() ); - log( CLP_LOG_RESULT, "Pixels:\t\t\t%d\n", m_apcInputStreams[input]->getHeight() * m_apcInputStreams[input]->getWidth() ); + log( CLP_LOG_RESULT, "Pixels:\t\t\t%d\n", + m_apcInputStreams[input]->getHeight() * m_apcInputStreams[input]->getWidth() ); for( unsigned int frame = 0; frame < m_apcInputStreams[input]->getFrameNum(); frame++ ) { @@ -714,10 +722,7 @@ int CalypTools::ListStatistics() log( CLP_LOG_RESULT, " Range: " ); for( unsigned channel = 0; channel < currFrame->getNumberChannels(); channel++ ) { - char buffer[14]; - sprintf( buffer, "[%d:%d]", min[channel], max[channel] ); - - log( CLP_LOG_RESULT, "| %13s ", buffer ); + log( CLP_LOG_RESULT, fmt::format( "[{}:{}]", min[channel], max[channel] ) ); } log( CLP_LOG_RESULT, "|\n" ); diff --git a/tools/CalypToolsCmdParser.cpp b/tools/CalypToolsCmdParser.cpp index a40c044..2067504 100644 --- a/tools/CalypToolsCmdParser.cpp +++ b/tools/CalypToolsCmdParser.cpp @@ -63,6 +63,15 @@ void CalypToolsCmdParser::log( unsigned int level, const char* fmt, ... ) } } +void CalypToolsCmdParser::log( unsigned int level, std::string log_msg ) +{ + if( level < m_uiLogLevel ) + { + return; + } + std::cout << log_msg; +} + int CalypToolsCmdParser::parseToolsArgs( int argc, char* argv[] ) { int iRet = 0; diff --git a/tools/CalypToolsCmdParser.h b/tools/CalypToolsCmdParser.h index 82ab262..26e6d98 100644 --- a/tools/CalypToolsCmdParser.h +++ b/tools/CalypToolsCmdParser.h @@ -51,6 +51,7 @@ public: * @note this function might not be safe in C++ (try to upgrade it) */ void log( unsigned int level, const char* fmt, ... ); + void log( unsigned int level, std::string log_msg ); int parseToolsArgs( int argc, char* argv[] );