Commit c7f46a91 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Add and make use of clang-format infrastructure

Makes the code consistent with KDE coding style and ensures it stays that way
parent b602ba59
......@@ -20,3 +20,4 @@ random_seed
CMakeLists.txt.user*
*.unc-backup*
.cmake/
.clang-format
......@@ -22,6 +22,8 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(FeatureSummary)
include(KDEClangFormat)
include(KDEGitCommitHooks)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets Svg)
find_package(KF5 ${KF_MIN_VERSION} REQUIRED COMPONENTS CoreAddons Parts I18n)
......@@ -38,3 +40,8 @@ add_subdirectory(src)
ki18n_install(po)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
......@@ -11,8 +11,7 @@
// Qt
#include <QDataStream>
SvgBrowserExtension::SvgBrowserExtension(SvgPart* part)
SvgBrowserExtension::SvgBrowserExtension(SvgPart *part)
: KParts::BrowserExtension(part)
, m_part(part)
{
......@@ -28,13 +27,13 @@ int SvgBrowserExtension::yOffset()
return m_part->verticalScrollPosition();
}
void SvgBrowserExtension::saveState(QDataStream& stream)
void SvgBrowserExtension::saveState(QDataStream &stream)
{
stream << m_part->zoom();
KParts::BrowserExtension::saveState(stream);
}
void SvgBrowserExtension::restoreState(QDataStream& stream)
void SvgBrowserExtension::restoreState(QDataStream &stream)
{
qreal zoom;
stream >> zoom;
......@@ -42,4 +41,3 @@ void SvgBrowserExtension::restoreState(QDataStream& stream)
m_part->setExtendedRestoreArguments(zoom);
KParts::BrowserExtension::restoreState(stream);
}
......@@ -17,16 +17,16 @@ class SvgBrowserExtension : public KParts::BrowserExtension
Q_OBJECT
public:
explicit SvgBrowserExtension(SvgPart* part);
explicit SvgBrowserExtension(SvgPart *part);
int xOffset() override;
int yOffset() override;
void saveState(QDataStream& stream) override;
void restoreState(QDataStream& stream) override;
void saveState(QDataStream &stream) override;
void restoreState(QDataStream &stream) override;
private:
SvgPart* m_part;
SvgPart *m_part;
};
#endif
......@@ -8,29 +8,26 @@
#include "svgbrowserextension.h"
// KF
#include <KPluginMetaData>
#include <KLocalizedString>
#include <KActionCollection>
#include <KStandardAction>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginMetaData>
#include <KStandardAction>
// Qt
#include <QGraphicsScene>
#include <QGraphicsSvgItem>
#include <QGraphicsView>
#include <QSvgRenderer>
#include <QTransform>
#include <QMimeDatabase>
#include <QScrollBar>
#include <QSvgRenderer>
#include <QTimer>
#include <QTransform>
//Factory Code
K_PLUGIN_FACTORY_WITH_JSON(SvgPartFactory, "svgpart.json",
registerPlugin<SvgPart>();)
// Factory Code
K_PLUGIN_FACTORY_WITH_JSON(SvgPartFactory, "svgpart.json", registerPlugin<SvgPart>();)
SvgPart::SvgPart(QWidget* parentWidget, QObject* parent,
const KPluginMetaData& metaData, const QVariantList&)
SvgPart::SvgPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &)
: KParts::ReadOnlyPart(parent)
, mItem(nullptr)
, m_browserExtension(new SvgBrowserExtension(this))
......@@ -50,8 +47,7 @@ SvgPart::SvgPart(QWidget* parentWidget, QObject* parent,
setXMLFile(QStringLiteral("svgpart.rc"));
}
bool SvgPart::openUrl(const QUrl& url)
bool SvgPart::openUrl(const QUrl &url)
{
mCloseUrlFromOpen = true;
......@@ -62,7 +58,6 @@ bool SvgPart::openUrl(const QUrl& url)
return success;
}
bool SvgPart::openFile()
{
if (!mRenderer->load(localFilePath())) {
......@@ -74,13 +69,11 @@ bool SvgPart::openFile()
return true;
}
bool SvgPart::doOpenStream(const QString& mimeType)
bool SvgPart::doOpenStream(const QString &mimeType)
{
auto mime = QMimeDatabase().mimeTypeForName(mimeType);
if (!mime.inherits(QStringLiteral("image/svg+xml"))
&& !mime.inherits(QStringLiteral("image/svg+xml-compressed"))) {
return false;
if (!mime.inherits(QStringLiteral("image/svg+xml")) && !mime.inherits(QStringLiteral("image/svg+xml-compressed"))) {
return false;
}
mStreamedData.clear();
......@@ -88,14 +81,12 @@ bool SvgPart::doOpenStream(const QString& mimeType)
return true;
}
bool SvgPart::doWriteStream(const QByteArray& data)
bool SvgPart::doWriteStream(const QByteArray &data)
{
mStreamedData.append(data);
return true;
}
bool SvgPart::doCloseStream()
{
// too bad QSvgRenderer supports QXmlStreamReader, but not its incremental parsing
......@@ -111,7 +102,6 @@ bool SvgPart::doCloseStream()
return true;
}
bool SvgPart::closeUrl()
{
// protect against repeated call if already closed
......@@ -128,7 +118,7 @@ bool SvgPart::closeUrl()
mView->resetTransform();
// cannot reset the rect completely, as a null QRectF is ignored
// so at least just a 1 pixel square one
mScene->setSceneRect(QRectF(0,0,1,1));
mScene->setSceneRect(QRectF(0, 0, 1, 1));
delete mItem;
mItem = nullptr;
......@@ -141,7 +131,6 @@ bool SvgPart::closeUrl()
return KParts::ReadOnlyPart::closeUrl();
}
void SvgPart::createViewForDocument()
{
mItem = new QGraphicsSvgItem();
......@@ -192,25 +181,21 @@ void SvgPart::zoomIn()
setZoom(zoom() * 2);
}
void SvgPart::zoomOut()
{
setZoom(zoom() / 2);
}
void SvgPart::zoomActualSize()
{
setZoom(1.0);
}
qreal SvgPart::zoom() const
{
return mView->transform().m11();
}
void SvgPart::setZoom(qreal value)
{
QTransform matrix;
......@@ -223,11 +208,9 @@ int SvgPart::horizontalScrollPosition() const
return mView->horizontalScrollBar()->value();
}
int SvgPart::verticalScrollPosition() const
{
return mView->verticalScrollBar()->value();
}
#include "svgpart.moc"
......@@ -23,9 +23,9 @@ class SvgPart : public KParts::ReadOnlyPart
Q_OBJECT
public:
SvgPart(QWidget* parentWidget, QObject* parent, const KPluginMetaData& metaData, const QVariantList&);
SvgPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &);
bool openUrl(const QUrl& url) override;
bool openUrl(const QUrl &url) override;
bool closeUrl() override;
void setExtendedRestoreArguments(qreal zoom);
......@@ -36,8 +36,8 @@ public:
protected:
bool openFile() override;
bool doOpenStream(const QString& mimeType) override;
bool doWriteStream(const QByteArray& data) override;
bool doOpenStream(const QString &mimeType) override;
bool doWriteStream(const QByteArray &data) override;
bool doCloseStream() override;
private Q_SLOTS:
......@@ -53,12 +53,12 @@ private:
void createViewForDocument();
private:
QGraphicsScene* mScene;
QGraphicsView* mView;
QGraphicsSvgItem* mItem;
QSvgRenderer* mRenderer;
QGraphicsScene *mScene;
QGraphicsView *mView;
QGraphicsSvgItem *mItem;
QSvgRenderer *mRenderer;
SvgBrowserExtension* m_browserExtension;
SvgBrowserExtension *m_browserExtension;
bool mCloseUrlFromOpen = false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment