mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-21 17:49:57 +00:00
initial plasma6 support
This commit is contained in:
@ -15,7 +15,6 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "awjsonformatter.h"
|
||||
#include "ui_awjsonformatter.h"
|
||||
|
||||
@ -27,24 +26,13 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWJsonFormatter::AWJsonFormatter(QWidget *_parent, const QString &_filePath)
|
||||
AWJsonFormatter::AWJsonFormatter(QObject *_parent, const QString &_filePath)
|
||||
: AWAbstractFormatter(_parent, _filePath)
|
||||
, ui(new Ui::AWJsonFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!_filePath.isEmpty())
|
||||
AWJsonFormatter::readConfiguration();
|
||||
ui->setupUi(this);
|
||||
AWJsonFormatter::translate();
|
||||
}
|
||||
|
||||
|
||||
AWJsonFormatter::~AWJsonFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
@ -53,8 +41,8 @@ QString AWJsonFormatter::convert(const QVariant &_value) const
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
// check if _value is string and parse first if required
|
||||
QJsonDocument json = _value.type() == QVariant::String ? QJsonDocument::fromJson(_value.toString().toUtf8())
|
||||
: QJsonDocument::fromVariant(_value);
|
||||
QJsonDocument json = _value.userType() == QMetaType::QString ? QJsonDocument::fromJson(_value.toString().toUtf8())
|
||||
: QJsonDocument::fromVariant(_value);
|
||||
QVariant converted = json.toVariant();
|
||||
for (auto &element : m_splittedPath)
|
||||
converted = getFromJson(converted, element);
|
||||
@ -67,7 +55,7 @@ AWJsonFormatter *AWJsonFormatter::copy(const QString &_fileName, const int _numb
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
auto *item = new AWJsonFormatter(dynamic_cast<QWidget *>(parent()), _fileName);
|
||||
auto item = new AWJsonFormatter(parent(), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setPath(path());
|
||||
@ -105,25 +93,34 @@ void AWJsonFormatter::readConfiguration()
|
||||
}
|
||||
|
||||
|
||||
int AWJsonFormatter::showConfiguration(const QVariant &args)
|
||||
int AWJsonFormatter::showConfiguration(QWidget *_parent, const QVariant &args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
auto dialog = new QDialog(_parent);
|
||||
auto ui = new Ui::AWJsonFormatter();
|
||||
ui->setupUi(dialog);
|
||||
translate(ui);
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText("Json");
|
||||
ui->lineEdit_path->setText(path());
|
||||
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setPath(ui->lineEdit_path->text());
|
||||
auto ret = dialog->exec();
|
||||
if (ret == 1) {
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AW_FORMATTER_API);
|
||||
setStrType(ui->label_typeValue->text());
|
||||
setPath(ui->lineEdit_path->text());
|
||||
|
||||
writeConfiguration();
|
||||
}
|
||||
|
||||
dialog->deleteLater();
|
||||
delete ui;
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -147,9 +144,9 @@ QVariant AWJsonFormatter::getFromJson(const QVariant &_value, const QVariant &_e
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Looking for element" << _element << "in" << _value;
|
||||
|
||||
if (_element.type() == QVariant::String) {
|
||||
if (_element.userType() == QMetaType::QString) {
|
||||
return getFromMap(_value, _element.toString());
|
||||
} else if (_element.type() == QVariant::Int) {
|
||||
} else if (_element.userType() == QMetaType::Int) {
|
||||
return getFromList(_value, _element.toInt());
|
||||
} else {
|
||||
qCWarning(LOG_LIB) << "Unknown type" << _element.typeName();
|
||||
@ -187,8 +184,10 @@ void AWJsonFormatter::initPath()
|
||||
}
|
||||
|
||||
|
||||
void AWJsonFormatter::translate()
|
||||
void AWJsonFormatter::translate(void *_ui)
|
||||
{
|
||||
auto ui = reinterpret_cast<Ui::AWJsonFormatter *>(_ui);
|
||||
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
|
Reference in New Issue
Block a user