mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-05 09:55:52 +00:00
code improvements
* drop c++14 requirements since it is not used * move from enum to enum classes * more intuitive graph building in GI * allow X-AW-Direction property works with graphs and bars
This commit is contained in:
@ -112,17 +112,16 @@ QString ExtScript::strRedirect() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_redirect) {
|
||||
case stdout2stderr:
|
||||
case Redirect::stdout2stderr:
|
||||
value = QString("stdout2stderr");
|
||||
break;
|
||||
case stderr2stdout:
|
||||
case Redirect::stderr2stdout:
|
||||
value = QString("stderr2stdout");
|
||||
break;
|
||||
case swap:
|
||||
case Redirect::swap:
|
||||
value = QString("swap");
|
||||
break;
|
||||
case nothing:
|
||||
default:
|
||||
case Redirect::nothing:
|
||||
value = QString("nothing");
|
||||
break;
|
||||
}
|
||||
@ -158,7 +157,7 @@ void ExtScript::setPrefix(const QString _prefix)
|
||||
|
||||
void ExtScript::setRedirect(const Redirect _redirect)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
qCDebug(LOG_LIB) << "Redirect" << static_cast<int>(_redirect);
|
||||
|
||||
m_redirect = _redirect;
|
||||
}
|
||||
@ -169,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
if (_redirect == QString("stdout2sdterr"))
|
||||
m_redirect = stdout2stderr;
|
||||
m_redirect = Redirect::stdout2stderr;
|
||||
else if (_redirect == QString("stderr2sdtout"))
|
||||
m_redirect = stderr2stdout;
|
||||
m_redirect = Redirect::stderr2stdout;
|
||||
else if (_redirect == QString("swap"))
|
||||
m_redirect = swap;
|
||||
m_redirect = Redirect::swap;
|
||||
else
|
||||
m_redirect = nothing;
|
||||
m_redirect = Redirect::nothing;
|
||||
}
|
||||
|
||||
|
||||
@ -376,16 +375,15 @@ void ExtScript::updateValue()
|
||||
QString strValue;
|
||||
|
||||
switch (m_redirect) {
|
||||
case stdout2stderr:
|
||||
case Redirect::stdout2stderr:
|
||||
break;
|
||||
case stderr2stdout:
|
||||
case Redirect::stderr2stdout:
|
||||
strValue = QString("%1\n%2").arg(qdebug).arg(qoutput);
|
||||
break;
|
||||
case swap:
|
||||
case Redirect::swap:
|
||||
strValue = qdebug;
|
||||
break;
|
||||
case nothing:
|
||||
default:
|
||||
case Redirect::nothing:
|
||||
strValue = qoutput;
|
||||
break;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem
|
||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||
|
||||
public:
|
||||
enum Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
|
||||
enum class Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
|
||||
|
||||
explicit ExtScript(QWidget *parent = nullptr,
|
||||
const QString scriptName = QString(),
|
||||
@ -56,7 +56,7 @@ public:
|
||||
void setExecutable(const QString _executable = QString("/usr/bin/true"));
|
||||
void setFilters(const QStringList _filters = QStringList());
|
||||
void setPrefix(const QString _prefix = QString(""));
|
||||
void setRedirect(const Redirect _redirect = nothing);
|
||||
void setRedirect(const Redirect _redirect = Redirect::nothing);
|
||||
void setStrRedirect(const QString _redirect = QString("nothing"));
|
||||
// filters
|
||||
QString applyFilters(QString _value) const;
|
||||
@ -80,7 +80,7 @@ private:
|
||||
QString m_executable = QString("/usr/bin/true");
|
||||
QStringList m_filters = QStringList();
|
||||
QString m_prefix = QString("");
|
||||
Redirect m_redirect = nothing;
|
||||
Redirect m_redirect = Redirect::nothing;
|
||||
// internal properties
|
||||
QVariantMap jsonFilters = QVariantMap();
|
||||
int times = 0;
|
||||
|
@ -102,27 +102,27 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
|
||||
// paint
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
case Type::Vertical:
|
||||
m_helper->paintVertical(converted);
|
||||
// scale
|
||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Circle:
|
||||
case Type::Circle:
|
||||
m_helper->paintCircle(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Graph:
|
||||
case Type::Graph:
|
||||
m_helper->paintGraph(converted);
|
||||
// direction option is not recognized by this GI type
|
||||
break;
|
||||
case Bars:
|
||||
m_helper->paintBars(converted);
|
||||
// direction option is not recognized by this GI type
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
scale[1] = -1;
|
||||
break;
|
||||
case Horizontal:
|
||||
default:
|
||||
case Type::Bars:
|
||||
m_helper->paintBars(converted);
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
scale[1] = -1;
|
||||
break;
|
||||
case Type::Horizontal:
|
||||
m_helper->paintHorizontal(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
@ -194,20 +194,19 @@ QString GraphicalItem::strType() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
case Type::Vertical:
|
||||
value = QString("Vertical");
|
||||
break;
|
||||
case Circle:
|
||||
case Type::Circle:
|
||||
value = QString("Circle");
|
||||
break;
|
||||
case Graph:
|
||||
case Type::Graph:
|
||||
value = QString("Graph");
|
||||
break;
|
||||
case Bars:
|
||||
case Type::Bars:
|
||||
value = QString("Bars");
|
||||
break;
|
||||
case Horizontal:
|
||||
default:
|
||||
case Type::Horizontal:
|
||||
value = QString("Horizontal");
|
||||
break;
|
||||
}
|
||||
@ -226,11 +225,10 @@ QString GraphicalItem::strDirection() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_direction) {
|
||||
case RightToLeft:
|
||||
case Direction::RightToLeft:
|
||||
value = QString("RightToLeft");
|
||||
break;
|
||||
case LeftToRight:
|
||||
default:
|
||||
case Direction::LeftToRight:
|
||||
value = QString("LeftToRight");
|
||||
break;
|
||||
}
|
||||
@ -323,7 +321,7 @@ void GraphicalItem::setMinValue(const float _value)
|
||||
|
||||
void GraphicalItem::setType(const Type _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||
|
||||
m_type = _type;
|
||||
}
|
||||
@ -334,21 +332,21 @@ void GraphicalItem::setStrType(const QString _type)
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
if (_type == QString("Vertical"))
|
||||
setType(Vertical);
|
||||
setType(Type::Vertical);
|
||||
else if (_type == QString("Circle"))
|
||||
setType(Circle);
|
||||
setType(Type::Circle);
|
||||
else if (_type == QString("Graph"))
|
||||
setType(Graph);
|
||||
setType(Type::Graph);
|
||||
else if (_type == QString("Bars"))
|
||||
setType(Bars);
|
||||
setType(Type::Bars);
|
||||
else
|
||||
setType(Horizontal);
|
||||
setType(Type::Horizontal);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setDirection(const Direction _direction)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Direction" << _direction;
|
||||
qCDebug(LOG_LIB) << "Direction" << static_cast<int>(_direction);
|
||||
|
||||
m_direction = _direction;
|
||||
}
|
||||
@ -359,9 +357,9 @@ void GraphicalItem::setStrDirection(const QString _direction)
|
||||
qCDebug(LOG_LIB) << "Direction" << _direction;
|
||||
|
||||
if (_direction == QString("RightToLeft"))
|
||||
setDirection(RightToLeft);
|
||||
setDirection(Direction::RightToLeft);
|
||||
else
|
||||
setDirection(LeftToRight);
|
||||
setDirection(Direction::LeftToRight);
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,8 +49,8 @@ class GraphicalItem : public AbstractExtItem
|
||||
Q_PROPERTY(int width READ width WRITE setWidth)
|
||||
|
||||
public:
|
||||
enum Direction { LeftToRight = 0, RightToLeft };
|
||||
enum Type { Horizontal = 0, Vertical, Circle, Graph, Bars };
|
||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||
enum class Type { Horizontal = 0, Vertical, Circle, Graph, Bars };
|
||||
|
||||
explicit GraphicalItem(QWidget *parent = nullptr,
|
||||
const QString desktopName = QString(),
|
||||
@ -83,9 +83,9 @@ public:
|
||||
= QString("color://255,255,255,130"));
|
||||
void setMinValue(const float _value = 0.0);
|
||||
void setMaxValue(const float _value = 100.0);
|
||||
void setType(const Type _type = Horizontal);
|
||||
void setType(const Type _type = Type::Horizontal);
|
||||
void setStrType(const QString _type = QString("Horizontal"));
|
||||
void setDirection(const Direction _direction = LeftToRight);
|
||||
void setDirection(const Direction _direction = Direction::LeftToRight);
|
||||
void setStrDirection(const QString _direction = QString("LeftToRight"));
|
||||
void setHeight(const int _height = 100);
|
||||
void setUsedKeys(const QStringList _usedKeys = QStringList());
|
||||
@ -117,8 +117,8 @@ private:
|
||||
QString m_inactiveColor = QString("color://255,255,255,130");
|
||||
float m_minValue = 0.0f;
|
||||
float m_maxValue = 100.0f;
|
||||
Type m_type = Horizontal;
|
||||
Direction m_direction = LeftToRight;
|
||||
Type m_type = Type::Horizontal;
|
||||
Direction m_direction = Direction::LeftToRight;
|
||||
int m_height = 100;
|
||||
QStringList m_usedKeys;
|
||||
int m_width = 100;
|
||||
|
@ -144,9 +144,9 @@ void GraphicalItemHelper::paintGraph(const float &value)
|
||||
for (int i = 0; i < m_values.count() - 1; i++) {
|
||||
// some magic here
|
||||
float x1 = i * normX;
|
||||
float y1 = -m_values.at(i) * normY + 0.5f;
|
||||
float y1 = m_values.at(i) * normY + 0.5f;
|
||||
float x2 = (i + 1) * normX;
|
||||
float y2 = -m_values.at(i + 1) * normY + 0.5f;
|
||||
float y2 = m_values.at(i + 1) * normY + 0.5f;
|
||||
m_scene->addLine(x1, y1, x2, y2, m_activePen);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user