Skip to content

Commit dbe36f7

Browse files
committed
apply WebKit code style
1 parent 44812b8 commit dbe36f7

10 files changed

+54
-60
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Live Coding Environment for C++, Qt and QML
22
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/machinekoder/cpp-qt-live-coding/blob/master/LICENSE)
3+
[![Code style: WebKit](https://img.shields.io/badge/code%20style-WebKit-blue.svg)](https://webkit.org/code-style-guidelines/)
34

45
This project aims to be the C++ version for Qt/QML live coding.
56

@@ -43,3 +44,4 @@ To use the live coding environment, you need to follow these steps:
4344
3. Disable shadow build and run your application.
4445

4546
Take a look at [example](./example) for an example.
47+
4

lib/cpp_qt_live_coding_plugin.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cpp_qt_live_coding_plugin.h"
2-
#include "livecoding.h"
32
#include "filewatcher.h"
3+
#include "livecoding.h"
44
#include "projectbrowser.h"
55

66
#include <QFile>
@@ -11,16 +11,15 @@ static void initResources()
1111
Q_INIT_RESOURCE(qml);
1212
}
1313

14-
1514
static const struct {
16-
const char *type;
15+
const char* type;
1716
int major, minor;
18-
} qmldir [] = {
17+
} qmldir[] = {
1918
{ "LiveCodingPanel", 1, 0 },
2019
{ "FileSelectionDialog", 1, 0 },
2120
};
2221

23-
void CppQtLiveCodingPlugin::registerTypes(const char *uri)
22+
void CppQtLiveCodingPlugin::registerTypes(const char* uri)
2423
{
2524
initResources();
2625

@@ -30,12 +29,12 @@ void CppQtLiveCodingPlugin::registerTypes(const char *uri)
3029
qmlRegisterSingletonType<LiveCoding>(uri, 1, 0, "LiveCoding", LiveCoding::qmlSingletonProvider);
3130

3231
const QString filesLocation = fileLocation();
33-
for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++) {
32+
for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) {
3433
qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type);
3534
}
3635
}
3736

38-
void CppQtLiveCodingPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
37+
void CppQtLiveCodingPlugin::initializeEngine(QQmlEngine* engine, const char* uri)
3938
{
4039
Q_UNUSED(uri);
4140

lib/cpp_qt_live_coding_plugin.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
#include <QQmlExtensionPlugin>
44

5-
class CppQtLiveCodingPlugin : public QQmlExtensionPlugin
6-
{
5+
class CppQtLiveCodingPlugin : public QQmlExtensionPlugin {
76
Q_OBJECT
87
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
98

109
public:
11-
void registerTypes(const char *uri);
12-
void initializeEngine(QQmlEngine *engine, const char *uri);
10+
void registerTypes(const char* uri);
11+
void initializeEngine(QQmlEngine* engine, const char* uri);
1312

1413
private:
1514
QString fileLocation() const;

lib/filewatcher.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "filewatcher.h"
22
#include <QDebug>
3-
#include <QFile>
43
#include <QDir>
54
#include <QDirIterator>
5+
#include <QFile>
66
#include <QLoggingCategory>
77

88
Q_LOGGING_CATEGORY(filewatcherCategory, "filewatcher");
99

10-
FileWatcher::FileWatcher(QObject *parent)
10+
FileWatcher::FileWatcher(QObject* parent)
1111
: QObject(parent)
1212
, m_fileUrl(QLatin1String(""))
1313
, m_enabled(true)
@@ -41,7 +41,7 @@ QStringList FileWatcher::nameFilters() const
4141
return m_nameFilters;
4242
}
4343

44-
void FileWatcher::setFileUrl(const QUrl &fileUrl)
44+
void FileWatcher::setFileUrl(const QUrl& fileUrl)
4545
{
4646
if (m_fileUrl == fileUrl) {
4747
return;
@@ -71,7 +71,7 @@ void FileWatcher::setRecursive(bool recursive)
7171
emit recursiveChanged(m_recursive);
7272
}
7373

74-
void FileWatcher::setNameFilters(const QStringList &nameFilters)
74+
void FileWatcher::setNameFilters(const QStringList& nameFilters)
7575
{
7676
if (m_nameFilters == nameFilters) {
7777
return;
@@ -86,31 +86,31 @@ void FileWatcher::setNameFilters(const QStringList &nameFilters)
8686
void FileWatcher::updateRegExps()
8787
{
8888
m_regExps.clear();
89-
for (QString &filter: m_nameFilters) {
89+
for (QString& filter : m_nameFilters) {
9090
m_regExps.append(QRegExp(filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
9191
}
9292
}
9393

9494
bool FileWatcher::updateWatchedFile()
9595
{
96-
const auto &files = m_fileSystemWatcher.files();
96+
const auto& files = m_fileSystemWatcher.files();
9797
if (files.length() > 0) {
9898
m_fileSystemWatcher.removePaths(files);
9999
}
100-
const auto &directories = m_fileSystemWatcher.directories();
100+
const auto& directories = m_fileSystemWatcher.directories();
101101
if (directories.length() > 0) {
102102
m_fileSystemWatcher.removePaths(directories);
103103
}
104104

105-
if (!m_fileUrl.isValid() || !m_enabled) {
105+
if (!m_fileUrl.isValid() || !m_enabled) {
106106
return false;
107107
}
108108

109109
if (!m_fileUrl.isLocalFile()) {
110110
qCWarning(filewatcherCategory) << "Can only watch local files";
111111
return false;
112112
}
113-
const auto &localFile = m_fileUrl.toLocalFile();
113+
const auto& localFile = m_fileUrl.toLocalFile();
114114
if (localFile.isEmpty()) {
115115
return false;
116116
}
@@ -122,10 +122,10 @@ bool FileWatcher::updateWatchedFile()
122122

123123
QDirIterator it(localFile, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
124124
while (it.hasNext()) {
125-
const auto &file = it.next();
125+
const auto& file = it.next();
126126
const QString extension = it.fileInfo().completeSuffix();
127127
bool filtered = false;
128-
for (QRegExp &regExp: m_regExps) {
128+
for (QRegExp& regExp : m_regExps) {
129129
if (regExp.exactMatch(extension)) {
130130
filtered = true;
131131
break;
@@ -140,11 +140,9 @@ bool FileWatcher::updateWatchedFile()
140140
}
141141

142142
return newPaths != QSet<QString>::fromList(files).unite(QSet<QString>::fromList(directories));
143-
}
144-
else if (QFile::exists(localFile)) {
143+
} else if (QFile::exists(localFile)) {
145144
m_fileSystemWatcher.addPath(localFile);
146-
}
147-
else {
145+
} else {
148146
#ifdef QT_DEBUG
149147
qCWarning(filewatcherCategory) << "File to watch does not exist" << localFile;
150148
#endif
@@ -159,7 +157,7 @@ void FileWatcher::onWatchedFileChanged()
159157
}
160158
}
161159

162-
void FileWatcher::onWatchedDirectoryChanged(const QString &)
160+
void FileWatcher::onWatchedDirectoryChanged(const QString&)
163161
{
164162
if (updateWatchedFile()) {
165163
onWatchedFileChanged(); // propagate event

lib/filewatcher.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#ifndef FILEWATCHER_H
22
#define FILEWATCHER_H
33

4+
#include <QFileSystemWatcher>
45
#include <QObject>
56
#include <QUrl>
6-
#include <QFileSystemWatcher>
77

8-
class FileWatcher : public QObject
9-
{
8+
class FileWatcher : public QObject {
109
Q_OBJECT
1110
Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
1211
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
1312
Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
1413
Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged)
1514

1615
public:
17-
explicit FileWatcher(QObject *parent = nullptr);
16+
explicit FileWatcher(QObject* parent = nullptr);
1817

1918
QUrl fileUrl() const;
2019
bool enabled() const;
@@ -24,16 +23,16 @@ class FileWatcher : public QObject
2423

2524
signals:
2625
void fileChanged();
27-
void fileUrlChanged(const QUrl &fileUrl);
26+
void fileUrlChanged(const QUrl& fileUrl);
2827
void enabledChanged(bool enabled);
2928
void recursiveChanged(bool recursive);
30-
void nameFiltersChanged(const QStringList &nameFilters);
29+
void nameFiltersChanged(const QStringList& nameFilters);
3130

3231
public slots:
33-
void setFileUrl(const QUrl &fileUrl);
32+
void setFileUrl(const QUrl& fileUrl);
3433
void setEnabled(bool enabled);
3534
void setRecursive(bool recursive);
36-
void setNameFilters(const QStringList &nameFilters);
35+
void setNameFilters(const QStringList& nameFilters);
3736

3837
private:
3938
QUrl m_fileUrl;
@@ -48,7 +47,7 @@ public slots:
4847
private slots:
4948
bool updateWatchedFile();
5049
void onWatchedFileChanged();
51-
void onWatchedDirectoryChanged(const QString &);
50+
void onWatchedDirectoryChanged(const QString&);
5251

5352
}; // class FileWatcher
5453

lib/livecoding.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#include "livecoding.h"
2+
#include <QCoreApplication>
23
#include <QDesktopServices>
34
#include <QLocale>
45
#include <QProcess>
56
#include <QSettings>
6-
#include <QCoreApplication>
77

8-
LiveCoding::LiveCoding(QQmlEngine *engine, QObject *parent)
8+
LiveCoding::LiveCoding(QQmlEngine* engine, QObject* parent)
99
: QObject(parent)
1010
, m_engine(engine)
1111
{
12-
1312
}
1413

15-
bool LiveCoding::openUrlWithDefaultApplication(const QUrl &url) const
14+
bool LiveCoding::openUrlWithDefaultApplication(const QUrl& url) const
1615
{
1716
return QDesktopServices::openUrl(url);
1817
}
@@ -28,7 +27,7 @@ QString LiveCoding::currentLanguage() const
2827
return languages.first();
2928
}
3029

31-
void LiveCoding::setLanguage(const QString &language)
30+
void LiveCoding::setLanguage(const QString& language)
3231
{
3332
QSettings settings;
3433
settings.setValue("language", language);

lib/livecoding.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@
44
#include <QObject>
55
#include <QQmlEngine>
66

7-
class LiveCoding : public QObject
8-
{
7+
class LiveCoding : public QObject {
98
Q_OBJECT
109

1110
Q_PROPERTY(QString currentLanguage READ currentLanguage CONSTANT)
1211

1312
public:
14-
explicit LiveCoding(QQmlEngine *engine, QObject *parent = nullptr);
13+
explicit LiveCoding(QQmlEngine* engine, QObject* parent = nullptr);
1514

16-
static QObject *qmlSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
15+
static QObject* qmlSingletonProvider(QQmlEngine* engine, QJSEngine* scriptEngine)
1716
{
1817
Q_UNUSED(engine)
1918
Q_UNUSED(scriptEngine)
2019

21-
return new LiveCoding(engine);
20+
return new LiveCoding(engine);
2221
}
2322

2423
/**
2524
* Opens an URL with the default application provided by the system.
2625
* E.g. a text file will be opened by the default text editor.
2726
*/
28-
Q_INVOKABLE bool openUrlWithDefaultApplication(const QUrl &url) const;
27+
Q_INVOKABLE bool openUrlWithDefaultApplication(const QUrl& url) const;
2928

3029
/**
3130
* Clear QML component cache of the main QQmlEngine.
@@ -40,15 +39,15 @@ class LiveCoding : public QObject
4039
/**
4140
* Sets the new UI language. Changes take effect after a restart.
4241
*/
43-
Q_INVOKABLE void setLanguage(const QString &language);
42+
Q_INVOKABLE void setLanguage(const QString& language);
4443

4544
/**
4645
* Restarts the application.
4746
*/
4847
Q_INVOKABLE void restartApplication();
4948

5049
private:
51-
QQmlEngine *m_engine;
50+
QQmlEngine* m_engine;
5251

5352
}; // class ApplicationHelpers
5453

lib/livewindow.h

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace LiveWindow {
77

88
QString loadLiveWindow();
9-
109
}
1110

1211
#endif // LIVEWINDOW_H

lib/projectbrowser.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#include "projectbrowser.h"
22

33
#include <QCoreApplication>
4-
#include <QFileInfo>
4+
#include <QDebug>
55
#include <QDir>
66
#include <QDirIterator>
7-
#include <QDebug>
7+
#include <QFileInfo>
88

9-
ProjectBrowser::ProjectBrowser(QObject *parent) : QObject(parent)
9+
ProjectBrowser::ProjectBrowser(QObject* parent)
10+
: QObject(parent)
1011
{
1112
m_projectPath = QUrl::fromLocalFile(QFileInfo(QCoreApplication::applicationFilePath()).dir().path());
1213

@@ -33,7 +34,7 @@ void ProjectBrowser::update()
3334
updateFiles();
3435
}
3536

36-
void ProjectBrowser::setExtensions(const QStringList &extensions)
37+
void ProjectBrowser::setExtensions(const QStringList& extensions)
3738
{
3839
if (m_extensions == extensions)
3940
return;
@@ -45,12 +46,12 @@ void ProjectBrowser::setExtensions(const QStringList &extensions)
4546
void ProjectBrowser::updateFiles()
4647
{
4748
QStringList fileList;
48-
const auto &root = m_projectPath.toLocalFile();
49+
const auto& root = m_projectPath.toLocalFile();
4950

5051
QDirIterator it(root, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
5152
while (it.hasNext()) {
5253
it.next();
53-
const auto &extension = it.fileInfo().completeSuffix();
54+
const auto& extension = it.fileInfo().completeSuffix();
5455
if (m_extensions.contains(extension, Qt::CaseInsensitive)) {
5556
fileList.append(it.fileInfo().filePath());
5657
}

lib/projectbrowser.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
#include <QObject>
55
#include <QUrl>
66

7-
class ProjectBrowser : public QObject
8-
{
7+
class ProjectBrowser : public QObject {
98
Q_OBJECT
109
Q_PROPERTY(QStringList qmlFiles READ qmlFiles NOTIFY qmlFilesChanged)
1110
Q_PROPERTY(QUrl projectPath READ projectPath CONSTANT)
1211
Q_PROPERTY(QStringList extensions READ extensions WRITE setExtensions NOTIFY extensionsChanged)
1312

1413
public:
15-
explicit ProjectBrowser(QObject *parent = nullptr);
14+
explicit ProjectBrowser(QObject* parent = nullptr);
1615

1716
QStringList qmlFiles() const;
1817
QUrl projectPath() const;
@@ -25,7 +24,7 @@ class ProjectBrowser : public QObject
2524
public slots:
2625
void update();
2726

28-
void setExtensions(const QStringList &extensions);
27+
void setExtensions(const QStringList& extensions);
2928

3029
private:
3130
QStringList m_qmlFiles;

0 commit comments

Comments
 (0)