mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
move graph data store to graphical item helper
It is required by custom graphs. X-AW-Count parameter (which is only recognized by Graph item type) has been introduced
This commit is contained in:
parent
7f665fef77
commit
52b1255d3f
@ -312,20 +312,14 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
// bars
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
if (item->type() == GraphicalItem::Graph) {
|
||||
if (item->isCustom())
|
||||
pattern.replace(
|
||||
QString("$%1").arg(bar),
|
||||
item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), aggregator, values, item->usedKeys())));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(QVariant::fromValue<QList<float>>(
|
||||
dataAggregator->getData(item->bar()))));
|
||||
} else {
|
||||
if (item->isCustom())
|
||||
pattern.replace(
|
||||
QString("$%1").arg(bar),
|
||||
item->image(AWPatternFunctions::expandLambdas(
|
||||
item->bar(), aggregator, values, item->usedKeys())));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(values[item->bar()]));
|
||||
}
|
||||
item->image(values[item->bar()]));
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
|
@ -47,6 +47,8 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeValue(int)));
|
||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
||||
SLOT(changeCountState(int)));
|
||||
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
|
||||
SLOT(changeColor()));
|
||||
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
|
||||
@ -73,6 +75,7 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
copyDefaults(item);
|
||||
item->setActiveColor(activeColor());
|
||||
item->setBar(m_bar);
|
||||
item->setCount(m_count);
|
||||
item->setCustom(m_custom);
|
||||
item->setDirection(m_direction);
|
||||
item->setHeight(m_height);
|
||||
@ -93,29 +96,28 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
|
||||
m_scene->clear();
|
||||
int scale[2] = {1, 1};
|
||||
float converted
|
||||
= m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue);
|
||||
|
||||
// paint
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
m_helper->paintVertical(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
m_helper->paintVertical(converted);
|
||||
// scale
|
||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Circle:
|
||||
m_helper->paintCircle(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
m_helper->paintCircle(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Graph:
|
||||
m_helper->paintGraph(value.value<QList<float>>());
|
||||
m_helper->paintGraph(converted);
|
||||
// direction option is not recognized by this GI type
|
||||
break;
|
||||
case Horizontal:
|
||||
default:
|
||||
m_helper->paintHorizontal(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
m_helper->paintHorizontal(converted);
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
@ -152,6 +154,12 @@ QString GraphicalItem::inactiveColor() const
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
|
||||
bool GraphicalItem::isCustom() const
|
||||
{
|
||||
return m_custom;
|
||||
@ -262,6 +270,16 @@ void GraphicalItem::setActiveColor(const QString _color)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setCount(const int _count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Count" << _count;
|
||||
if (_count <= 1)
|
||||
return;
|
||||
|
||||
m_count = _count;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setCustom(const bool _custom)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Use custom tag" << _custom;
|
||||
@ -379,6 +397,7 @@ void GraphicalItem::readConfiguration()
|
||||
QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Count"), m_count).toInt());
|
||||
setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool());
|
||||
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
|
||||
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat());
|
||||
@ -435,6 +454,7 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
}
|
||||
ui->doubleSpinBox_max->setValue(m_maxValue);
|
||||
ui->doubleSpinBox_min->setValue(m_minValue);
|
||||
ui->spinBox_count->setValue(m_count);
|
||||
ui->pushButton_activeColor->setText(activeColor());
|
||||
ui->pushButton_inactiveColor->setText(inactiveColor());
|
||||
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
|
||||
@ -442,12 +462,17 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
ui->spinBox_height->setValue(m_height);
|
||||
ui->spinBox_width->setValue(m_width);
|
||||
|
||||
// update UI
|
||||
changeCountState(ui->comboBox_type->currentIndex());
|
||||
changeValue(ui->checkBox_custom->checkState());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWGIAPI);
|
||||
setCount(ui->spinBox_count->value());
|
||||
setCustom(ui->checkBox_custom->isChecked());
|
||||
setBar(m_custom ? ui->lineEdit_customValue->text()
|
||||
: ui->comboBox_value->currentText());
|
||||
@ -476,6 +501,7 @@ void GraphicalItem::writeConfiguration() const
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Value"), m_bar);
|
||||
settings.setValue(QString("X-AW-Count"), m_count);
|
||||
settings.setValue(QString("X-AW-Custom"), m_custom);
|
||||
settings.setValue(QString("X-AW-Max"), m_maxValue);
|
||||
settings.setValue(QString("X-AW-Min"), m_minValue);
|
||||
@ -512,6 +538,15 @@ void GraphicalItem::changeColor()
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeCountState(const int state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current state is" << state;
|
||||
|
||||
// 3 is magic number. Actually 3 is Graph mode
|
||||
ui->widget_count->setHidden(state != 3);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeValue(const int state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current state is" << state;
|
||||
@ -540,7 +575,8 @@ void GraphicalItem::initScene()
|
||||
|
||||
// init helper
|
||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height);
|
||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
|
||||
m_count);
|
||||
}
|
||||
|
||||
|
||||
@ -548,6 +584,7 @@ void GraphicalItem::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_count->setText(i18n("Points count"));
|
||||
ui->checkBox_custom->setText(i18n("Use custom formula"));
|
||||
ui->label_value->setText(i18n("Value"));
|
||||
ui->label_customValue->setText(i18n("Value"));
|
||||
|
@ -37,6 +37,7 @@ class GraphicalItem : public AbstractExtItem
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString bar READ bar WRITE setBar)
|
||||
Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor)
|
||||
Q_PROPERTY(int count READ count WRITE setCount)
|
||||
Q_PROPERTY(bool custom READ isCustom WRITE setCustom)
|
||||
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
|
||||
Q_PROPERTY(Type type READ type WRITE setType)
|
||||
@ -61,6 +62,7 @@ public:
|
||||
QString bar() const;
|
||||
QString activeColor() const;
|
||||
QString inactiveColor() const;
|
||||
int count() const;
|
||||
bool isCustom() const;
|
||||
float minValue() const;
|
||||
float maxValue() const;
|
||||
@ -75,6 +77,7 @@ public:
|
||||
// set methods
|
||||
void setBar(const QString _bar = QString("cpu"));
|
||||
void setActiveColor(const QString _color = QString("0,0,0,130"));
|
||||
void setCount(const int _count = 100);
|
||||
void setCustom(const bool _custom = false);
|
||||
void setInactiveColor(const QString _color = QString("255,255,255,130"));
|
||||
void setMinValue(const float _value = 0.0);
|
||||
@ -95,6 +98,7 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void changeColor();
|
||||
void changeCountState(const int state);
|
||||
void changeValue(const int state);
|
||||
|
||||
private:
|
||||
@ -106,6 +110,7 @@ private:
|
||||
void translate();
|
||||
// properties
|
||||
QString m_bar = QString("cpu");
|
||||
int m_count = 100;
|
||||
bool m_custom = false;
|
||||
QColor m_activeColor = QColor(0, 0, 0, 130);
|
||||
QColor m_inactiveColor = QColor(255, 255, 255, 130);
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>416</width>
|
||||
<height>461</height>
|
||||
<height>481</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -187,6 +187,32 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_count" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_count">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_count">
|
||||
<property name="text">
|
||||
<string>Points count</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_count">
|
||||
<property name="maximum">
|
||||
<number>2000</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>25</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
|
@ -42,15 +42,17 @@ GraphicalItemHelper::~GraphicalItemHelper()
|
||||
|
||||
void GraphicalItemHelper::setParameters(const QColor active,
|
||||
const QColor inactive, const int width,
|
||||
const int height)
|
||||
const int height, const int count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive
|
||||
<< ", width" << width << ", height" << height;
|
||||
<< ", width" << width << ", height" << height << ", count"
|
||||
<< count;
|
||||
|
||||
m_activeColor = active;
|
||||
m_inactiveColor = inactive;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
|
||||
@ -77,24 +79,25 @@ void GraphicalItemHelper::paintCircle(const float &percent)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::paintGraph(const QList<float> &value)
|
||||
void GraphicalItemHelper::paintGraph(const float &value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Paint with value" << value;
|
||||
|
||||
storeValue(value);
|
||||
QPen pen;
|
||||
pen.setColor(m_activeColor);
|
||||
|
||||
// default norms
|
||||
float normX
|
||||
= static_cast<float>(m_width) / static_cast<float>(value.count());
|
||||
float normY = static_cast<float>(m_height) / (1.5f * 100.0f);
|
||||
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
|
||||
float normY = static_cast<float>(m_height) / 1.5f;
|
||||
// paint graph
|
||||
for (int i = 0; i < value.count() - 1; i++) {
|
||||
for (int i = 0; i < m_values.count() - 1; i++) {
|
||||
// some magic here
|
||||
float x1 = i * normX;
|
||||
float y1 = -fabs(value.at(i)) * normY + 5.0f;
|
||||
float y1 = -fabs(m_values.at(i)) * normY + 5.0f;
|
||||
float x2 = (i + 1) * normX;
|
||||
float y2 = -fabs(value.at(i + 1)) * normY + 5.0f;
|
||||
float y2 = -fabs(m_values.at(i + 1)) * normY + 5.0f;
|
||||
m_scene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
}
|
||||
@ -173,3 +176,16 @@ QColor GraphicalItemHelper::stringToColor(const QString &color)
|
||||
|
||||
return qColor;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::storeValue(const float &value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Save value to array" << value;
|
||||
|
||||
if (m_values.count() == 0)
|
||||
m_values.append(0.0);
|
||||
else if (m_values.count() > m_count)
|
||||
m_values.removeFirst();
|
||||
|
||||
m_values.append(value);
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ public:
|
||||
virtual ~GraphicalItemHelper();
|
||||
// parameters
|
||||
void setParameters(const QColor active, const QColor inactive,
|
||||
const int width, const int height);
|
||||
const int width, const int height, const int count);
|
||||
// paint methods
|
||||
void paintCircle(const float &percent);
|
||||
void paintGraph(const QList<float> &value);
|
||||
void paintGraph(const float &value);
|
||||
void paintHorizontal(const float &percent);
|
||||
void paintVertical(const float &percent);
|
||||
// additional conversion methods
|
||||
@ -44,11 +44,15 @@ public:
|
||||
QColor stringToColor(const QString &color);
|
||||
|
||||
private:
|
||||
void storeValue(const float &value);
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
int m_count;
|
||||
QColor m_activeColor;
|
||||
QColor m_inactiveColor;
|
||||
int m_width;
|
||||
int m_height;
|
||||
// list of values which will be used to store data for graph type only
|
||||
QList<float> m_values;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user