mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-14 14:25:50 +00:00
add tests for abstract formatter
This commit is contained in:
@ -46,20 +46,58 @@ void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const
|
||||
|
||||
QString AWAbstractFormatter::uniq() const
|
||||
{
|
||||
return QString("%1(%2)").arg(name()).arg(m_type);
|
||||
return QString("%1(%2)").arg(name()).arg(strType());
|
||||
}
|
||||
|
||||
|
||||
QString AWAbstractFormatter::type() const
|
||||
QString AWAbstractFormatter::strType() const
|
||||
{
|
||||
QString value;
|
||||
switch (m_type) {
|
||||
case FormatterClass::DateTime:
|
||||
value = QString("DateTime");
|
||||
break;
|
||||
case FormatterClass::Float:
|
||||
value = QString("Float");
|
||||
break;
|
||||
case FormatterClass::Script:
|
||||
value = QString("Script");
|
||||
break;
|
||||
case FormatterClass::NoFormat:
|
||||
value = QString("NoFormat");
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
AWAbstractFormatter::FormatterClass AWAbstractFormatter::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setType(const QString _type)
|
||||
void AWAbstractFormatter::setStrType(const QString _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
|
||||
if (_type == QString("DateTime"))
|
||||
m_type = FormatterClass::DateTime;
|
||||
else if (_type == QString("Float"))
|
||||
m_type = FormatterClass::Float;
|
||||
else if (_type == QString("Script"))
|
||||
m_type = FormatterClass::Script;
|
||||
else
|
||||
m_type = FormatterClass::NoFormat;
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractFormatter::setType(
|
||||
const AWAbstractFormatter::FormatterClass _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
|
||||
|
||||
m_type = _type;
|
||||
}
|
||||
|
||||
@ -71,7 +109,7 @@ void AWAbstractFormatter::readConfiguration()
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setType(settings.value(QString("X-AW-Type"), m_type).toString());
|
||||
setStrType(settings.value(QString("X-AW-Type"), strType()).toString());
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -84,7 +122,7 @@ void AWAbstractFormatter::writeConfiguration() const
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Type"), m_type);
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
|
@ -24,9 +24,12 @@
|
||||
class AWAbstractFormatter : public AbstractExtItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString type READ type WRITE setType)
|
||||
Q_PROPERTY(FormatterClass type READ type WRITE setType)
|
||||
Q_PROPERTY(QString strType READ strType WRITE setStrType)
|
||||
|
||||
public:
|
||||
enum class FormatterClass { DateTime, Float, Script, NoFormat };
|
||||
|
||||
explicit AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWAbstractFormatter();
|
||||
@ -34,8 +37,10 @@ public:
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
QString uniq() const;
|
||||
// properties
|
||||
QString type() const;
|
||||
void setType(const QString _type = QString("NoFormat"));
|
||||
QString strType() const;
|
||||
FormatterClass type() const;
|
||||
void setStrType(const QString type);
|
||||
void setType(const FormatterClass _type = FormatterClass::NoFormat);
|
||||
|
||||
public slots:
|
||||
virtual void readConfiguration();
|
||||
@ -44,7 +49,7 @@ public slots:
|
||||
|
||||
private:
|
||||
// properties
|
||||
QString m_type = QString("NoFormat");
|
||||
FormatterClass m_type = FormatterClass::NoFormat;
|
||||
};
|
||||
|
||||
|
||||
|
@ -115,7 +115,7 @@ int AWDateTimeFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setType(ui->label_typeValue->text());
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->lineEdit_format->text());
|
||||
|
||||
writeConfiguration();
|
||||
|
@ -212,7 +212,7 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setType(ui->label_typeValue->text());
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setFormat(ui->comboBox_format->currentText().at(0).toLatin1());
|
||||
setPrecision(ui->spinBox_precision->value());
|
||||
setCount(ui->spinBox_width->value());
|
||||
|
@ -79,7 +79,7 @@ int AWNoFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setType(ui->label_typeValue->text());
|
||||
setStrType(ui->label_typeValue->text());
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
|
@ -174,7 +174,7 @@ int AWScriptFormatter::showConfiguration(const QVariant args)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setType(ui->label_typeValue->text());
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setAppendCode(ui->checkBox_appendCode->checkState() == Qt::Checked);
|
||||
setHasReturn(ui->checkBox_hasReturn->checkState() == Qt::Checked);
|
||||
setCode(ui->textEdit_code->toPlainText());
|
||||
|
@ -168,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
|
||||
qCDebug(LOG_LIB) << "Redirect" << _redirect;
|
||||
|
||||
if (_redirect == QString("stdout2sdterr"))
|
||||
m_redirect = Redirect::stdout2stderr;
|
||||
setRedirect(Redirect::stdout2stderr);
|
||||
else if (_redirect == QString("stderr2sdtout"))
|
||||
m_redirect = Redirect::stderr2stdout;
|
||||
setRedirect(Redirect::stderr2stdout);
|
||||
else if (_redirect == QString("swap"))
|
||||
m_redirect = Redirect::swap;
|
||||
setRedirect(Redirect::swap);
|
||||
else
|
||||
m_redirect = Redirect::nothing;
|
||||
setRedirect(Redirect::nothing);
|
||||
}
|
||||
|
||||
|
||||
@ -317,7 +317,7 @@ int ExtScript::showConfiguration(const QVariant args)
|
||||
setExecutable(ui->lineEdit_command->text());
|
||||
setPrefix(ui->lineEdit_prefix->text());
|
||||
setActive(ui->checkBox_active->checkState() == Qt::Checked);
|
||||
setStrRedirect(ui->comboBox_redirect->currentText());
|
||||
setRedirect(static_cast<Redirect>(ui->comboBox_redirect->currentIndex()));
|
||||
setInterval(ui->spinBox_interval->value());
|
||||
// filters
|
||||
updateFilter(QString("color"),
|
||||
|
@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem
|
||||
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
|
||||
|
||||
public:
|
||||
enum class Redirect { stdout2stderr, nothing, stderr2stdout, swap };
|
||||
enum class Redirect { stdout2stderr = 0, nothing = 1, stderr2stdout = 2, swap = 3 };
|
||||
|
||||
explicit ExtScript(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~ExtScript();
|
||||
|
@ -43,8 +43,6 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString filePath)
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
|
||||
initScene();
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeValue(int)));
|
||||
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
|
||||
@ -141,6 +139,31 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
// cleanup
|
||||
delete m_helper;
|
||||
delete m_scene;
|
||||
|
||||
// init scene
|
||||
m_scene = new QGraphicsScene();
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
// init view
|
||||
m_view = new QGraphicsView(m_scene);
|
||||
m_view->setStyleSheet(QString("background: transparent"));
|
||||
m_view->setContentsMargins(0, 0, 0, 0);
|
||||
m_view->setFrameShape(QFrame::NoFrame);
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
|
||||
// init helper
|
||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
|
||||
m_count);
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::bar() const
|
||||
{
|
||||
return m_bar;
|
||||
@ -433,6 +456,7 @@ void GraphicalItem::readConfiguration()
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWGIAPI);
|
||||
initScene();
|
||||
}
|
||||
|
||||
|
||||
@ -489,8 +513,8 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
setMinValue(ui->doubleSpinBox_min->value());
|
||||
setActiveColor(ui->lineEdit_activeColor->text());
|
||||
setInactiveColor(ui->lineEdit_inactiveColor->text());
|
||||
setStrType(ui->comboBox_type->currentText());
|
||||
setStrDirection(ui->comboBox_direction->currentText());
|
||||
setType(static_cast<Type>(ui->comboBox_type->currentIndex()));
|
||||
setDirection(static_cast<Direction>(ui->comboBox_direction->currentIndex()));
|
||||
setItemHeight(ui->spinBox_height->value());
|
||||
setItemWidth(ui->spinBox_width->value());
|
||||
|
||||
@ -590,27 +614,6 @@ void GraphicalItem::changeValue(const int state)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
// init scene
|
||||
m_scene = new QGraphicsScene();
|
||||
m_scene->setBackgroundBrush(QBrush(Qt::NoBrush));
|
||||
// init view
|
||||
m_view = new QGraphicsView(m_scene);
|
||||
m_view->setStyleSheet(QString("background: transparent"));
|
||||
m_view->setContentsMargins(0, 0, 0, 0);
|
||||
m_view->setFrameShape(QFrame::NoFrame);
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
|
||||
// init helper
|
||||
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height,
|
||||
m_count);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
|
@ -50,12 +50,13 @@ class GraphicalItem : public AbstractExtItem
|
||||
|
||||
public:
|
||||
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
|
||||
enum class Type { Horizontal, Vertical, Circle, Graph, Bars };
|
||||
enum class Type { Horizontal = 0, Vertical = 1, Circle = 2, Graph = 3, Bars = 4 };
|
||||
|
||||
explicit GraphicalItem(QWidget *parent, const QString filePath = QString());
|
||||
virtual ~GraphicalItem();
|
||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||
QString image(const QVariant &value);
|
||||
void initScene();
|
||||
// get methods
|
||||
QString bar() const;
|
||||
QString activeColor() const;
|
||||
@ -105,7 +106,6 @@ private:
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsView *m_view = nullptr;
|
||||
Ui::GraphicalItem *ui = nullptr;
|
||||
void initScene();
|
||||
void translate();
|
||||
// properties
|
||||
QString m_bar = QString("cpu");
|
||||
|
Reference in New Issue
Block a user