mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-09 11:55:52 +00:00
add list formatter
This commit is contained in:
155
sources/awesomewidgets/awlistformatter.cpp
Normal file
155
sources/awesomewidgets/awlistformatter.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/***************************************************************************
|
||||
* 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 "awlistformatter.h"
|
||||
#include "ui_awlistformatter.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWListFormatter::AWListFormatter(QWidget *parent, const QString filePath)
|
||||
: AWAbstractFormatter(parent, filePath)
|
||||
, ui(new Ui::AWListFormatter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
if (!filePath.isEmpty())
|
||||
readConfiguration();
|
||||
ui->setupUi(this);
|
||||
translate();
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter::~AWListFormatter()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::convert(const QVariant &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Convert value" << _value;
|
||||
|
||||
QStringList output = _value.toStringList();
|
||||
if (isSorted())
|
||||
output.sort();
|
||||
|
||||
return output.filter(m_regex).join(separator());
|
||||
}
|
||||
|
||||
|
||||
AWListFormatter *AWListFormatter::copy(const QString _fileName,
|
||||
const int _number)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "File" << _fileName << "with number" << _number;
|
||||
|
||||
AWListFormatter *item
|
||||
= new AWListFormatter(static_cast<QWidget *>(parent()), _fileName);
|
||||
AWAbstractFormatter::copyDefaults(item);
|
||||
item->setFilter(filter());
|
||||
item->setSeparator(separator());
|
||||
item->setSorted(isSorted());
|
||||
item->setNumber(_number);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::filter() const
|
||||
{
|
||||
return m_filter;
|
||||
}
|
||||
|
||||
|
||||
bool AWListFormatter::isSorted() const
|
||||
{
|
||||
return m_sorted;
|
||||
}
|
||||
|
||||
|
||||
QString AWListFormatter::separator() const
|
||||
{
|
||||
return m_separator;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setFilter(const QString _filter)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Filter" << _filter;
|
||||
|
||||
m_filter = _filter;
|
||||
m_regex = QRegExp(m_filter);
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setSeparator(const QString _separator)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Separtor" << _separator;
|
||||
|
||||
m_separator = _separator;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::setSorted(const bool _sorted)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Sorting" << _sorted;
|
||||
|
||||
m_sorted = _sorted;
|
||||
}
|
||||
|
||||
|
||||
int AWListFormatter::showConfiguration(const QVariant args)
|
||||
{
|
||||
Q_UNUSED(args)
|
||||
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->label_typeValue->setText(QString("NoFormat"));
|
||||
ui->lineEdit_filter->setText(filter());
|
||||
ui->lineEdit_separator->setText(separator());
|
||||
ui->checkBox_sorted->setCheckState(isSorted() ? 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());
|
||||
setFilter(ui->lineEdit_filter->text());
|
||||
setSeparator(ui->lineEdit_separator->text());
|
||||
setSorted(ui->checkBox_sorted->checkState() == Qt::Checked);
|
||||
|
||||
writeConfiguration();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AWListFormatter::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
ui->label_filter->setText(i18n("Filter"));
|
||||
ui->label_separator->setText(i18n("Separator"));
|
||||
ui->checkBox_sorted->setText(i18n("Sort"));
|
||||
}
|
Reference in New Issue
Block a user