mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
rewrite formatters to ext classes
This commit is contained in:
parent
14aab3b758
commit
326c65528d
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "awactions.h"
|
#include "awactions.h"
|
||||||
#include "awconfighelper.h"
|
#include "awconfighelper.h"
|
||||||
#include "awdataengineaggregator.h"
|
#include "awformatterhelper.h"
|
||||||
#include "awkeys.h"
|
#include "awkeys.h"
|
||||||
|
|
||||||
|
|
||||||
@ -31,5 +31,6 @@ void AWPlugin::registerTypes(const char *uri)
|
|||||||
|
|
||||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||||
|
qmlRegisterType<AWFormatterHelper>(uri, 1, 0, "AWFormatterHelper");
|
||||||
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,11 @@
|
|||||||
|
|
||||||
#include "awformatterhelper.h"
|
#include "awformatterhelper.h"
|
||||||
|
|
||||||
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QInputDialog>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
#include "awdatetimeformatter.h"
|
#include "awdatetimeformatter.h"
|
||||||
@ -28,15 +30,13 @@
|
|||||||
#include "awscriptformatter.h"
|
#include "awscriptformatter.h"
|
||||||
|
|
||||||
|
|
||||||
AWFormatterHelper::AWFormatterHelper(QObject *parent)
|
AWFormatterHelper::AWFormatterHelper(QWidget *parent)
|
||||||
: QObject(parent)
|
: AbstractExtItemAggregator(parent, QString("formatters"))
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
#ifdef BUILD_FUTURE
|
#ifdef BUILD_FUTURE
|
||||||
installDirectories();
|
initItems();
|
||||||
initFormatters();
|
|
||||||
initKeys();
|
|
||||||
#endif /* BUILD_FUTURE */
|
#endif /* BUILD_FUTURE */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +66,30 @@ QStringList AWFormatterHelper::definedFormatters() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AWFormatterHelper::formatterByTag(const QString tag) const
|
||||||
|
{
|
||||||
|
qCDebug(LOG_AW) << "Looking for tag" << tag;
|
||||||
|
|
||||||
|
return m_formatters.contains(tag) ? m_formatters[tag]->name() : QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList AWFormatterHelper::knownFormatters() const
|
QStringList AWFormatterHelper::knownFormatters() const
|
||||||
{
|
{
|
||||||
return m_formattersClasses.keys();
|
return m_formattersClasses.keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||||
|
{
|
||||||
|
QList<AbstractExtItem *> converted;
|
||||||
|
for (auto item : m_formattersClasses.values())
|
||||||
|
converted.append(item);
|
||||||
|
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AWFormatterHelper::FormatterClass
|
AWFormatterHelper::FormatterClass
|
||||||
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||||
{
|
{
|
||||||
@ -114,19 +132,18 @@ void AWFormatterHelper::initFormatters()
|
|||||||
switch (metadata.second) {
|
switch (metadata.second) {
|
||||||
case FormatterClass::DateTime:
|
case FormatterClass::DateTime:
|
||||||
m_formattersClasses[name]
|
m_formattersClasses[name]
|
||||||
= new AWDateTimeFormatter(nullptr, filePath);
|
= new AWDateTimeFormatter(this, filePath);
|
||||||
break;
|
break;
|
||||||
case FormatterClass::Float:
|
case FormatterClass::Float:
|
||||||
m_formattersClasses[name]
|
m_formattersClasses[name]
|
||||||
= new AWFloatFormatter(nullptr, filePath);
|
= new AWFloatFormatter(this, filePath);
|
||||||
break;
|
break;
|
||||||
case FormatterClass::Script:
|
case FormatterClass::Script:
|
||||||
m_formattersClasses[name]
|
m_formattersClasses[name]
|
||||||
= new AWScriptFormatter(nullptr, filePath);
|
= new AWScriptFormatter(this, filePath);
|
||||||
break;
|
break;
|
||||||
case FormatterClass::NoFormat:
|
case FormatterClass::NoFormat:
|
||||||
m_formattersClasses[name]
|
m_formattersClasses[name] = new AWNoFormatter(this, filePath);
|
||||||
= new AWNoFormatter(nullptr, filePath);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,3 +202,36 @@ AWFormatterHelper::readMetadata(const QString filePath) const
|
|||||||
|
|
||||||
return QPair<QString, AWFormatterHelper::FormatterClass>(name, formatter);
|
return QPair<QString, AWFormatterHelper::FormatterClass>(name, formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::doCreateItem()
|
||||||
|
{
|
||||||
|
QStringList selection = QStringList()
|
||||||
|
<< QString("NoFormat") << QString("DateTime")
|
||||||
|
<< QString("Float") << QString("Script");
|
||||||
|
bool ok;
|
||||||
|
QString select = QInputDialog::getItem(
|
||||||
|
this, i18n("Select type"), i18n("Type:"), selection, 0, false, &ok);
|
||||||
|
if (!ok)
|
||||||
|
return;
|
||||||
|
|
||||||
|
FormatterClass formatter = defineFormatterClass(select);
|
||||||
|
switch (formatter) {
|
||||||
|
case FormatterClass::DateTime:
|
||||||
|
return createItem<AWDateTimeFormatter>();
|
||||||
|
case FormatterClass::Float:
|
||||||
|
return createItem<AWFloatFormatter>();
|
||||||
|
case FormatterClass::Script:
|
||||||
|
return createItem<AWScriptFormatter>();
|
||||||
|
case FormatterClass::NoFormat:
|
||||||
|
return createItem<AWNoFormatter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AWFormatterHelper::initItems()
|
||||||
|
{
|
||||||
|
installDirectories();
|
||||||
|
initFormatters();
|
||||||
|
initKeys();
|
||||||
|
}
|
||||||
|
@ -19,25 +19,28 @@
|
|||||||
#ifndef AWFORMATTERHELPER_H
|
#ifndef AWFORMATTERHELPER_H
|
||||||
#define AWFORMATTERHELPER_H
|
#define AWFORMATTERHELPER_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "abstractextitemaggregator.h"
|
||||||
|
|
||||||
#include "awabstractformatter.h"
|
|
||||||
|
|
||||||
|
|
||||||
class AWFormatterHelper : public QObject
|
class AWAbstractFormatter;
|
||||||
|
|
||||||
|
class AWFormatterHelper : public AbstractExtItemAggregator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class FormatterClass { DateTime, Float, Script, NoFormat };
|
enum class FormatterClass { DateTime, Float, Script, NoFormat };
|
||||||
|
|
||||||
explicit AWFormatterHelper(QObject *parent = nullptr);
|
explicit AWFormatterHelper(QWidget *parent = nullptr);
|
||||||
virtual ~AWFormatterHelper();
|
virtual ~AWFormatterHelper();
|
||||||
QString convert(const QVariant &value, const QString name) const;
|
QString convert(const QVariant &value, const QString name) const;
|
||||||
QStringList definedFormatters() const;
|
Q_INVOKABLE QStringList definedFormatters() const;
|
||||||
QStringList knownFormatters() const;
|
Q_INVOKABLE QString formatterByTag(const QString tag) const;
|
||||||
|
Q_INVOKABLE QStringList knownFormatters() const;
|
||||||
|
QList<AbstractExtItem *> items() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// methods
|
||||||
AWFormatterHelper::FormatterClass
|
AWFormatterHelper::FormatterClass
|
||||||
defineFormatterClass(const QString stringType) const;
|
defineFormatterClass(const QString stringType) const;
|
||||||
void initFormatters();
|
void initFormatters();
|
||||||
@ -45,6 +48,9 @@ private:
|
|||||||
void installDirectories();
|
void installDirectories();
|
||||||
QPair<QString, AWFormatterHelper::FormatterClass>
|
QPair<QString, AWFormatterHelper::FormatterClass>
|
||||||
readMetadata(const QString filePath) const;
|
readMetadata(const QString filePath) const;
|
||||||
|
// parent methods
|
||||||
|
void doCreateItem();
|
||||||
|
void initItems();
|
||||||
// properties
|
// properties
|
||||||
QStringList m_directories;
|
QStringList m_directories;
|
||||||
QString m_formatterConfig;
|
QString m_formatterConfig;
|
||||||
|
@ -49,7 +49,7 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
|
|||||||
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
m_formatter[QString("swaptotmb")] = FormatterType::MemMBFormat;
|
||||||
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
m_formatter[QString("swaptotgb")] = FormatterType::MemGBFormat;
|
||||||
|
|
||||||
m_customFormatters = new AWFormatterHelper(this);
|
m_customFormatters = new AWFormatterHelper(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,15 +19,16 @@
|
|||||||
|
|
||||||
#include <KI18n/KLocalizedString>
|
#include <KI18n/KLocalizedString>
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
|
||||||
#include "awdebug.h"
|
|
||||||
|
|
||||||
|
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent,
|
||||||
AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent)
|
const QString type)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_type(type)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
@ -62,6 +63,59 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::copyItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
QString fileName = getName();
|
||||||
|
int number = uniqNumber();
|
||||||
|
QString dir = QString("%1/awesomewidgets/%2")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation))
|
||||||
|
.arg(m_type);
|
||||||
|
if ((source == nullptr) || (fileName.isEmpty())) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to copy";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||||
|
|
||||||
|
AbstractExtItem *newItem = source->copy(filePath, number);
|
||||||
|
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::deleteItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
if (source == nullptr) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to delete";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (source->tryDelete()) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::editItem()
|
||||||
|
{
|
||||||
|
AbstractExtItem *source = itemFromWidget();
|
||||||
|
if (source == nullptr) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to edit";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (source->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AbstractExtItemAggregator::getName()
|
QString AbstractExtItemAggregator::getName()
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
@ -77,12 +131,69 @@ QString AbstractExtItemAggregator::getName()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AbstractExtItem *AbstractExtItemAggregator::itemFromWidget()
|
||||||
|
{
|
||||||
|
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
||||||
|
if (widgetItem == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
AbstractExtItem *found = nullptr;
|
||||||
|
for (auto item : items()) {
|
||||||
|
QString fileName = QFileInfo(item->fileName()).fileName();
|
||||||
|
if (fileName != widgetItem->text())
|
||||||
|
continue;
|
||||||
|
found = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (found == nullptr)
|
||||||
|
qCWarning(LOG_LIB) << "Could not find item by name"
|
||||||
|
<< widgetItem->text();
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AbstractExtItemAggregator::repaintList()
|
||||||
|
{
|
||||||
|
widgetDialog->clear();
|
||||||
|
for (auto _item : items()) {
|
||||||
|
QString fileName = QFileInfo(_item->fileName()).fileName();
|
||||||
|
QListWidgetItem *item = new QListWidgetItem(fileName, widgetDialog);
|
||||||
|
QStringList tooltip;
|
||||||
|
tooltip.append(i18n("Name: %1", _item->name()));
|
||||||
|
tooltip.append(i18n("Comment: %1", _item->comment()));
|
||||||
|
tooltip.append(i18n("Identity: %1", _item->uniq()));
|
||||||
|
item->setToolTip(tooltip.join(QChar('\n')));
|
||||||
|
widgetDialog->addItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int AbstractExtItemAggregator::uniqNumber() const
|
||||||
|
{
|
||||||
|
QList<int> tagList;
|
||||||
|
for (auto item : items())
|
||||||
|
tagList.append(item->number());
|
||||||
|
int number = 0;
|
||||||
|
while (tagList.contains(number))
|
||||||
|
number++;
|
||||||
|
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant AbstractExtItemAggregator::configArgs() const
|
QVariant AbstractExtItemAggregator::configArgs() const
|
||||||
{
|
{
|
||||||
return m_configArgs;
|
return m_configArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString AbstractExtItemAggregator::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
qCDebug(LOG_LIB) << "Configuration arguments" << _configArgs;
|
||||||
@ -102,7 +213,7 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
|
|||||||
if (static_cast<QPushButton *>(button) == copyButton)
|
if (static_cast<QPushButton *>(button) == copyButton)
|
||||||
return copyItem();
|
return copyItem();
|
||||||
else if (static_cast<QPushButton *>(button) == createButton)
|
else if (static_cast<QPushButton *>(button) == createButton)
|
||||||
return createItem();
|
return doCreateItem();
|
||||||
else if (static_cast<QPushButton *>(button) == deleteButton)
|
else if (static_cast<QPushButton *>(button) == deleteButton)
|
||||||
return deleteItem();
|
return deleteItem();
|
||||||
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
|
||||||
|
@ -22,19 +22,52 @@
|
|||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "abstractextitem.h"
|
||||||
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
// additional class since QObject macro does not allow class templates
|
// additional class since QObject macro does not allow class templates
|
||||||
class AbstractExtItemAggregator : public QWidget
|
class AbstractExtItemAggregator : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
|
||||||
|
Q_PROPERTY(QVariant type READ type)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AbstractExtItemAggregator(QWidget *parent = nullptr);
|
explicit AbstractExtItemAggregator(QWidget *parent, const QString type);
|
||||||
virtual ~AbstractExtItemAggregator();
|
virtual ~AbstractExtItemAggregator();
|
||||||
|
// methods
|
||||||
|
void copyItem();
|
||||||
|
template <class T> void createItem()
|
||||||
|
{
|
||||||
|
QString fileName = getName();
|
||||||
|
int number = uniqNumber();
|
||||||
|
QString dir = QString("%1/awesomewidgets/%2")
|
||||||
|
.arg(QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation))
|
||||||
|
.arg(m_type);
|
||||||
|
if (fileName.isEmpty()) {
|
||||||
|
qCWarning(LOG_LIB) << "Nothing to create";
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
||||||
|
|
||||||
|
T *newItem = new T(this, filePath);
|
||||||
|
newItem->setNumber(number);
|
||||||
|
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||||
|
initItems();
|
||||||
|
repaintList();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
void deleteItem();
|
||||||
|
void editItem();
|
||||||
QString getName();
|
QString getName();
|
||||||
|
AbstractExtItem *itemFromWidget();
|
||||||
|
void repaintList();
|
||||||
|
int uniqNumber() const;
|
||||||
// ui
|
// ui
|
||||||
QDialog *dialog = nullptr;
|
QDialog *dialog = nullptr;
|
||||||
QListWidget *widgetDialog = nullptr;
|
QListWidget *widgetDialog = nullptr;
|
||||||
@ -44,6 +77,8 @@ public:
|
|||||||
QPushButton *deleteButton = nullptr;
|
QPushButton *deleteButton = nullptr;
|
||||||
// get methods
|
// get methods
|
||||||
QVariant configArgs() const;
|
QVariant configArgs() const;
|
||||||
|
virtual QList<AbstractExtItem *> items() const = 0;
|
||||||
|
QString type() const;
|
||||||
// set methods
|
// set methods
|
||||||
void setConfigArgs(const QVariant _configArgs);
|
void setConfigArgs(const QVariant _configArgs);
|
||||||
|
|
||||||
@ -53,11 +88,10 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant m_configArgs;
|
QVariant m_configArgs;
|
||||||
// methods
|
QString m_type;
|
||||||
virtual void copyItem() = 0;
|
// ui methods
|
||||||
virtual void createItem() = 0;
|
virtual void doCreateItem() = 0;
|
||||||
virtual void deleteItem() = 0;
|
virtual void initItems() = 0;
|
||||||
virtual void editItem() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,23 +17,16 @@
|
|||||||
|
|
||||||
#include "awabstractformatter.h"
|
#include "awabstractformatter.h"
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
|
||||||
|
|
||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
|
AWAbstractFormatter::AWAbstractFormatter(QWidget *parent,
|
||||||
const QString filePath)
|
const QString filePath)
|
||||||
: QDialog(parent)
|
: AbstractExtItem(parent, filePath)
|
||||||
, m_fileName(filePath)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
qCDebug(LOG_AW) << "Desktop name" << filePath;
|
|
||||||
|
|
||||||
m_name = m_fileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,44 +36,17 @@ AWAbstractFormatter::~AWAbstractFormatter()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractFormatter::copyDefaults(AWAbstractFormatter *_other) const
|
void AWAbstractFormatter::copyDefaults(AbstractExtItem *_other) const
|
||||||
{
|
{
|
||||||
_other->setComment(m_comment);
|
AbstractExtItem::copyDefaults(_other);
|
||||||
_other->setName(m_name);
|
|
||||||
_other->setType(m_type);
|
static_cast<AWAbstractFormatter *>(_other)->setType(m_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString AWAbstractFormatter::writtableConfig() const
|
QString AWAbstractFormatter::uniq() const
|
||||||
{
|
{
|
||||||
QStringList paths = m_fileName.split(QChar('/'));
|
return QString("%1(%2)").arg(name()).arg(m_type);
|
||||||
|
|
||||||
QString name = paths.takeLast();
|
|
||||||
QString dir = paths.takeLast();
|
|
||||||
|
|
||||||
return QString("%1/awesomewidgets/%2/%3")
|
|
||||||
.arg(QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::GenericDataLocation))
|
|
||||||
.arg(dir)
|
|
||||||
.arg(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWAbstractFormatter::comment() const
|
|
||||||
{
|
|
||||||
return m_comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWAbstractFormatter::fileName() const
|
|
||||||
{
|
|
||||||
return m_fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString AWAbstractFormatter::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -90,22 +56,6 @@ QString AWAbstractFormatter::type() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractFormatter::setComment(const QString _comment)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Comment" << _comment;
|
|
||||||
|
|
||||||
m_comment = _comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractFormatter::setName(const QString _name)
|
|
||||||
{
|
|
||||||
qCDebug(LOG_AW) << "Name" << _name;
|
|
||||||
|
|
||||||
m_name = _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractFormatter::setType(const QString _type)
|
void AWAbstractFormatter::setType(const QString _type)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_AW) << "Type" << _type;
|
qCDebug(LOG_AW) << "Type" << _type;
|
||||||
@ -116,34 +66,24 @@ void AWAbstractFormatter::setType(const QString _type)
|
|||||||
|
|
||||||
void AWAbstractFormatter::readConfiguration()
|
void AWAbstractFormatter::readConfiguration()
|
||||||
{
|
{
|
||||||
QSettings settings(m_fileName, QSettings::IniFormat);
|
AbstractExtItem::readConfiguration();
|
||||||
|
|
||||||
|
QSettings settings(fileName(), QSettings::IniFormat);
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
setName(settings.value(QString("Name"), m_name).toString());
|
|
||||||
setComment(settings.value(QString("Comment"), m_comment).toString());
|
|
||||||
setType(settings.value(QString("Type"), m_type).toString());
|
setType(settings.value(QString("Type"), m_type).toString());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AWAbstractFormatter::tryDelete() const
|
|
||||||
{
|
|
||||||
bool status = QFile::remove(m_fileName);
|
|
||||||
qCInfo(LOG_AW) << "Remove file" << m_fileName << status;
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AWAbstractFormatter::writeConfiguration() const
|
void AWAbstractFormatter::writeConfiguration() const
|
||||||
{
|
{
|
||||||
|
AbstractExtItem::writeConfiguration();
|
||||||
|
|
||||||
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
QSettings settings(writtableConfig(), QSettings::IniFormat);
|
||||||
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
qCInfo(LOG_AW) << "Configuration file" << settings.fileName();
|
||||||
|
|
||||||
settings.beginGroup(QString("Desktop Entry"));
|
settings.beginGroup(QString("Desktop Entry"));
|
||||||
settings.setValue(QString("Encoding"), QString("UTF-8"));
|
|
||||||
settings.setValue(QString("Name"), m_name);
|
|
||||||
settings.setValue(QString("Comment"), m_comment);
|
|
||||||
settings.setValue(QString("Type"), m_type);
|
settings.setValue(QString("Type"), m_type);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
@ -18,47 +18,32 @@
|
|||||||
#ifndef AWABSTRACTFORMATTER_H
|
#ifndef AWABSTRACTFORMATTER_H
|
||||||
#define AWABSTRACTFORMATTER_H
|
#define AWABSTRACTFORMATTER_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include "abstractextitem.h"
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
|
|
||||||
class AWAbstractFormatter : public QDialog
|
class AWAbstractFormatter : public AbstractExtItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString comment READ comment WRITE setComment)
|
|
||||||
Q_PROPERTY(QString fileName READ fileName)
|
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
|
||||||
Q_PROPERTY(QString type READ type WRITE setType)
|
Q_PROPERTY(QString type READ type WRITE setType)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AWAbstractFormatter(QWidget *parent = nullptr,
|
explicit AWAbstractFormatter(QWidget *parent = nullptr,
|
||||||
const QString filePath = QString());
|
const QString filePath = QString());
|
||||||
virtual ~AWAbstractFormatter();
|
virtual ~AWAbstractFormatter();
|
||||||
virtual AWAbstractFormatter *copy(const QString _fileName) = 0;
|
void copyDefaults(AbstractExtItem *_other) const;
|
||||||
void copyDefaults(AWAbstractFormatter *_other) const;
|
|
||||||
virtual QString convert(const QVariant &_value) const = 0;
|
virtual QString convert(const QVariant &_value) const = 0;
|
||||||
QString writtableConfig() const;
|
QString uniq() const;
|
||||||
// properties
|
// properties
|
||||||
QString comment() const;
|
|
||||||
QString fileName() const;
|
|
||||||
QString name() const;
|
|
||||||
QString type() const;
|
QString type() const;
|
||||||
void setComment(const QString _comment = QString("empty"));
|
|
||||||
void setName(const QString _name = QString("none"));
|
|
||||||
void setType(const QString _type = QString("NoFormat"));
|
void setType(const QString _type = QString("NoFormat"));
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void readConfiguration();
|
virtual void readConfiguration();
|
||||||
virtual int showConfiguration(const QVariant args = QVariant()) = 0;
|
QVariantHash run() { return QVariantHash(); };
|
||||||
bool tryDelete() const;
|
|
||||||
virtual void writeConfiguration() const;
|
virtual void writeConfiguration() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_fileName;
|
|
||||||
virtual void translate() = 0;
|
|
||||||
// properties
|
// properties
|
||||||
QString m_comment = QString("empty");
|
|
||||||
QString m_name = QString("none");
|
|
||||||
QString m_type = QString("NoFormat");
|
QString m_type = QString("NoFormat");
|
||||||
};
|
};
|
||||||
|
|
@ -70,14 +70,16 @@ QString AWDateTimeFormatter::convert(const QVariant &_value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName)
|
AWDateTimeFormatter *AWDateTimeFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
AWDateTimeFormatter *item
|
AWDateTimeFormatter *item
|
||||||
= new AWDateTimeFormatter(static_cast<QWidget *>(parent()), _fileName);
|
= new AWDateTimeFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
item->setFormat(format());
|
item->setFormat(format());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ public:
|
|||||||
explicit AWDateTimeFormatter(const QString format, QWidget *parent);
|
explicit AWDateTimeFormatter(const QString format, QWidget *parent);
|
||||||
virtual ~AWDateTimeFormatter();
|
virtual ~AWDateTimeFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWDateTimeFormatter *copy(const QString _fileName);
|
AWDateTimeFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
QString format() const;
|
QString format() const;
|
||||||
void setFormat(const QString _format);
|
void setFormat(const QString _format);
|
@ -77,17 +77,19 @@ QString AWFloatFormatter::convert(const QVariant &_value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName)
|
AWFloatFormatter *AWFloatFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
AWFloatFormatter *item
|
AWFloatFormatter *item
|
||||||
= new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
= new AWFloatFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
item->setCount(count());
|
item->setCount(count());
|
||||||
item->setFormat(format());
|
item->setFormat(format());
|
||||||
item->setFillChar(fillChar());
|
item->setFillChar(fillChar());
|
||||||
item->setMultiplier(multiplier());
|
item->setMultiplier(multiplier());
|
||||||
|
item->setNumber(_number);
|
||||||
item->setPrecision(precision());
|
item->setPrecision(precision());
|
||||||
item->setSummand(summand());
|
item->setSummand(summand());
|
||||||
|
|
@ -44,7 +44,7 @@ public:
|
|||||||
QWidget *parent);
|
QWidget *parent);
|
||||||
virtual ~AWFloatFormatter();
|
virtual ~AWFloatFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWFloatFormatter *copy(const QString _fileName);
|
AWFloatFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
int count() const;
|
int count() const;
|
||||||
QChar fillChar() const;
|
QChar fillChar() const;
|
@ -63,13 +63,14 @@ QString AWNoFormatter::convert(const QVariant &_value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWNoFormatter *AWNoFormatter::copy(const QString _fileName)
|
AWNoFormatter *AWNoFormatter::copy(const QString _fileName, const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
AWNoFormatter *item
|
AWNoFormatter *item
|
||||||
= new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
= new AWNoFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ public:
|
|||||||
explicit AWNoFormatter(QWidget *parent);
|
explicit AWNoFormatter(QWidget *parent);
|
||||||
virtual ~AWNoFormatter();
|
virtual ~AWNoFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWNoFormatter *copy(const QString _fileName);
|
AWNoFormatter *copy(const QString _fileName, const int _number);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int showConfiguration(const QVariant args = QVariant());
|
int showConfiguration(const QVariant args = QVariant());
|
@ -86,16 +86,18 @@ QString AWScriptFormatter::convert(const QVariant &_value) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName)
|
AWScriptFormatter *AWScriptFormatter::copy(const QString _fileName,
|
||||||
|
const int _number)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "File" << _fileName;
|
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||||
|
|
||||||
AWScriptFormatter *item
|
AWScriptFormatter *item
|
||||||
= new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
= new AWScriptFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||||
copyDefaults(item);
|
AWAbstractFormatter::copyDefaults(item);
|
||||||
item->setAppendCode(appendCode());
|
item->setAppendCode(appendCode());
|
||||||
item->setCode(code());
|
item->setCode(code());
|
||||||
item->setHasReturn(hasReturn());
|
item->setHasReturn(hasReturn());
|
||||||
|
item->setNumber(_number);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ public:
|
|||||||
const bool hasReturn, QWidget *parent);
|
const bool hasReturn, QWidget *parent);
|
||||||
virtual ~AWScriptFormatter();
|
virtual ~AWScriptFormatter();
|
||||||
QString convert(const QVariant &_value) const;
|
QString convert(const QVariant &_value) const;
|
||||||
AWScriptFormatter *copy(const QString _fileName);
|
AWScriptFormatter *copy(const QString _fileName, const int _number);
|
||||||
// properties
|
// properties
|
||||||
bool appendCode() const;
|
bool appendCode() const;
|
||||||
QString code() const;
|
QString code() const;
|
@ -32,8 +32,7 @@ template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
explicit ExtItemAggregator(QWidget *parent, const QString type)
|
||||||
: AbstractExtItemAggregator(parent)
|
: AbstractExtItemAggregator(parent, type)
|
||||||
, m_type(type)
|
|
||||||
{
|
{
|
||||||
qSetMessagePattern(LOG_FORMAT);
|
qSetMessagePattern(LOG_FORMAT);
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
@ -70,7 +69,7 @@ public:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->tag(_type) != _tag)
|
if (item->tag(_type) != _tag)
|
||||||
continue;
|
continue;
|
||||||
found = item;
|
found = static_cast<T *>(item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found == nullptr)
|
if (found == nullptr)
|
||||||
@ -87,7 +86,7 @@ public:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (item->number() != _number)
|
if (item->number() != _number)
|
||||||
continue;
|
continue;
|
||||||
found = item;
|
found = static_cast<T *>(item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (found == nullptr)
|
if (found == nullptr)
|
||||||
@ -96,63 +95,31 @@ public:
|
|||||||
return found;
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
T *itemFromWidget() const
|
QList<AbstractExtItem *> items() const { return m_items; };
|
||||||
{
|
|
||||||
QListWidgetItem *widgetItem = widgetDialog->currentItem();
|
|
||||||
if (widgetItem == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
T *found = nullptr;
|
|
||||||
for (auto item : m_items) {
|
|
||||||
QString fileName = QFileInfo(item->fileName()).fileName();
|
|
||||||
if (fileName != widgetItem->text())
|
|
||||||
continue;
|
|
||||||
found = item;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (found == nullptr)
|
|
||||||
qCWarning(LOG_LIB) << "Could not find item by name"
|
|
||||||
<< widgetItem->text();
|
|
||||||
|
|
||||||
return found;
|
|
||||||
};
|
|
||||||
|
|
||||||
QList<T *> items() const { return m_items; };
|
|
||||||
|
|
||||||
int uniqNumber() const
|
|
||||||
{
|
|
||||||
QList<int> tagList;
|
|
||||||
for (auto item : m_items)
|
|
||||||
tagList.append(item->number());
|
|
||||||
int number = 0;
|
|
||||||
while (tagList.contains(number))
|
|
||||||
number++;
|
|
||||||
|
|
||||||
return number;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<T *> m_items;
|
QList<AbstractExtItem *> m_items;
|
||||||
QList<T *> m_activeItems;
|
QList<T *> m_activeItems;
|
||||||
QString m_type;
|
|
||||||
|
|
||||||
QList<T *> getItems()
|
void doCreateItem() { return createItem<T>(); }
|
||||||
|
|
||||||
|
QList<AbstractExtItem *> getItems()
|
||||||
{
|
{
|
||||||
// create directory at $HOME
|
// create directory at $HOME
|
||||||
QString localDir = QString("%1/awesomewidgets/%2")
|
QString localDir = QString("%1/awesomewidgets/%2")
|
||||||
.arg(QStandardPaths::writableLocation(
|
.arg(QStandardPaths::writableLocation(
|
||||||
QStandardPaths::GenericDataLocation))
|
QStandardPaths::GenericDataLocation))
|
||||||
.arg(m_type);
|
.arg(type());
|
||||||
QDir localDirectory;
|
QDir localDirectory;
|
||||||
if (localDirectory.mkpath(localDir))
|
if (localDirectory.mkpath(localDir))
|
||||||
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
qCInfo(LOG_LIB) << "Created directory" << localDir;
|
||||||
|
|
||||||
QStringList dirs = QStandardPaths::locateAll(
|
QStringList dirs = QStandardPaths::locateAll(
|
||||||
QStandardPaths::GenericDataLocation,
|
QStandardPaths::GenericDataLocation,
|
||||||
QString("awesomewidgets/%1").arg(m_type),
|
QString("awesomewidgets/%1").arg(type()),
|
||||||
QStandardPaths::LocateDirectory);
|
QStandardPaths::LocateDirectory);
|
||||||
QStringList names;
|
QStringList names;
|
||||||
QList<T *> items;
|
QList<AbstractExtItem *> items;
|
||||||
for (auto dir : dirs) {
|
for (auto dir : dirs) {
|
||||||
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
QStringList files = QDir(dir).entryList(QDir::Files, QDir::Name);
|
||||||
for (auto file : files) {
|
for (auto file : files) {
|
||||||
@ -167,9 +134,10 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort items
|
// sort items
|
||||||
std::sort(items.begin(), items.end(), [](const T *lhs, const T *rhs) {
|
std::sort(items.begin(), items.end(),
|
||||||
return lhs->number() < rhs->number();
|
[](const AbstractExtItem *lhs, const AbstractExtItem *rhs) {
|
||||||
});
|
return lhs->number() < rhs->number();
|
||||||
|
});
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,96 +150,7 @@ private:
|
|||||||
for (auto item : m_items) {
|
for (auto item : m_items) {
|
||||||
if (!item->isActive())
|
if (!item->isActive())
|
||||||
continue;
|
continue;
|
||||||
m_activeItems.append(item);
|
m_activeItems.append(static_cast<T *>(item));
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void repaintList()
|
|
||||||
{
|
|
||||||
widgetDialog->clear();
|
|
||||||
for (auto _item : m_items) {
|
|
||||||
QString fileName = QFileInfo(_item->fileName()).fileName();
|
|
||||||
QListWidgetItem *item
|
|
||||||
= new QListWidgetItem(fileName, widgetDialog);
|
|
||||||
QStringList tooltip;
|
|
||||||
tooltip.append(i18n("Name: %1", _item->name()));
|
|
||||||
tooltip.append(i18n("Comment: %1", _item->comment()));
|
|
||||||
tooltip.append(i18n("Identity: %1", _item->uniq()));
|
|
||||||
item->setToolTip(tooltip.join(QChar('\n')));
|
|
||||||
widgetDialog->addItem(item);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// methods
|
|
||||||
void copyItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
QString fileName = getName();
|
|
||||||
int number = uniqNumber();
|
|
||||||
QString dir = QString("%1/awesomewidgets/%2")
|
|
||||||
.arg(QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::GenericDataLocation))
|
|
||||||
.arg(m_type);
|
|
||||||
if ((source == nullptr) || (fileName.isEmpty())) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to copy";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
|
||||||
|
|
||||||
T *newItem = static_cast<T *>(source->copy(filePath, number));
|
|
||||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaintList();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void createItem()
|
|
||||||
{
|
|
||||||
QString fileName = getName();
|
|
||||||
int number = uniqNumber();
|
|
||||||
QString dir = QString("%1/awesomewidgets/%2")
|
|
||||||
.arg(QStandardPaths::writableLocation(
|
|
||||||
QStandardPaths::GenericDataLocation))
|
|
||||||
.arg(m_type);
|
|
||||||
if (fileName.isEmpty()) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to create";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
QString filePath = QString("%1/%2").arg(dir).arg(fileName);
|
|
||||||
|
|
||||||
T *newItem = new T(this, filePath);
|
|
||||||
newItem->setNumber(number);
|
|
||||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaintList();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void deleteItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
if (source == nullptr) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to delete";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (source->tryDelete()) {
|
|
||||||
initItems();
|
|
||||||
repaintList();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void editItem()
|
|
||||||
{
|
|
||||||
T *source = itemFromWidget();
|
|
||||||
if (source == nullptr) {
|
|
||||||
qCWarning(LOG_LIB) << "Nothing to edit";
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (source->showConfiguration(configArgs()) == 1) {
|
|
||||||
initItems();
|
|
||||||
repaintList();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user