Skip to content

Commit

Permalink
Clean some Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Jan 13, 2025
1 parent 5859d3d commit 9368347
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 58 deletions.
70 changes: 25 additions & 45 deletions include/wble/DoubleSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,56 @@

#include "wble_global.h"

/**
* @class DoubleSlider
* @brief Slider with two moving independently handles.
*/
/// @class DoubleSlider
/// @brief Slider with two moving independently handles.
class WBLE_EXPORT DoubleSlider : public QSlider
{
Q_OBJECT
public:
/**
* Constructor of DoubleSlider class.
* @param min Minimum value of slider.
* @param max Maximum value of slider.
* @param parent Parent widget.
*/
/// Constructor of DoubleSlider class.
/// @param min Minimum value of slider.
/// @param max Maximum value of slider.
/// @param parent Parent widget.
DoubleSlider(double min, double max, QWidget* parent = nullptr);

/**
* Get slider minimum value.
* @return Slider minimum value.
*/
/// Get slider minimum value.
/// @return Slider minimum value.
double getMin() const;

/**
* Get slider maximum value.
* @return Slider maximum value.
*/
/// Get slider maximum value.
/// @return Slider maximum value.
double getMax() const;

/**
* Get current value of left handle (minimum).
* @return Current minimum value.
*/
/// Get current value of left handle (minimum).
/// @return Current minimum value.
double getCurrentMin() const;

/**
* Get current value of right handle (maximum).
* @return Current maximum value.
*/
/// Get current value of right handle (maximum).
/// @return Current maximum value.
double getCurrentMax() const;

public Q_SLOTS:
/**
* Set current minimum.
* @param currentMinToSet Minimum value to set.
*/
/// Set current minimum.
/// @param currentMinToSet Minimum value to set.
void setCurrentMin(double currentMinToSet);

/**
* Set current maximum.
* @param currentMaxToSet Maximum value to set.
*/
/// Set current maximum.
/// @param currentMaxToSet Maximum value to set.
void setCurrentMax(double currentMaxToSet);

Q_SIGNALS:
/**
* Signal emitted when minimum value has changed (left slider moved).
*/
/// Signal emitted when minimum value has changed (left slider moved).
void currentMinChanged(double currentMin);

/**
* Signal emitted when maximum value has changed (right slider moved).
*/
/// Signal emitted when maximum value has changed (right slider moved).
void currentMaxChanged(double currentMax);

protected:
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void changeEvent(QEvent* event) override;
void paintEvent(QPaintEvent* ev) override;
void mousePressEvent(QMouseEvent* ev) override;
void mouseReleaseEvent(QMouseEvent* ev) override;
void mouseMoveEvent(QMouseEvent* ev) override;
void changeEvent(QEvent* e) override;

private:
enum class Handle : char
Expand Down
26 changes: 13 additions & 13 deletions src/DoubleSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ int DoubleSlider::getMousePosition(const QMouseEvent* event) const
return pos;
}

void DoubleSlider::mousePressEvent([[maybe_unused]] QMouseEvent* event)
void DoubleSlider::mousePressEvent([[maybe_unused]] QMouseEvent* ev)
{
moving_ = Handle::NONE;
}

void DoubleSlider::mouseReleaseEvent(QMouseEvent* event)
void DoubleSlider::mouseReleaseEvent(QMouseEvent* ev)
{
moving_ = Handle::NONE;
mouseMoveEvent(event);
mouseMoveEvent(ev);
update();
}

void DoubleSlider::changeEvent(QEvent* event)
void DoubleSlider::changeEvent(QEvent* e)
{
QSlider::changeEvent(event);
QSlider::changeEvent(e);

if (event->type() == QEvent::StyleChange)
if (e->type() == QEvent::StyleChange)
setHandleRect();
}

Expand All @@ -128,22 +128,22 @@ bool DoubleSlider::mouseIsOnHandle(int mousePosX, int handlePos) const
(mousePosX >= (handlePosX - (handleRect_.width() * shiftRatio)));
}

void DoubleSlider::mouseMoveEvent(QMouseEvent* event)
void DoubleSlider::mouseMoveEvent(QMouseEvent* ev)
{
if ((event->buttons() & Qt::LeftButton) == 0U)
if ((ev->buttons() & Qt::LeftButton) == 0U)
{
moving_ = Handle::NONE;
return;
}

const int newPosition{getMousePosition(event)};
const int newPosition{getMousePosition(ev)};
const int minX{getHandlePosition(Handle::LEFT)};
const int maxX{getHandlePosition(Handle::RIGHT)};

const bool onMinHandle{
mouseIsOnHandle(static_cast<int>(event->position().x()), minX)};
mouseIsOnHandle(static_cast<int>(ev->position().x()), minX)};
const bool onMaxHandle{
mouseIsOnHandle(static_cast<int>(event->position().x()), maxX)};
mouseIsOnHandle(static_cast<int>(ev->position().x()), maxX)};

const double range{max_ - min_};
const double newCurrent{
Expand Down Expand Up @@ -248,13 +248,13 @@ void DoubleSlider::drawHandles(QPainter& painter) const
style()->drawComplexControl(QStyle::CC_Slider, &rightStyle, &painter, this);
}

void DoubleSlider::paintEvent(QPaintEvent* event)
void DoubleSlider::paintEvent(QPaintEvent* ev)
{
if (utilities::doublesAreEqual(min_, max_))
return;

QPainter painter(this);
painter.setClipRegion(event->region());
painter.setClipRegion(ev->region());

drawSliderBar(painter);
drawSliderBarBetweenHandles(painter);
Expand Down

0 comments on commit 9368347

Please sign in to comment.