Commit 3ec12f71 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent dfe3485a
......@@ -7,23 +7,21 @@
#include <QTest>
#include <QDebug>
#include <QJsonDocument>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSignalSpy>
#include "iconmodel.h"
#include "sortfiltermodel.h"
using namespace CuttleFish;
class IconModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void init()
......@@ -39,9 +37,7 @@ private Q_SLOTS:
delete m_proxyModel;
}
void initTestCase()
{
};
void initTestCase(){};
void testCategoryFilter()
{
......@@ -62,18 +58,13 @@ private Q_SLOTS:
QVERIFY(_alledit >= _editactions);
}
private: // disable from here for testing just the above
private:
QJsonArray m_data;
QJsonArray m_empty;
IconModel* m_iconModel;
SortFilterModel* m_proxyModel;
IconModel *m_iconModel;
SortFilterModel *m_proxyModel;
};
QTEST_MAIN(IconModelTest)
......
......@@ -21,13 +21,12 @@ ColorSchemes::ColorSchemes(QObject *parent)
{
}
QAbstractItemModel* CuttleFish::ColorSchemes::colorSchemes()
QAbstractItemModel *CuttleFish::ColorSchemes::colorSchemes()
{
return m_colorManager->model();
}
void ColorSchemes::activateColorScheme(const QString& name)
void ColorSchemes::activateColorScheme(const QString &name)
{
m_colorManager->activateScheme(m_colorManager->indexForScheme(name));
}
......@@ -14,22 +14,23 @@ class QAbstractItemModel;
class KColorSchemeManager;
namespace CuttleFish {
class ColorSchemes : public QObject {
namespace CuttleFish
{
class ColorSchemes : public QObject
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *colorSchemes READ colorSchemes CONSTANT)
Q_PROPERTY(QAbstractItemModel *colorSchemes READ colorSchemes CONSTANT)
public:
Q_INVOKABLE void activateColorScheme(const QString &name);
ColorSchemes(QObject *parent);
QAbstractItemModel* colorSchemes();
QAbstractItemModel *colorSchemes();
private:
KColorSchemeManager* m_colorManager;
KColorSchemeManager *m_colorManager;
};
}
#endif
......@@ -17,8 +17,8 @@
K_PLUGIN_FACTORY_WITH_JSON(CuttleFishPluginFactory, "cuttlefishplugin.json", registerPlugin<CuttleFishPlugin>();)
CuttleFishPlugin::CuttleFishPlugin(QObject *parent, const QList<QVariant> &):
KTextEditor::Plugin(parent)
CuttleFishPlugin::CuttleFishPlugin(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent)
{
}
......@@ -29,28 +29,25 @@ CuttleFishPlugin::~CuttleFishPlugin()
QObject *CuttleFishPlugin::createView(KTextEditor::MainWindow *mainWindow)
{
Q_UNUSED(mainWindow);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated,
this, &CuttleFishPlugin::documentCreated);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated, this, &CuttleFishPlugin::documentCreated);
Q_FOREACH (auto doc, KTextEditor::Editor::instance()->application()->documents()) {
documentCreated(doc);
}
return new QObject(this);
}
void CuttleFishPlugin::documentCreated(KTextEditor::Document* document)
void CuttleFishPlugin::documentCreated(KTextEditor::Document *document)
{
connect(document, &KTextEditor::Document::viewCreated,
this, &CuttleFishPlugin::viewCreated);
connect(document, &KTextEditor::Document::viewCreated, this, &CuttleFishPlugin::viewCreated);
}
void CuttleFishPlugin::viewCreated(KTextEditor::Document *document, KTextEditor::View *view)
{
Q_UNUSED(document);
connect(view, &KTextEditor::View::contextMenuAboutToShow,
this, &CuttleFishPlugin::contextMenuAboutToShow);
Q_UNUSED(document);
connect(view, &KTextEditor::View::contextMenuAboutToShow, this, &CuttleFishPlugin::contextMenuAboutToShow);
}
void CuttleFishPlugin::contextMenuAboutToShow(KTextEditor::View* view, QMenu* menu)
void CuttleFishPlugin::contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu)
{
Q_UNUSED(view);
if (m_decorated.contains(menu)) {
......@@ -62,38 +59,30 @@ void CuttleFishPlugin::contextMenuAboutToShow(KTextEditor::View* view, QMenu* me
action->setText(i18n("Insert Icon with Cuttlefish"));
menu->addAction(action);
connect(action, &QAction::triggered,
[this] {
const QString cfexe = QStandardPaths::findExecutable("cuttlefish");
QProcess *cuttlefish = new QProcess(this);
cuttlefish->setProgram(cfexe);
cuttlefish->setArguments(QStringList() << "--picker");
connect(cuttlefish, &QProcess::readyReadStandardOutput,
[ cuttlefish]() {
auto qba = cuttlefish->readAllStandardOutput();
auto view = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
if (view) {
view->document()->insertText(view->cursorPosition(), QString::fromLocal8Bit(qba));
}
cuttlefish->terminate();
}
);
connect(cuttlefish, &QProcess::stateChanged,
[cuttlefish](QProcess::ProcessState newState) {
if (newState == QProcess::NotRunning &&
KTextEditor::Editor::instance()->application()->activeMainWindow()) {
delete cuttlefish;
}
}
);
cuttlefish->start();
}
);
connect(action, &QAction::triggered, [this] {
const QString cfexe = QStandardPaths::findExecutable("cuttlefish");
QProcess *cuttlefish = new QProcess(this);
cuttlefish->setProgram(cfexe);
cuttlefish->setArguments(QStringList() << "--picker");
connect(cuttlefish, &QProcess::readyReadStandardOutput, [cuttlefish]() {
auto qba = cuttlefish->readAllStandardOutput();
auto view = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
if (view) {
view->document()->insertText(view->cursorPosition(), QString::fromLocal8Bit(qba));
}
cuttlefish->terminate();
});
connect(cuttlefish, &QProcess::stateChanged, [cuttlefish](QProcess::ProcessState newState) {
if (newState == QProcess::NotRunning && KTextEditor::Editor::instance()->application()->activeMainWindow()) {
delete cuttlefish;
}
});
cuttlefish->start();
});
}
// required for CuttleFishPluginFactory vtable
......
......@@ -7,9 +7,9 @@
#ifndef CUTTLEFISHPLUGIN_H
#define CUTTLEFISHPLUGIN_H
#include <KTextEditor/Plugin>
#include <KTextEditor/MainWindow>
#include <KTextEditor/Document>
#include <KTextEditor/MainWindow>
#include <KTextEditor/Plugin>
#include <KTextEditor/View>
#include <QList>
......@@ -17,7 +17,6 @@
#include <QProcess>
#include <QVariant>
class CuttleFishPlugin : public KTextEditor::Plugin
{
Q_OBJECT
......@@ -29,13 +28,12 @@ public:
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
private Q_SLOTS:
void contextMenuAboutToShow (KTextEditor::View *view, QMenu *menu);
void contextMenuAboutToShow(KTextEditor::View *view, QMenu *menu);
void documentCreated(KTextEditor::Document *document);
void viewCreated(KTextEditor::Document *document, KTextEditor::View *view);
private:
QList<QMenu*> m_decorated;
QList<QMenu *> m_decorated;
};
#endif // CUTTLEFISHPLUGIN_H
......@@ -6,22 +6,22 @@
#include "iconmodel.h"
#include <QDebug>
#include <QByteArray>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QElapsedTimer>
#include <QFile>
#include <QIcon>
#include <QStandardPaths>
#include <QJsonDocument>
#include <QStandardPaths>
#include <KConfigGroup>
#include <KIconLoader>
#include <KIconTheme>
#include <KSharedConfig>
#include <KPackage/PackageLoader>
#include <KSharedConfig>
#include <algorithm>
#include <cstring>
......@@ -31,8 +31,8 @@ using namespace CuttleFish;
static QTextStream cout(stdout);
IconModel::IconModel(QObject *parent) :
QAbstractListModel(parent)
IconModel::IconModel(QObject *parent)
: QAbstractListModel(parent)
, m_loading(false)
{
m_roleNames.insert(FileName, "fileName");
......@@ -45,24 +45,23 @@ IconModel::IconModel(QObject *parent) :
m_roleNames.insert(Theme, "iconTheme");
m_roleNames.insert(Type, "type");
m_categories = QStringList() << "all" \
<< "actions"
<< "animations"
<< "apps"
<< "categories"
<< "devices"
<< "emblems"
<< "emotes"
<< "filesystems"
<< "international"
<< "mimetypes"
<< "places"
<< "status";
m_categories = QStringList() << "all"
<< "actions"
<< "animations"
<< "apps"
<< "categories"
<< "devices"
<< "emblems"
<< "emotes"
<< "filesystems"
<< "international"
<< "mimetypes"
<< "places"
<< "status";
load();
}
QHash<int, QByteArray> IconModel::roleNames() const
{
return m_roleNames;
......@@ -122,7 +121,6 @@ void IconModel::add(const QFileInfo &info, const QString &cat)
}
QVariantMap &data = m_data[icon];
if (!m_icons.contains(icon)) {
data["fullPath"] = info.absoluteFilePath();
data["iconName"] = icon;
data["fileName"] = info.fileName();
......@@ -139,12 +137,12 @@ void IconModel::add(const QFileInfo &info, const QString &cat)
QStringList _s = info.path().split('/');
if (_s.count() > 2) {
QString size = _s[_s.count()-2]; // last but one is size, last is category
QString size = _s[_s.count() - 2]; // last but one is size, last is category
if (size.indexOf("x") > 1) {
size = size.split("x")[0];
QStringList sizes = data["sizes"].toStringList();
if (!sizes.contains(size)) {
//qDebug() << "Size added" << sizes << size << data["iconName"];
// qDebug() << "Size added" << sizes << size << data["iconName"];
sizes << size;
data["sizes"] = sizes;
}
......@@ -159,7 +157,7 @@ QStringList IconModel::categories() const
void IconModel::load()
{
//qDebug() << "\n -- Loading (category / filter) : " << m_category << m_filter;
// qDebug() << "\n -- Loading (category / filter) : " << m_category << m_filter;
m_loading = true;
emit loadingChanged();
......@@ -171,7 +169,7 @@ void IconModel::load()
beginResetModel();
m_data.clear();
m_icons.clear();
//sm_categories.clear();
// sm_categories.clear();
QString iconTheme;
if (KIconLoader::global()) {
iconTheme = KIconLoader::global()->theme()->internalName();
......@@ -218,13 +216,13 @@ void IconModel::load()
emit loadingChanged();
}
QString IconModel::categoryFromPath(const QString& path)
QString IconModel::categoryFromPath(const QString &path)
{
QStringList cats;
Q_FOREACH (auto c, m_categories) {
cats << c.toLower();
}
//cats << "actions" << "apps" << "places" << "status";
// cats << "actions" << "apps" << "places" << "status";
const QStringList _p1 = path.split("/icons/");
if (_p1.count() > 1) {
foreach (const QString &cat, cats) {
......@@ -241,17 +239,17 @@ bool IconModel::loading()
return m_loading;
}
void IconModel::output(const QString& text)
void IconModel::output(const QString &text)
{
cout << text.toLocal8Bit();
cout.flush();
}
QVariantList IconModel::inOtherThemes(const QString& name, int iconSize)
QVariantList IconModel::inOtherThemes(const QString &name, int iconSize)
{
QVariantList list;
const QStringList themes = KIconTheme::list();
for (const auto& themeName : themes) {
for (const auto &themeName : themes) {
const KIconTheme theme(themeName);
const QString iconPath = theme.iconPathByName(name, iconSize, KIconLoader::MatchBest);
list.append(QVariantMap({{"themeName", themeName}, {"iconPath", iconPath}}));
......
......@@ -8,15 +8,14 @@
#define CUTTLEFISHICONMODEL_H
#include <QAbstractListModel>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonObject>
#include <QFileInfo>
#include <QVariantMap>
#include <QVariantList>
#include <QVariantMap>
namespace CuttleFish {
namespace CuttleFish
{
class IconModel : public QAbstractListModel
{
Q_OBJECT
......@@ -39,7 +38,7 @@ public:
explicit IconModel(QObject *parent = nullptr);
Q_INVOKABLE QVariantList inOtherThemes(const QString& iconName, int size);
Q_INVOKABLE QVariantList inOtherThemes(const QString &iconName, int size);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override;
......@@ -58,7 +57,6 @@ public:
Q_INVOKABLE void output(const QString &text);
Q_SIGNALS:
void categoriesChanged();
void loadingChanged();
......
......@@ -6,12 +6,12 @@
// Qt
#include <QApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QDebug>
#include <QQmlEngine>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlEngine>
// Frameworks
#include <KConfigGroup>
......@@ -28,9 +28,9 @@
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
if ((msg.contains("qt.svg") && msg.contains("Could not resolve property: #linearGradient")) || msg.contains("Could not resolve property: #pattern")) {
return;
return;
}
QByteArray localMsg = msg.toLocal8Bit();
const char *file = context.file ? context.file : "";
const char *function = context.function ? context.function : "";
......@@ -68,16 +68,13 @@ int main(int argc, char **argv)
app.setApplicationName("Cuttlefish");
const static auto _category = QStringLiteral("category");
QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category,
i18n("Start with category"), i18n("category"));
QCommandLineOption category = QCommandLineOption(QStringList() << QStringLiteral("c") << _category, i18n("Start with category"), i18n("category"));
const static auto _f = QStringLiteral("fullscreen");
QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f,
i18n("Start full-screen"));
QCommandLineOption fullscreen = QCommandLineOption(QStringList() << QStringLiteral("f") << _f, i18n("Start full-screen"));
const static auto _p = QStringLiteral("picker");
QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p,
i18n("Run in icon-picker mode"));
QCommandLineOption picker = QCommandLineOption(QStringList() << QStringLiteral("p") << _p, i18n("Run in icon-picker mode"));
QCommandLineParser parser;
parser.addVersionOption();
......
......@@ -4,25 +4,22 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "iconmodel.h"
#include "sortfiltermodel.h"
#include "iconmodel.h"
using namespace CuttleFish;
SortFilterModel::SortFilterModel(QObject *parent)
: QSortFilterProxyModel(parent)
: QSortFilterProxyModel(parent)
{
setSortRole(IconModel::IconName);
setSortCaseSensitivity(Qt::CaseInsensitive);
}
bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
const QModelIndex sourceIndex = sourceModel()->index(source_row, 0, source_parent);
if (!(m_category.isEmpty() || m_category == QLatin1String("all"))
&& (m_category != sourceIndex.data(IconModel::Category))) {
if (!(m_category.isEmpty() || m_category == QLatin1String("all")) && (m_category != sourceIndex.data(IconModel::Category))) {
return false;
}
if (!m_filter.isEmpty()) {
......@@ -33,7 +30,7 @@ bool SortFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source
int SortFilterModel::currentIndex()
{
const QModelIndex index = mapFromSource(m_currentSourceIndex);
const QModelIndex index = mapFromSource(m_currentSourceIndex);
if (index.isValid()) {
return index.row();
}
......@@ -47,7 +44,6 @@ void SortFilterModel::setCurrentIndex(int index)
m_currentSourceIndex = mapToSource(this->index(index, 0));
emit currentIndexChanged();
}
}
QString SortFilterModel::category() const
......@@ -58,7 +54,7 @@ QString SortFilterModel::category() const
void SortFilterModel::setCategory(const QString &category)
{
if (category == m_category) {
return;
return;
}
int oldIndex = currentIndex();
m_category = category;
......@@ -74,7 +70,7 @@ QString SortFilterModel::filter() const
return m_filter;
}
void SortFilterModel::setFilter(const QString& filter)
void SortFilterModel::setFilter(const QString &filter)
{
if (filter == m_filter) {
return;
......@@ -87,5 +83,3 @@ void SortFilterModel::setFilter(const QString& filter)
emit currentIndexChanged();
}
}
......@@ -6,9 +6,10 @@
#include <QSortFilterProxyModel>
namespace CuttleFish {
class SortFilterModel : public QSortFilterProxyModel {
namespace CuttleFish
{
class SortFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
Q_PROPERTY(QString category READ category WRITE setCategory NOTIFY categoryChanged)
......@@ -30,7 +31,7 @@ Q_SIGNALS:
void categoryChanged();
void currentIndexChanged();
private:
private:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
QString m_category;
......
......@@ -7,18 +7,17 @@
#include "engineexplorer.h"
#include <QApplication>
#include <QStandardItemModel>
#include <QBitmap>
#include <QBitArray>
#include <QBitmap>
#include <QDialogButtonBox>
#include <QMenu>
#include <QStandardItemModel>
#include <QUrl>
#include <KStandardAction>
#include <KStringHandler>
#include <KPluginMetaData>
#include <KLocalizedString>
#include <KPluginMetaData>
#include <KStandardAction>
#include <KStringHandler>
#include <QAction>
#include <QDateTime>
......@@ -30,16 +29,16 @@ Q_DECLARE_METATYPE(Plasma::DataEngine::Data)
#include "serviceviewer.h"
#include "titlecombobox.h"
EngineExplorer::EngineExplorer(QWidget* parent)
: QDialog(parent),
m_engine(nullptr),
m_sourceCount(0),
m_requestingSource(false),
m_expandButton(new QPushButton(i18n("Expand All"), this)),
m_collapseButton(new QPushButton(i18n("Collapse All"), this))
EngineExplorer::EngineExplorer(QWidget *parent)
: QDialog(parent)
, m_engine(nullptr)
, m_sourceCount(0)
, m_requestingSource(false)
, m_expandButton(new QPushButton(i18n("Expand All"), this))
, m_collapseButton(new QPushButton(i18n("Collapse All"), this))
{
setWindowTitle(i18n("Plasma Engine Explorer"));