From f3df40cdf79448a7ac9e4d0ccebd7f9b6276bd3c Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 27 Nov 2021 00:52:32 +0000 Subject: [PATCH] Code cleanup --- .clang-tidy | 4 +++- app/VideoSubWindow.cpp | 20 +++++++------------- app/VideoSubWindow.h | 6 +++--- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 874d502..378727e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -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' +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 @@ -41,3 +41,5 @@ CheckOptions: value: '0' - key: google-readability-function-size.StatementThreshold value: '800' + - key: readability-magic-numbers.IgnorePowersOf2IntegerValues + value: '1' diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 51ebe31..4b8486c 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -396,7 +396,7 @@ QSize VideoSubWindow::getScrollSize() return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 ); } -void VideoSubWindow::adjustScrollBarToRatio( const double& horRatio, const double& verRatio ) +void VideoSubWindow::adjustScrollBarToRatio( const double horRatio, const double verRatio ) { QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar(); QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar(); @@ -500,12 +500,11 @@ void VideoSubWindow::zoomToFactor( double factor, QPoint center ) void VideoSubWindow::scaleView( double scale, QPoint center ) { - Q_ASSERT( !m_cViewArea->image().isNull() ); - if( scale != 1.0 ) - { - double usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() ); - adjustScrollBarByScale( usedScale, center ); - } + if( scale == 1.0 ) + return; + + double usedScale = m_cViewArea->scaleZoomFactor( scale, center, getScrollSize() ); + adjustScrollBarByScale( usedScale, center ); } void VideoSubWindow::scaleView( const QSize& size, QPoint center ) @@ -521,12 +520,7 @@ void VideoSubWindow::scaleView( const QSize& size, QPoint center ) // Calc the zoom factor double wfactor = (double)newSize.width() / imgViewSize.width(); double hfactor = (double)newSize.height() / imgViewSize.height(); - double factor{ wfactor }; - - if( wfactor < hfactor ) - factor = wfactor; - else - factor = hfactor; + auto factor = std::min( wfactor, hfactor ); double curFactor = getScaleFactor(); if( factor != curFactor ) diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 809135f..93abbb0 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -135,7 +135,7 @@ public: void setFillWindow( bool bFlag ); - void adjustScrollBarToRatio( const double& horRatio, const double& verRatio ); + void adjustScrollBarToRatio( const double horRatio, const double verRatio ); private: bool hasRunningModule(); @@ -177,8 +177,8 @@ protected: private: QScrollArea* m_pcScrollArea; QPoint m_cCurrScroll; - double m_dHorScroll; - double m_dVerScroll; + double m_dHorScroll{ 0 }; + double m_dVerScroll{ 0 }; ViewArea* m_cViewArea; QRect m_cSelectedArea; VideoSubWindow* m_pcReferenceSubWindow;