-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: demo for menu spinbox in datalogger menu
Signed-off-by: IonutMuthi <[email protected]>
- Loading branch information
1 parent
e504773
commit 88f660c
Showing
8 changed files
with
789 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#ifndef INCREMENTSTRATEGY_H | ||
#define INCREMENTSTRATEGY_H | ||
|
||
#include <plot_utils.hpp> | ||
#include <scopy-gui_export.h> | ||
|
||
namespace scopy { | ||
namespace gui { | ||
|
||
class SCOPY_GUI_EXPORT IncrementStrategy | ||
{ | ||
public: | ||
virtual ~IncrementStrategy() {} | ||
virtual double increment(double val) = 0; | ||
virtual double decrement(double val) = 0; | ||
virtual void setScale(double scale) = 0; | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT IncrementStrategy125 : public IncrementStrategy | ||
{ | ||
public: | ||
NumberSeries m_steps; | ||
|
||
IncrementStrategy125() | ||
: m_steps(1e-9, 1e9, 10) | ||
{} | ||
~IncrementStrategy125() {} | ||
virtual double increment(double val) override { return m_steps.getNumberAfter(val); } | ||
virtual double decrement(double val) override { return m_steps.getNumberBefore(val); } | ||
|
||
double m_scale; | ||
void setScale(double scale) override { m_scale = scale; } | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT IncrementStrategyPower2 : public IncrementStrategy | ||
{ | ||
public: | ||
QList<double> m_steps; | ||
IncrementStrategyPower2() | ||
{ | ||
for(int i = 30; i >= 0; i--) { | ||
m_steps.append(-(1 << i)); | ||
} | ||
for(int i = 0; i < 31; i++) { | ||
m_steps.append(1 << i); | ||
} | ||
} | ||
~IncrementStrategyPower2() {} | ||
virtual double increment(double val) override | ||
{ | ||
int i = 0; | ||
val = val + 1; | ||
while(val > m_steps[i]) { | ||
i++; | ||
} | ||
return m_steps[i]; | ||
} | ||
virtual double decrement(double val) override | ||
{ | ||
int i = m_steps.count() - 1; | ||
val = val - 1; | ||
while(val < m_steps[i]) { | ||
i--; | ||
} | ||
return m_steps[i]; | ||
} | ||
double m_scale; | ||
|
||
void setScale(double scale) override { m_scale = scale; } | ||
}; | ||
class SCOPY_GUI_EXPORT IncrementStrategyFixed : public IncrementStrategy | ||
{ | ||
public: | ||
IncrementStrategyFixed(double k = 1) | ||
{ | ||
m_k = k; | ||
m_scale = 1; | ||
} | ||
~IncrementStrategyFixed() {} | ||
virtual double increment(double val) override | ||
{ | ||
val = val + m_k * m_scale; | ||
return val; | ||
} | ||
virtual double decrement(double val) override | ||
{ | ||
val = val - m_k * m_scale; | ||
return val; | ||
} | ||
void setK(double val) { m_k = val; } | ||
double k() { return m_k; } | ||
|
||
private: | ||
double m_k; | ||
double m_scale; | ||
|
||
void setScale(double scale) override { m_scale = scale; } | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT IncrementStrategyTest : public IncrementStrategy | ||
{ | ||
public: | ||
IncrementStrategyTest() { m_scale = 1; } | ||
~IncrementStrategyTest() {} | ||
virtual double increment(double val) override | ||
{ | ||
val = val + m_scale; | ||
return val; | ||
} | ||
virtual double decrement(double val) override | ||
{ | ||
val = val - m_scale; | ||
return val; | ||
} | ||
|
||
private: | ||
double m_scale; | ||
|
||
void setScale(double scale) override { m_scale = scale; } | ||
}; | ||
} // namespace gui | ||
} // namespace scopy | ||
#endif // INCREMENTSTRATEGY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#ifndef SCALE_H | ||
#define SCALE_H | ||
|
||
#include <QComboBox> | ||
#include <QList> | ||
#include <QString> | ||
#include <scopy-gui_export.h> | ||
#include <QObject> | ||
|
||
namespace scopy { | ||
namespace gui { | ||
|
||
class SCOPY_GUI_EXPORT UnitPrefix | ||
{ | ||
public: | ||
QString prefix; | ||
double scale; | ||
// enum type - metric, hour, logarithmic, etc | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT ScaleOption | ||
{ | ||
public: | ||
QString option; | ||
double scale; | ||
// enum type - metric, hour, logarithmic, etc | ||
}; | ||
|
||
class SCOPY_GUI_EXPORT Scale : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
Scale(QString unit, double min, double max, bool hasPrefix = true); | ||
~Scale(); | ||
|
||
double getScaleForPrefix(QString prefix, Qt::CaseSensitivity s); | ||
double getScaleForUnit(QString unit, Qt::CaseSensitivity s); | ||
double getScaleForSymbol(QString symbol); | ||
|
||
QList<UnitPrefix> scalePrefixes() const; | ||
void setScalePrefixes(const QList<UnitPrefix> &newScalePrefixes); | ||
|
||
QList<ScaleOption> scaleOptions() const; | ||
void setScaleOptions(const QList<ScaleOption> &newScaleOptions); | ||
|
||
bool scalingEnabled() const; | ||
void setScalingEnabled(bool newScalingEnabled); | ||
|
||
QComboBox *scaleCb() const; | ||
|
||
QString unit() const; | ||
void setUnit(const QString &newUnit); | ||
|
||
void computeScale(double val); | ||
|
||
bool hasPrefix() const; | ||
void setHasPrefix(bool newHasPrefix); | ||
|
||
Q_SIGNALS: | ||
void scaleUpdated(); | ||
void unitChanged(QString unit); | ||
void scaleDown(int newScaleIndex); | ||
|
||
private: | ||
bool m_hasPrefix; | ||
bool m_scalingEnabled = true; | ||
double m_min, m_max; | ||
QString m_unit; | ||
QList<ScaleOption> m_scaleOptions; | ||
QList<UnitPrefix> m_scalePrefixes; | ||
QComboBox *m_scaleCb; | ||
void populateScaleCb(); | ||
}; | ||
|
||
} // namespace gui | ||
} // namespace scopy | ||
#endif // SCALE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef TESTSPINBOX_H | ||
#define TESTSPINBOX_H | ||
|
||
#include <QLabel> | ||
#include <QLineEdit> | ||
#include <QPushButton> | ||
#include <QWidget> | ||
#include <incrementstrategy.h> | ||
#include <mousewheelwidgetguard.h> | ||
#include <scale.h> | ||
#include <scopy-gui_export.h> | ||
|
||
namespace scopy { | ||
namespace gui { | ||
|
||
class SCOPY_GUI_EXPORT TestSpinbox : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
typedef enum | ||
{ | ||
IS_POW2, | ||
IS_125, | ||
IS_FIXED | ||
|
||
} IncrementMode; | ||
|
||
explicit TestSpinbox(QString name, double val, QString unit, double min, double max, bool vertical = 0, | ||
bool left = 0, QWidget *parent = nullptr); | ||
|
||
IncrementStrategy *incrementStrategy() const; | ||
|
||
double value() const; | ||
|
||
Scale *scale() const; | ||
void setScale(Scale *newScale); | ||
void setScalingEnabled(bool en); | ||
bool scallingEnabled(); | ||
|
||
public Q_SLOTS: | ||
void setIncrementMode(IncrementMode im); | ||
void setValue(double newValue); | ||
void setValueForce(double newValue, bool force = true); | ||
|
||
Q_SIGNALS: | ||
void nameChanged(QString); | ||
void valueChanged(double); | ||
void unitChanged(QString); | ||
|
||
private: | ||
void layoutVertically(bool left); | ||
void layoutHorizontally(bool left); | ||
void updateWidgetsVal(); | ||
double clamp(double val, double min, double max); | ||
|
||
QLabel *m_label; | ||
QLineEdit *m_edit; | ||
QPushButton *m_plus; | ||
QPushButton *m_minus; | ||
MouseWheelWidgetGuard *m_mouseWheelGuard; | ||
|
||
double m_value, m_min, m_max; | ||
|
||
IncrementStrategy *m_incrementStrategy; | ||
IncrementMode m_im; | ||
|
||
Scale *m_scale; | ||
|
||
int findLastDigit(QString str); | ||
double userInput(QString s); | ||
}; | ||
} // namespace gui | ||
} // namespace scopy | ||
#endif // TESTSPINBOX_H |
Oops, something went wrong.