Commit d7d741a0 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 78134c26
......@@ -26,8 +26,9 @@
using namespace Milou;
DragHelper::DragHelper(QObject* parent) : QObject(parent)
, m_dragIconSize(32)
DragHelper::DragHelper(QObject *parent)
: QObject(parent)
, m_dragIconSize(32)
{
}
......@@ -58,9 +59,10 @@ void DragHelper::startDrag(QQuickItem *item, QMimeData *mimeData, const QIcon &i
{
// This allows the caller to return, making sure we don't crash if
// the caller is destroyed mid-drag
// clang-format off
QMetaObject::invokeMethod(this, "doDrag", Qt::QueuedConnection,
Q_ARG(QQuickItem*, item), Q_ARG(QMimeData*, mimeData), Q_ARG(QIcon, icon));
// clang-format on
}
void DragHelper::startDrag(QQuickItem *item, QMimeData *mimeData, const QString &iconName)
......@@ -81,4 +83,3 @@ void DragHelper::doDrag(QQuickItem *item, QMimeData *mimeData, const QIcon &icon
Q_EMIT dropped();
}
......@@ -20,40 +20,40 @@
#ifndef DRAGHELPER_H
#define DRAGHELPER_H
#include <QObject>
#include <QIcon>
#include <QObject>
#include "milou_export.h"
class QQuickItem;
class QMimeData;
namespace Milou {
namespace Milou
{
class MILOU_EXPORT DragHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(int dragIconSize READ dragIconSize WRITE setDragIconSize NOTIFY dragIconSizeChanged)
public:
explicit DragHelper(QObject *parent = nullptr);
~DragHelper() override;
public:
explicit DragHelper(QObject *parent = nullptr);
~DragHelper() override;
int dragIconSize() const;
void setDragIconSize(int size);
int dragIconSize() const;
void setDragIconSize(int size);
Q_INVOKABLE bool isDrag(int oldX, int oldY, int newX, int newY) const;
// TODO KF6 merge the two
Q_INVOKABLE void startDrag(QQuickItem* item, QMimeData *mimeData, const QIcon &icon = QIcon());
Q_INVOKABLE void startDrag(QQuickItem* item, QMimeData *mimeData, const QString &iconName);
Q_INVOKABLE bool isDrag(int oldX, int oldY, int newX, int newY) const;
// TODO KF6 merge the two
Q_INVOKABLE void startDrag(QQuickItem *item, QMimeData *mimeData, const QIcon &icon = QIcon());
Q_INVOKABLE void startDrag(QQuickItem *item, QMimeData *mimeData, const QString &iconName);
Q_SIGNALS:
void dragIconSizeChanged();
void dropped();
Q_SIGNALS:
void dragIconSizeChanged();
void dropped();
private:
int m_dragIconSize;
Q_INVOKABLE void doDrag(QQuickItem* item, QMimeData *mimeData, const QIcon &icon = QIcon());
private:
int m_dragIconSize;
Q_INVOKABLE void doDrag(QQuickItem *item, QMimeData *mimeData, const QIcon &icon = QIcon());
};
}
......
......@@ -25,7 +25,7 @@
using namespace Milou;
MouseHelper::MouseHelper(QObject* parent)
MouseHelper::MouseHelper(QObject *parent)
: QObject(parent)
{
}
......
......@@ -27,14 +27,14 @@
#include "milou_export.h"
namespace Milou {
namespace Milou
{
class MILOU_EXPORT MouseHelper : public QObject
{
Q_OBJECT
public:
explicit MouseHelper(QObject* parent = nullptr);
explicit MouseHelper(QObject *parent = nullptr);
~MouseHelper() override;
Q_INVOKABLE QPointF globalMousePosition() const;
......
......@@ -33,21 +33,21 @@
using namespace Milou;
Preview::Preview(QQuickItem* parent)
Preview::Preview(QQuickItem *parent)
: QQuickItem(parent)
, m_loaded(false)
, m_declarativeItem(nullptr)
, m_filePlugin(nullptr)
{
//setFlag(QGraphicsItem::ItemHasNoContents, false);
// setFlag(QGraphicsItem::ItemHasNoContents, false);
m_plugins = allPlugins();
for (PreviewPlugin* plugin : qAsConst(m_plugins)) {
connect(plugin, &PreviewPlugin::previewGenerated,
this, &Preview::slotPreviewGenerated);
for (PreviewPlugin *plugin : qAsConst(m_plugins)) {
connect(plugin, &PreviewPlugin::previewGenerated, this, &Preview::slotPreviewGenerated);
if (plugin->mimetypes().contains(QStringLiteral("file")))
if (plugin->mimetypes().contains(QStringLiteral("file"))) {
m_filePlugin = plugin;
}
}
// When the object is created, it doesn't have a QQmlContext
......@@ -56,8 +56,8 @@ Preview::Preview(QQuickItem* parent)
void Preview::setPluginContexts()
{
QQmlContext* context = qmlContext(parentItem());
for (PreviewPlugin* plugin : qAsConst(m_plugins)) {
QQmlContext *context = qmlContext(parentItem());
for (PreviewPlugin *plugin : qAsConst(m_plugins)) {
plugin->setContext(context);
}
}
......@@ -69,8 +69,9 @@ Preview::~Preview()
void Preview::refresh()
{
if (m_oldUrl == m_url && m_oldMimetype == m_mimetype) {
if (m_declarativeItem)
if (m_declarativeItem) {
Q_EMIT loadingFinished();
}
return;
}
......@@ -78,7 +79,7 @@ void Preview::refresh()
bool foundPlugin = false;
QUrl url = QUrl::fromLocalFile(m_url);
for (PreviewPlugin* plugin : qAsConst(m_plugins)) {
for (PreviewPlugin *plugin : qAsConst(m_plugins)) {
const QStringList mimeTypes = plugin->mimetypes();
for (const QString &mime : mimeTypes) {
if (m_mimetype.startsWith(mime)) {
......@@ -101,7 +102,7 @@ void Preview::refresh()
}
}
void Preview::slotPreviewGenerated(QQuickItem* item)
void Preview::slotPreviewGenerated(QQuickItem *item)
{
clear();
......@@ -128,7 +129,7 @@ QString Preview::mimetype() const
return m_mimetype;
}
void Preview::setMimetype(const QString& mime)
void Preview::setMimetype(const QString &mime)
{
if (m_mimetype != mime) {
m_oldMimetype = m_mimetype;
......@@ -136,7 +137,7 @@ void Preview::setMimetype(const QString& mime)
}
}
void Preview::setUrl(const QString& url)
void Preview::setUrl(const QString &url)
{
if (m_url != url) {
m_oldUrl = m_url;
......@@ -149,7 +150,7 @@ QString Preview::url() const
return m_url;
}
void Preview::setHighlight(const QString& highlight)
void Preview::setHighlight(const QString &highlight)
{
m_highlight = highlight;
}
......@@ -159,18 +160,18 @@ QString Preview::highlight() const
return m_highlight;
}
QList<PreviewPlugin*> Preview::allPlugins()
QList<PreviewPlugin *> Preview::allPlugins()
{
KService::List serviceList = KServiceTypeTrader::self()->query(QStringLiteral("MilouPreviewPlugin"));
QList<PreviewPlugin*> plugins;
QList<PreviewPlugin *> plugins;
KService::List::const_iterator it;
for (it = serviceList.constBegin(); it != serviceList.constEnd(); it++) {
KService::Ptr service = *it;
QString error;
PreviewPlugin* p = service->createInstance<PreviewPlugin>(this, QVariantList(), &error);
if(!p) {
PreviewPlugin *p = service->createInstance<PreviewPlugin>(this, QVariantList(), &error);
if (!p) {
qWarning() << "Could not create PreviewPlugin:" << service->library();
qWarning() << error;
continue;
......
......@@ -23,11 +23,11 @@
#ifndef PREVIEW_H
#define PREVIEW_H
#include <QQuickItem>
#include "milou_export.h"
#include <QQuickItem>
namespace Milou {
namespace Milou
{
class PreviewPlugin;
class MILOU_EXPORT Preview : public QQuickItem
......@@ -39,19 +39,22 @@ class MILOU_EXPORT Preview : public QQuickItem
Q_PROPERTY(bool loaded READ loaded)
public:
explicit Preview(QQuickItem* parent = nullptr);
explicit Preview(QQuickItem *parent = nullptr);
~Preview() override;
QString mimetype() const;
void setMimetype(const QString& mime);
void setMimetype(const QString &mime);
QString url() const;
void setUrl(const QString& url);
void setUrl(const QString &url);
QString highlight() const;
void setHighlight(const QString& highlight);
void setHighlight(const QString &highlight);
bool loaded() const { return m_loaded; }
bool loaded() const
{
return m_loaded;
}
Q_SIGNALS:
void loadingFinished();
......@@ -61,7 +64,7 @@ public Q_SLOTS:
void clear();
private Q_SLOTS:
void slotPreviewGenerated(QQuickItem* item);
void slotPreviewGenerated(QQuickItem *item);
void setPluginContexts();
......@@ -74,11 +77,11 @@ private:
QString m_oldMimetype;
QString m_oldUrl;
QQuickItem* m_declarativeItem;
QQuickItem *m_declarativeItem;
QList<Milou::PreviewPlugin*> m_plugins;
QList<Milou::PreviewPlugin*> allPlugins();
PreviewPlugin* m_filePlugin;
QList<Milou::PreviewPlugin *> m_plugins;
QList<Milou::PreviewPlugin *> allPlugins();
PreviewPlugin *m_filePlugin;
};
}
......
......@@ -26,18 +26,17 @@
using namespace Milou;
PreviewPlugin::PreviewPlugin(QObject* parent)
PreviewPlugin::PreviewPlugin(QObject *parent)
: QObject(parent)
, m_context(nullptr)
{
}
PreviewPlugin::~PreviewPlugin()
{
}
void PreviewPlugin::setUrl(const QUrl& url)
void PreviewPlugin::setUrl(const QUrl &url)
{
m_url = url;
}
......@@ -47,7 +46,7 @@ QUrl PreviewPlugin::url() const
return m_url;
}
void PreviewPlugin::setMimetype(const QString& mimetype)
void PreviewPlugin::setMimetype(const QString &mimetype)
{
m_mimetype = mimetype;
}
......@@ -57,7 +56,7 @@ QString PreviewPlugin::mimetype() const
return m_mimetype;
}
void PreviewPlugin::setHighlight(const QString& term)
void PreviewPlugin::setHighlight(const QString &term)
{
m_highlight = term;
}
......@@ -67,26 +66,27 @@ QString PreviewPlugin::highlight() const
return m_highlight;
}
void PreviewPlugin::setContext(QQmlContext* context)
void PreviewPlugin::setContext(QQmlContext *context)
{
m_context = context;
}
QQmlContext* PreviewPlugin::context()
QQmlContext *PreviewPlugin::context()
{
Q_ASSERT(m_context);
return m_context;
}
void PreviewPlugin::highlight(const QTextDocument* doc) const
void PreviewPlugin::highlight(const QTextDocument *doc) const
{
QTextCursor cursor;
const QStringList highlights = highlight().split(QLatin1Char(' '), Qt::SkipEmptyParts);
for (const QString &text : highlights) {
while (1) {
cursor = doc->find(text, cursor);
if (cursor.isNull())
if (cursor.isNull()) {
break;
}
QString selection = cursor.selectedText();
......
......@@ -23,19 +23,19 @@
#ifndef MILOU_PREVIEWPLUGIN_H
#define MILOU_PREVIEWPLUGIN_H
#include "milou_export.h"
#include <KService>
#include <QQuickItem>
#include "milou_export.h"
#include <QTextDocument>
namespace Milou {
namespace Milou
{
class MILOU_EXPORT PreviewPlugin : public QObject
{
Q_OBJECT
public:
explicit PreviewPlugin(QObject* parent);
explicit PreviewPlugin(QObject *parent);
~PreviewPlugin() override;
/**
......@@ -57,42 +57,43 @@ public:
* Retrieve the context, this allows you to create
* your own preview plugins in QML
*/
QQmlContext* context();
QQmlContext *context();
void setContext(QQmlContext* context);
void setContext(QQmlContext *context);
/**
* The url of the preview being generated
*/
QUrl url() const;
void setUrl(const QUrl& url);
void setUrl(const QUrl &url);
/**
* The mimetype of the url for whcih the preview
* should be generated
*/
QString mimetype() const;
void setMimetype(const QString& mimetype);
void setMimetype(const QString &mimetype);
/**
* A term that should be highlighted in the preview
* that is generated
*/
QString highlight() const;
void setHighlight(const QString& term);
void setHighlight(const QString &term);
Q_SIGNALS:
void previewGenerated(QQuickItem* graphicsItem);
void previewGenerated(QQuickItem *graphicsItem);
protected:
/**
* Highlights all the occurrences of highlight in the document
*/
void highlight(const QTextDocument* doc) const;
void highlight(const QTextDocument *doc) const;
bool onHighDPI() const;
private:
QQmlContext* m_context;
QQmlContext *m_context;
QUrl m_url;
QString m_highlight;
......@@ -107,7 +108,6 @@ private:
* \param classname The name of the subclass to export
* \param libname The name of the library which should export the extractor
*/
#define MILOU_EXPORT_PREVIEW( classname, libname ) \
K_PLUGIN_FACTORY(factory, registerPlugin<classname>();)
#define MILOU_EXPORT_PREVIEW(classname, libname) K_PLUGIN_FACTORY(factory, registerPlugin<classname>();)
#endif // MILOU_PREVIEWPLUGIN_H
......@@ -23,13 +23,13 @@
#include "textplugin.h"
#include <QFile>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQmlContext>
#include <QTextStream>
#include <QQmlEngine>
#include <QStandardPaths>
#include <QTextStream>
TextPlugin::TextPlugin(QObject* parent, const QVariantList&)
TextPlugin::TextPlugin(QObject *parent, const QVariantList &)
: PreviewPlugin(parent)
{
}
......@@ -41,7 +41,8 @@ void TextPlugin::generatePreview()
return;
}
QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/plasmoids/org.kde.milou/contents/ui/previews/TextPreview.qml"));
QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, //
QStringLiteral("plasma/plasmoids/org.kde.milou/contents/ui/previews/TextPreview.qml"));
QQmlComponent component(context()->engine(), path);
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
......@@ -59,4 +60,3 @@ void TextPlugin::generatePreview()
MILOU_EXPORT_PREVIEW(TextPlugin, "miloutextplugin")
#include "textplugin.moc"
......@@ -29,9 +29,10 @@ class TextPlugin : public Milou::PreviewPlugin
{
Q_OBJECT
public:
explicit TextPlugin(QObject* parent, const QVariantList&);
explicit TextPlugin(QObject *parent, const QVariantList &);
QStringList mimetypes() override {
QStringList mimetypes() override
{
return QStringList() << QLatin1String("text/");
}
void generatePreview() override;
......
......@@ -22,14 +22,14 @@
#include "qmlplugins.h"
#include "sourcesmodel.h"
#include "resultsmodel.h"
#include "preview.h"
#include "draghelper.h"
#include "mousehelper.h"
#include "preview.h"
#include "resultsmodel.h"
#include "sourcesmodel.h"
#include <QQmlEngine>
#include <QMimeData>
#include <QQmlEngine>
void QmlPlugins::initializeEngine(QQmlEngine *, const char *)
{
......@@ -37,14 +37,12 @@ void QmlPlugins::initializeEngine(QQmlEngine *, const char *)
void QmlPlugins::registerTypes(const char *uri)
{
qmlRegisterType<Milou::SourcesModel> (uri, 0, 1, "SourcesModel");
qmlRegisterType<Milou::SourcesModel>(uri, 0, 1, "SourcesModel");
qmlRegisterType<Milou::ResultsModel>(uri, 0, 3, "ResultsModel");
qmlRegisterType<Milou::Preview> (uri, 0, 1, "Preview");
qmlRegisterType<Milou::DragHelper> (uri, 0, 2, "DragHelper");
qmlRegisterSingletonType<Milou::MouseHelper> (uri, 0, 1, "MouseHelper",
[](QQmlEngine*, QJSEngine*) -> QObject* {
qmlRegisterType<Milou::Preview>(uri, 0, 1, "Preview");
qmlRegisterType<Milou::DragHelper>(uri, 0, 2, "DragHelper");
qmlRegisterSingletonType<Milou::MouseHelper>(uri, 0, 1, "MouseHelper", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new Milou::MouseHelper();
});
qmlRegisterAnonymousType<QMimeData>(uri, 0);
}
......@@ -27,8 +27,8 @@
class QmlPlugins : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void initializeEngine(QQmlEngine *engine, const char *uri) override;
void registerTypes(const char *uri) override;
......
......@@ -24,8 +24,8 @@
#include "runnerresultsmodel.h"
#include <QIdentityProxyModel>
#include <KRunner/RunnerManager>
#include <QIdentityProxyModel>
#include <KDescendantsProxyModel>
#include <KModelIndexProxyMapper>
......@@ -45,14 +45,16 @@ class SortProxyModel : public QSortFilterProxyModel
Q_OBJECT
public:
SortProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
SortProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
setDynamicSortFilter(true);
sort(0, Qt::DescendingOrder);
}
~SortProxyModel() override = default;
void setQueryString(const QString &queryString) {
void setQueryString(const QString &queryString)
{
const QStringList words = queryString.split(QLatin1Char(' '), Qt::SkipEmptyParts);
if (m_words != words) {
m_words = words;
......@@ -60,7 +62,8 @@ public:
}
}
bool categoryHasMatchWithAllWords(const QModelIndex &categoryIdx) const {
bool categoryHasMatchWithAllWords(const QModelIndex &categoryIdx) const
{
for (int i = 0; i < sourceModel()->rowCount(categoryIdx); ++i) {
const QModelIndex idx = sourceModel()->index(i, 0, categoryIdx);
const QString display = idx.data(Qt::DisplayRole).toString();
......@@ -129,9 +132,9 @@ class CategoryDistributionProxyModel : public QSortFilterProxyModel
Q_OBJECT
public:
CategoryDistributionProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
CategoryDistributionProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
~CategoryDistributionProxyModel() override = default;
......@@ -150,8 +153,13 @@ public:
}
}
int limit() const { return m_limit; }
void setLimit(int limit) {
int limit() const
{
return m_limit;
}
void setLimit(int limit)
{
if (m_limit == limit) {
return;
}
......@@ -223,16 +231,18 @@ class HideRootLevelProxyModel : public QSortFilterProxyModel
Q_OBJECT
public:
HideRootLevelProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
HideRootLevelProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
~HideRootLevelProxyModel() override = default;
QAbstractItemModel *treeModel() const {
QAbstractItemModel *treeModel() const
{
return m_treeModel;
}
void setTreeModel(QAbstractItemModel *treeModel) {
void setTreeModel(QAbstractItemModel *treeModel)