mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
add string formatter
This commit is contained in:
parent
085eec7a3d
commit
0d4211b2c4
@ -29,6 +29,7 @@
|
||||
#include "awlistformatter.h"
|
||||
#include "awnoformatter.h"
|
||||
#include "awscriptformatter.h"
|
||||
#include "awstringformatter.h"
|
||||
|
||||
|
||||
AWFormatterHelper::AWFormatterHelper(QWidget *parent)
|
||||
@ -157,12 +158,14 @@ AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||
formatter = AWAbstractFormatter::FormatterClass::DateTime;
|
||||
else if (stringType == QString("Float"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::Float;
|
||||
else if (stringType == QString("List"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::List;
|
||||
else if (stringType == QString("NoFormat"))
|
||||
;
|
||||
else if (stringType == QString("Script"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::Script;
|
||||
else if (stringType == QString("List"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::List;
|
||||
else if (stringType == QString("String"))
|
||||
formatter = AWAbstractFormatter::FormatterClass::String;
|
||||
else
|
||||
qCWarning(LOG_AW) << "Unknown formatter" << stringType;
|
||||
|
||||
@ -199,16 +202,20 @@ void AWFormatterHelper::initFormatters()
|
||||
m_formattersClasses[name]
|
||||
= new AWFloatFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
m_formattersClasses[name] = new AWListFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
m_formattersClasses[name]
|
||||
= new AWScriptFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
m_formattersClasses[name]
|
||||
= new AWStringFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
m_formattersClasses[name] = new AWNoFormatter(this, filePath);
|
||||
break;
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
m_formattersClasses[name] = new AWListFormatter(this, filePath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -286,8 +293,8 @@ void AWFormatterHelper::doCreateItem()
|
||||
{
|
||||
QStringList selection = QStringList()
|
||||
<< QString("NoFormat") << QString("DateTime")
|
||||
<< QString("Float") << QString("Script")
|
||||
<< QString("List");
|
||||
<< QString("Float") << QString("List")
|
||||
<< QString("Script") << QString("String");
|
||||
bool ok;
|
||||
QString select = QInputDialog::getItem(
|
||||
this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||
@ -304,12 +311,14 @@ void AWFormatterHelper::doCreateItem()
|
||||
return createItem<AWDateTimeFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Float:
|
||||
return createItem<AWFloatFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
return createItem<AWScriptFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
return createItem<AWNoFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::List:
|
||||
return createItem<AWListFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::Script:
|
||||
return createItem<AWScriptFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::String:
|
||||
return createItem<AWStringFormatter>();
|
||||
case AWAbstractFormatter::FormatterClass::NoFormat:
|
||||
return createItem<AWNoFormatter>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,15 +60,18 @@ QString AWAbstractFormatter::strType() const
|
||||
case FormatterClass::Float:
|
||||
value = QString("Float");
|
||||
break;
|
||||
case FormatterClass::List:
|
||||
value = QString("List");
|
||||
break;
|
||||
case FormatterClass::Script:
|
||||
value = QString("Script");
|
||||
break;
|
||||
case FormatterClass::String:
|
||||
value = QString("String");
|
||||
break;
|
||||
case FormatterClass::NoFormat:
|
||||
value = QString("NoFormat");
|
||||
break;
|
||||
case FormatterClass::List:
|
||||
value = QString("List");
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
@ -89,10 +92,12 @@ void AWAbstractFormatter::setStrType(const QString _type)
|
||||
m_type = FormatterClass::DateTime;
|
||||
else if (_type == QString("Float"))
|
||||
m_type = FormatterClass::Float;
|
||||
else if (_type == QString("Script"))
|
||||
m_type = FormatterClass::Script;
|
||||
else if (_type == QString("List"))
|
||||
m_type = FormatterClass::List;
|
||||
else if (_type == QString("Script"))
|
||||
m_type = FormatterClass::Script;
|
||||
else if (_type == QString("String"))
|
||||
m_type = FormatterClass::String;
|
||||
else
|
||||
m_type = FormatterClass::NoFormat;
|
||||
}
|
||||
|
@ -28,7 +28,14 @@ class AWAbstractFormatter : public AbstractExtItem
|
||||
Q_PROPERTY(QString strType READ strType WRITE setStrType)
|
||||
|
||||
public:
|
||||
enum class FormatterClass { DateTime, Float, Script, NoFormat, List };
|
||||
enum class FormatterClass {
|
||||
DateTime,
|
||||
Float,
|
||||
List,
|
||||
Script,
|
||||
String,
|
||||
NoFormat
|
||||
};
|
||||
|
||||
explicit AWAbstractFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
|
@ -52,8 +52,13 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
return QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
QString output
|
||||
= QString("%1").arg(_value.toDouble() * multiplier() + summand(),
|
||||
count(), format(), precision(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +73,7 @@ AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||
item->setCount(count());
|
||||
item->setFormat(format());
|
||||
item->setFillChar(fillChar());
|
||||
item->setForceWidth(forceWidth());
|
||||
item->setMultiplier(multiplier());
|
||||
item->setNumber(_number);
|
||||
item->setPrecision(precision());
|
||||
@ -89,6 +95,12 @@ QChar AWFloatFormatter::fillChar() const
|
||||
}
|
||||
|
||||
|
||||
bool AWFloatFormatter::forceWidth() const
|
||||
{
|
||||
return m_forceWidth;
|
||||
}
|
||||
|
||||
|
||||
char AWFloatFormatter::format() const
|
||||
{
|
||||
return m_format;
|
||||
@ -129,6 +141,14 @@ void AWFloatFormatter::setFillChar(const QChar _fillChar)
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setForceWidth(const bool _forceWidth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||
|
||||
m_forceWidth = _forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWFloatFormatter::setFormat(char _format)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set format" << _format;
|
||||
@ -177,6 +197,8 @@ void AWFloatFormatter::readConfiguration()
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
setFormat(settings.value(QString("X-AW-Format"), QString(format()))
|
||||
.toString()
|
||||
.at(0)
|
||||
@ -204,6 +226,8 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
ui->spinBox_precision->setValue(precision());
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
ui->doubleSpinBox_multiplier->setValue(multiplier());
|
||||
ui->doubleSpinBox_summand->setValue(summand());
|
||||
|
||||
@ -217,6 +241,7 @@ int AWFloatFormatter::showConfiguration(const QVariant args)
|
||||
setPrecision(ui->spinBox_precision->value());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||
setMultiplier(ui->doubleSpinBox_multiplier->value());
|
||||
setSummand(ui->doubleSpinBox_summand->value());
|
||||
|
||||
@ -236,6 +261,7 @@ void AWFloatFormatter::writeConfiguration() const
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-Format"), format());
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.setValue(QString("X-AW-Multiplier"), multiplier());
|
||||
settings.setValue(QString("X-AW-Precision"), precision());
|
||||
settings.setValue(QString("X-AW-Summand"), summand());
|
||||
@ -254,6 +280,7 @@ void AWFloatFormatter::translate()
|
||||
ui->label_precision->setText(i18n("Precision"));
|
||||
ui->label_width->setText(i18n("Width"));
|
||||
ui->label_fill->setText(i18n("Fill char"));
|
||||
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||
ui->label_multiplier->setText(i18n("Multiplier"));
|
||||
ui->label_summand->setText(i18n("Summand"));
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class AWFloatFormatter : public AWAbstractFormatter
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count WRITE setCount)
|
||||
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
Q_PROPERTY(char format READ format WRITE setFormat)
|
||||
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
||||
Q_PROPERTY(int precision READ precision WRITE setPrecision)
|
||||
@ -45,12 +46,14 @@ public:
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
bool forceWidth() const;
|
||||
char format() const;
|
||||
double multiplier() const;
|
||||
int precision() const;
|
||||
double summand() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
void setFormat(char _format);
|
||||
void setMultiplier(const double _multiplier);
|
||||
void setPrecision(const int _precision);
|
||||
@ -67,6 +70,7 @@ private:
|
||||
// properties
|
||||
int m_count = 0;
|
||||
QChar m_fillChar = QChar();
|
||||
bool m_forceWidth = false;
|
||||
char m_format = 'f';
|
||||
double m_multiplier = 1.0;
|
||||
int m_precision = -1;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>315</height>
|
||||
<height>362</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -199,6 +199,36 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_forceWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
|
192
sources/awesomewidgets/awstringformatter.cpp
Normal file
192
sources/awesomewidgets/awstringformatter.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awstringformatter.h"
|
||||
#include "ui_awstringformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWStringFormatter::AWStringFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWStringFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter::~AWStringFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWStringFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QString output = QString("%1").arg(_value.toString(), count(), fillChar());
|
||||
if (forceWidth())
|
||||
output = output.left(count());
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
AWStringFormatter *AWStringFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWStringFormatter *item
|
||||
= new AWStringFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setCount(count());
|
||||
item->setFillChar(fillChar());
|
||||
item->setForceWidth(forceWidth());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
int AWStringFormatter::count() const
|
||||
{
|
||||
return m_count;
|
||||
}
|
||||
|
||||
|
||||
QChar AWStringFormatter::fillChar() const
|
||||
{
|
||||
return m_fillChar;
|
||||
}
|
||||
|
||||
|
||||
bool AWStringFormatter::forceWidth() const
|
||||
{
|
||||
return m_forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setCount(const int _count)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set width" << _count;
|
||||
|
||||
m_count = _count;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setFillChar(const QChar _fillChar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set char" << _fillChar;
|
||||
|
||||
m_fillChar = _fillChar;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::setForceWidth(const bool _forceWidth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set force strip" << _forceWidth;
|
||||
|
||||
m_forceWidth = _forceWidth;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::readConfiguration()
|
||||
{
|
||||
AWAbstractFormatter::readConfiguration();
|
||||
|
||||
QSettings settings(fileName(), QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCount(settings.value(QString("X-AW-Width"), count()).toInt());
|
||||
setFillChar(
|
||||
settings.value(QString("X-AW-FillChar"), fillChar()).toString().at(0));
|
||||
setForceWidth(
|
||||
settings.value(QString("X-AW-ForceWidth"), forceWidth()).toBool());
|
||||
settings.endGroup();
|
||||
|
||||
bumpApi(AWEFAPI);
|
||||
}
|
||||
|
||||
|
||||
int AWStringFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("String"));
|
||||
ui->spinBox_width->setValue(count());
|
||||
ui->lineEdit_fill->setText(QString(fillChar()));
|
||||
ui->checkBox_forceWidth->setCheckState(forceWidth() ? Qt::Checked
|
||||
: Qt::Unchecked);
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setCount(ui->spinBox_width->value());
|
||||
setFillChar(ui->lineEdit_fill->text().at(0));
|
||||
setForceWidth(ui->checkBox_forceWidth->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::writeConfiguration() const
|
||||
{
|
||||
AWAbstractFormatter::writeConfiguration();
|
||||
|
||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||
qCInfo(LOG_LIB) << "Configuration file" << settings.fileName();
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Width"), count());
|
||||
settings.setValue(QString("X-AW-FillChar"), fillChar());
|
||||
settings.setValue(QString("X-AW-ForceWidth"), forceWidth());
|
||||
settings.endGroup();
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
|
||||
void AWStringFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_width->setText(i18n("Width"));
|
||||
ui->label_fill->setText(i18n("Fill char"));
|
||||
ui->checkBox_forceWidth->setText(i18n("Force width"));
|
||||
}
|
65
sources/awesomewidgets/awstringformatter.h
Normal file
65
sources/awesomewidgets/awstringformatter.h
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef AWSTRINGFORMATTER_H
|
||||
#define AWSTRINGFORMATTER_H
|
||||
|
||||
#include "awabstractformatter.h"
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWStringFormatter;
|
||||
}
|
||||
|
||||
class AWStringFormatter : public AWAbstractFormatter
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int count READ count WRITE setCount)
|
||||
Q_PROPERTY(QChar fillChar READ fillChar WRITE setFillChar)
|
||||
Q_PROPERTY(bool forceWidth READ forceWidth WRITE setForceWidth)
|
||||
|
||||
public:
|
||||
explicit AWStringFormatter(QWidget *parent,
|
||||
const QString filePath = QString());
|
||||
virtual ~AWStringFormatter();
|
||||
QString convert(const QVariant &_value) const;
|
||||
AWStringFormatter *copy(const QString _fileName, const int _number);
|
||||
// properties
|
||||
int count() const;
|
||||
QChar fillChar() const;
|
||||
bool forceWidth() const;
|
||||
void setCount(const int _count);
|
||||
void setFillChar(const QChar _fillChar);
|
||||
void setForceWidth(const bool _forceWidth);
|
||||
|
||||
public slots:
|
||||
void readConfiguration();
|
||||
int showConfiguration(const QVariant args = QVariant());
|
||||
void writeConfiguration() const;
|
||||
|
||||
private:
|
||||
Ui::AWStringFormatter *ui = nullptr;
|
||||
void translate();
|
||||
// properties
|
||||
int m_count = 0;
|
||||
QChar m_fillChar = QChar();
|
||||
bool m_forceWidth = false;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWSTRINGFORMATTER_H */
|
225
sources/awesomewidgets/awstringformatter.ui
Normal file
225
sources/awesomewidgets/awstringformatter.ui
Normal file
@ -0,0 +1,225 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWStringFormatter</class>
|
||||
<widget class="QDialog" name="AWStringFormatter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>420</width>
|
||||
<height>225</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_comment">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_comment">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Comment</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_comment"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_type">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_type">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_typeValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_width">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_width">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_width">
|
||||
<property name="minimum">
|
||||
<number>-10000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10000</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_fill">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_fill">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fill char</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_fill">
|
||||
<property name="maxLength">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_forceWIdth">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_forceWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Force width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWStringFormatter</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWStringFormatter</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -27,7 +27,7 @@ set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSO
|
||||
## modules
|
||||
set(TEST_MODULES
|
||||
abstractextitem extquotes extscript extupgrade extweather
|
||||
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter
|
||||
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter stringformatter
|
||||
extitemaggregator
|
||||
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
|
||||
awconfighelper awkeycache awkeys awpatternfunctions awupdatehelper
|
||||
|
@ -49,8 +49,7 @@ void TestAWFloatFormatter::test_count()
|
||||
QCOMPARE(formatter->count(), count);
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
@ -67,8 +66,7 @@ void TestAWFloatFormatter::test_fillChar()
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
int value = AWTestLibrary::randomInt();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomInt());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
|
||||
// reset
|
||||
@ -77,6 +75,24 @@ void TestAWFloatFormatter::test_fillChar()
|
||||
}
|
||||
|
||||
|
||||
void TestAWFloatFormatter::test_forceWidth()
|
||||
{
|
||||
// assign
|
||||
int count = AWTestLibrary::randomInt(6);
|
||||
formatter->setForceWidth(true);
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->forceWidth(), true);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setForceWidth(false);
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWFloatFormatter::test_format()
|
||||
{
|
||||
// assign
|
||||
@ -87,8 +103,7 @@ void TestAWFloatFormatter::test_format()
|
||||
QCOMPARE(formatter->format(), 'e');
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
QVERIFY(output.contains('e'));
|
||||
|
||||
// reset
|
||||
@ -104,8 +119,7 @@ void TestAWFloatFormatter::test_precision()
|
||||
QCOMPARE(formatter->precision(), precision);
|
||||
|
||||
// test
|
||||
double value = AWTestLibrary::randomDouble();
|
||||
QString output = formatter->convert(value);
|
||||
QString output = formatter->convert(AWTestLibrary::randomDouble());
|
||||
output.remove(QString("0."));
|
||||
QCOMPARE(output.count(), precision);
|
||||
|
||||
@ -157,6 +171,7 @@ void TestAWFloatFormatter::test_copy()
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
QCOMPARE(newFormatter->forceWidth(), formatter->forceWidth());
|
||||
QCOMPARE(newFormatter->format(), formatter->format());
|
||||
QCOMPARE(newFormatter->multiplier(), formatter->multiplier());
|
||||
QCOMPARE(newFormatter->precision(), formatter->precision());
|
||||
@ -171,6 +186,7 @@ void TestAWFloatFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
formatter->setFormat(AWTestLibrary::randomChar());
|
||||
formatter->setMultiplier(AWTestLibrary::randomDouble());
|
||||
formatter->setPrecision(AWTestLibrary::randomInt());
|
||||
|
@ -36,6 +36,7 @@ private slots:
|
||||
void test_values();
|
||||
void test_count();
|
||||
void test_fillChar();
|
||||
void test_forceWidth();
|
||||
void test_format();
|
||||
void test_precision();
|
||||
void test_multiplier();
|
||||
|
118
sources/test/teststringformatter.cpp
Normal file
118
sources/test/teststringformatter.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "teststringformatter.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awstringformatter.h"
|
||||
#include "awtestlibrary.h"
|
||||
|
||||
|
||||
void TestAWStringFormatter::initTestCase()
|
||||
{
|
||||
formatter = new AWStringFormatter(nullptr);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::cleanupTestCase()
|
||||
{
|
||||
delete formatter;
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_values()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_count()
|
||||
{
|
||||
// assign
|
||||
int count = 10 + AWTestLibrary::randomInt();
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->count(), count);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_fillChar()
|
||||
{
|
||||
// assign
|
||||
char c = AWTestLibrary::randomChar();
|
||||
formatter->setFillChar(QChar(c));
|
||||
QCOMPARE(formatter->fillChar(), QChar(c));
|
||||
formatter->setCount(101);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QVERIFY(output.startsWith(QChar(c)));
|
||||
|
||||
// reset
|
||||
formatter->setFillChar(QChar());
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_forceWidth()
|
||||
{
|
||||
// assign
|
||||
int count = AWTestLibrary::randomInt();
|
||||
formatter->setForceWidth(true);
|
||||
formatter->setCount(count);
|
||||
QCOMPARE(formatter->forceWidth(), true);
|
||||
|
||||
// test
|
||||
QString output = formatter->convert(AWTestLibrary::randomString());
|
||||
QCOMPARE(output.count(), count);
|
||||
|
||||
// reset
|
||||
formatter->setForceWidth(false);
|
||||
formatter->setCount(0);
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::test_copy()
|
||||
{
|
||||
doRandom();
|
||||
AWStringFormatter *newFormatter = formatter->copy(QString("/dev/null"), 1);
|
||||
|
||||
QCOMPARE(newFormatter->count(), formatter->count());
|
||||
QCOMPARE(newFormatter->fillChar(), formatter->fillChar());
|
||||
QCOMPARE(newFormatter->forceWidth(), formatter->forceWidth());
|
||||
QCOMPARE(newFormatter->number(), 1);
|
||||
|
||||
delete newFormatter;
|
||||
}
|
||||
|
||||
|
||||
void TestAWStringFormatter::doRandom()
|
||||
{
|
||||
formatter->setCount(AWTestLibrary::randomInt());
|
||||
formatter->setFillChar(QChar(AWTestLibrary::randomChar()));
|
||||
formatter->setForceWidth(AWTestLibrary::randomInt() % 2);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAWStringFormatter);
|
48
sources/test/teststringformatter.h
Normal file
48
sources/test/teststringformatter.h
Normal file
@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef TESTSTRINGFORMATTER_H
|
||||
#define TESTSTRINGFORMATTER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class AWStringFormatter;
|
||||
|
||||
class TestAWStringFormatter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_values();
|
||||
void test_count();
|
||||
void test_fillChar();
|
||||
void test_forceWidth();
|
||||
void test_copy();
|
||||
|
||||
private:
|
||||
void doRandom();
|
||||
AWStringFormatter *formatter = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTSTRINGFORMATTER_H */
|
Loading…
Reference in New Issue
Block a user