Skip to content

Commit

Permalink
update clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
朱子楚\zhuzi committed Jun 28, 2024
1 parent 1dc726a commit 8d1ee6f
Show file tree
Hide file tree
Showing 52 changed files with 684 additions and 660 deletions.
4 changes: 2 additions & 2 deletions example/src/AppInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <QGuiApplication>
#include "Version.h"

AppInfo::AppInfo(QObject *parent)
: QObject{parent} {
AppInfo::AppInfo(QObject *parent) : QObject{parent} {
version(APPLICATION_VERSION);
}


[[maybe_unused]] void AppInfo::testCrash() {
auto *crash = reinterpret_cast<volatile int *>(0);
*crash = 0;
Expand Down
9 changes: 4 additions & 5 deletions example/src/AppInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#include "singleton.h"

class AppInfo : public QObject {
Q_OBJECT
Q_PROPERTY_AUTO(QString, version)
Q_OBJECT
Q_PROPERTY_AUTO(QString, version)
private:
explicit AppInfo(QObject *parent = nullptr);

public:
SINGLETON(AppInfo)

[[maybe_unused]] Q_INVOKABLE void testCrash();
SINGLETON(AppInfo)
Q_INVOKABLE [[maybe_unused]] void testCrash();
};
36 changes: 23 additions & 13 deletions example/src/app_dmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@

#pragma comment(lib, "Dbghelp.lib")

static void
miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
typedef HRESULT (WINAPI *MiniDumpWriteDumpPtr)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
static void miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile,
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
typedef HRESULT(WINAPI * MiniDumpWriteDumpPtr)(
HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType,
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
HMODULE module = LoadLibraryW(L"Dbghelp.dll");
if (module) {
MiniDumpWriteDumpPtr mini_dump_write_dump;
mini_dump_write_dump = reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
mini_dump_write_dump =
reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
if (mini_dump_write_dump) {
mini_dump_write_dump(hProcess, ProcessId, hFile, static_cast<MINIDUMP_TYPE>(80), ExceptionParam, nullptr, CallbackParam);
mini_dump_write_dump(hProcess, ProcessId, hFile, static_cast<MINIDUMP_TYPE>(80),
ExceptionParam, nullptr, CallbackParam);
}
}
}

BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PMINIDUMP_CALLBACK_OUTPUT output) {
BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input,
PMINIDUMP_CALLBACK_OUTPUT output) {
if (input == nullptr || output == nullptr)
return FALSE;

Expand All @@ -42,16 +49,17 @@ BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PM
output->ModuleWriteFlags &= ~ModuleWriteModule;
}
ret = TRUE;
}
break;
} break;
default:
break;
}
return ret;
}

void WriteDump(EXCEPTION_POINTERS *exp, const std::wstring &path) {
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, nullptr);
MINIDUMP_EXCEPTION_INFORMATION info;
info.ThreadId = ::GetCurrentThreadId();
info.ExceptionPointers = exp;
Expand All @@ -64,8 +72,10 @@ void WriteDump(EXCEPTION_POINTERS *exp, const std::wstring &path) {
}

LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *exp) {
const QString dumpFileName = QString("%1_%2.dmp").arg("crash", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
const QString dumpDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/dmp";
const QString dumpFileName =
QString("%1_%2.dmp").arg("crash", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
const QString dumpDirPath =
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/dmp";
const QDir dumpDir(dumpDirPath);
if (!dumpDir.exists()) {
dumpDir.mkpath(dumpDirPath);
Expand All @@ -76,4 +86,4 @@ LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *exp) {
arguments << "-crashed=" + dumpFilePath;
QProcess::startDetached(QGuiApplication::applicationFilePath(), arguments);
return EXCEPTION_EXECUTE_HANDLER;
}
}
7 changes: 3 additions & 4 deletions example/src/component/CircularReveal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ CircularReveal::CircularReveal(QQuickItem *parent) : QQuickPaintedItem(parent) {
setVisible(false);
Q_EMIT animationFinished();
});
connect(this, &CircularReveal::radiusChanged, this, [=]() {
update();
});
connect(this, &CircularReveal::radiusChanged, this, [=]() { update(); });
}

void CircularReveal::paint(QPainter *painter) {
Expand All @@ -36,7 +34,8 @@ void CircularReveal::paint(QPainter *painter) {
_anim->setEndValue(radius);
_center = center;
_grabResult = _target->grabToImage(QSize(w, h));
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &CircularReveal::handleGrabResult);
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this,
&CircularReveal::handleGrabResult);
}

void CircularReveal::handleGrabResult() {
Expand Down
13 changes: 4 additions & 9 deletions example/src/component/CircularReveal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
#include "src/stdafx.h"

class CircularReveal : public QQuickPaintedItem {
Q_OBJECT
Q_PROPERTY_AUTO_P(QQuickItem*, target)
Q_PROPERTY_AUTO(int, radius)
Q_OBJECT
Q_PROPERTY_AUTO_P(QQuickItem *, target)
Q_PROPERTY_AUTO(int, radius)
public:
explicit CircularReveal(QQuickItem *parent = nullptr);

void paint(QPainter *painter) override;

[[maybe_unused]] Q_INVOKABLE void start(int w, int h, const QPoint &center, int radius);

Q_INVOKABLE [[maybe_unused]] void start(int w, int h, const QPoint &center, int radius);
Q_SIGNAL void imageChanged();

Q_SIGNAL void animationFinished();

Q_SLOT void handleGrabResult();

private:
Expand Down
5 changes: 2 additions & 3 deletions example/src/component/FileWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
#include "src/stdafx.h"

class FileWatcher : public QObject {
Q_OBJECT
Q_PROPERTY_AUTO(QString, path);
Q_OBJECT
Q_PROPERTY_AUTO(QString, path)
public:
explicit FileWatcher(QObject *parent = nullptr);

Q_SIGNAL void fileChanged();

private:
Expand Down
4 changes: 3 additions & 1 deletion example/src/component/FpsItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ FpsItem::FpsItem() {
});
connect(this, &QQuickItem::windowChanged, this, [this] {
if (window()) {
connect(window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; }, Qt::DirectConnection);
connect(
window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; },
Qt::DirectConnection);
}
});
timer->start(1000);
Expand Down
7 changes: 3 additions & 4 deletions example/src/component/FpsItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
#include "src/stdafx.h"

class FpsItem : public QQuickItem {
Q_OBJECT
Q_PROPERTY_AUTO(int, fps)
Q_OBJECT
Q_PROPERTY_AUTO(int, fps)
public:
FpsItem();

private:
int _frameCount = 0;

};
};
44 changes: 18 additions & 26 deletions example/src/component/OpenGLItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,31 @@
class FBORenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions {
public:
explicit FBORenderer(const OpenGLItem *item);

void render() override;

QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override;

QOpenGLShaderProgram program;
const OpenGLItem *item = nullptr;
};

FBORenderer::FBORenderer(const OpenGLItem *item) {
this->item = item;
initializeOpenGLFunctions();
program.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex,
"attribute highp vec4 vertices;"
"varying highp vec2 coords;"
"void main() {"
" gl_Position = vertices;"
" coords = vertices.xy;"
"}");
program.addCacheableShaderFromSourceCode(QOpenGLShader::Fragment,
"uniform lowp float t;"
"varying highp vec2 coords;"
"void main() {"
" lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
" i = smoothstep(t - 0.8, t + 0.8, i);"
" i = floor(i * 20.) / 20.;"
" gl_FragColor = vec4(coords * .5 + .5, i, i);"
"}");
program.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, "attribute highp vec4 vertices;"
"varying highp vec2 coords;"
"void main() {"
" gl_Position = vertices;"
" coords = vertices.xy;"
"}");
program.addCacheableShaderFromSourceCode(
QOpenGLShader::Fragment,
"uniform lowp float t;"
"varying highp vec2 coords;"
"void main() {"
" lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
" i = smoothstep(t - 0.8, t + 0.8, i);"
" i = floor(i * 20.) / 20.;"
" gl_FragColor = vec4(coords * .5 + .5, i, i);"
"}");

program.bindAttributeLocation("vertices", 0);
program.link();
Expand All @@ -54,16 +51,11 @@ void FBORenderer::render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
program.bind();
program.enableAttributeArray(0);
float values[] = {
-1, -1,
1, -1,
-1, 1,
1, 1
};
float values[] = {-1, -1, 1, -1, -1, 1, 1, 1};
glBindBuffer(GL_ARRAY_BUFFER, 0);
program.setAttributeArray(0, GL_FLOAT, values, 2);
program.setUniformValue("t", (float) item->t());
glViewport(0, 0, qRound(item->width()*pixelRatio), qRound(item->height()*pixelRatio));
glViewport(0, 0, qRound(item->width() * pixelRatio), qRound(item->height() * pixelRatio));
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
Expand Down
12 changes: 4 additions & 8 deletions example/src/component/OpenGLItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
class FBORenderer;

class OpenGLItem : public QQuickFramebufferObject, protected QOpenGLFunctions {
Q_OBJECT
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
public:
explicit OpenGLItem(QQuickItem *parent = nullptr);

[[nodiscard]] QQuickFramebufferObject::Renderer *createRenderer() const override;

void timerEvent(QTimerEvent *) override;

[[nodiscard]] qreal t() const { return m_t; }

[[nodiscard]] qreal t() const {
return m_t;
}
void setT(qreal t);

signals:

void tChanged();

private:
Expand Down
53 changes: 30 additions & 23 deletions example/src/helper/InitializrHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include <QGuiApplication>

[[maybe_unused]] InitializrHelper::InitializrHelper(QObject *parent) : QObject(parent) {

}

InitializrHelper::~InitializrHelper() = default;


bool InitializrHelper::copyDir(const QDir &fromDir, const QDir &toDir, bool coverIfFileExists) {
const QDir &_formDir = fromDir;
QDir _toDir = toDir;
Expand All @@ -17,25 +17,25 @@ bool InitializrHelper::copyDir(const QDir &fromDir, const QDir &toDir, bool cove
return false;
}
QFileInfoList fileInfoList = _formDir.entryInfoList();
foreach(QFileInfo fileInfo, fileInfoList) {
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
continue;
if (fileInfo.isDir()) {
if (!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()), true))
return false;
} else {
if (coverIfFileExists && _toDir.exists(fileInfo.fileName())) {
_toDir.remove(fileInfo.fileName());
}
if (!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()))) {
return false;
}
foreach (QFileInfo fileInfo, fileInfoList) {
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
continue;
if (fileInfo.isDir()) {
if (!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()), true))
return false;
} else {
if (coverIfFileExists && _toDir.exists(fileInfo.fileName())) {
_toDir.remove(fileInfo.fileName());
}
if (!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()))) {
return false;
}
}
}
return true;
}

template<typename...Args>
template <typename... Args>
void InitializrHelper::templateToFile(const QString &source, const QString &dest, Args &&...args) {
QFile file(source);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
Expand All @@ -61,7 +61,8 @@ void InitializrHelper::templateToFile(const QString &source, const QString &dest

void InitializrHelper::copyFile(const QString &source, const QString &dest) {
QFile::copy(source, dest);
QFile::setPermissions(dest, QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther);
QFile::setPermissions(dest, QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup |
QFile::WriteOther);
}

[[maybe_unused]] void InitializrHelper::generate(const QString &name, const QString &path) {
Expand All @@ -87,15 +88,21 @@ void InitializrHelper::copyFile(const QString &source, const QString &dest) {
projectDir.mkpath(projectPath);
QDir fluentDir(projectDir.filePath("FluentUI"));
copyDir(QDir(QGuiApplication::applicationDirPath() + "/source"), fluentDir);
templateToFile(":/example/res/template/CMakeLists.txt.in", projectDir.filePath("CMakeLists.txt"), name);
templateToFile(":/example/res/template/src/CMakeLists.txt.in", projectDir.filePath("src/CMakeLists.txt"), name);
templateToFile(":/example/res/template/src/main.cpp.in", projectDir.filePath("src/main.cpp"), name);
templateToFile(":/example/res/template/src/main.qml.in", projectDir.filePath("src/main.qml"), name);
templateToFile(":/example/res/template/src/en_US.ts.in", projectDir.filePath("src/" + name + "_en_US.ts"), name);
templateToFile(":/example/res/template/src/zh_CN.ts.in", projectDir.filePath("src/" + name + "_zh_CN.ts"), name);
templateToFile(":/example/res/template/CMakeLists.txt.in",
projectDir.filePath("CMakeLists.txt"), name);
templateToFile(":/example/res/template/src/CMakeLists.txt.in",
projectDir.filePath("src/CMakeLists.txt"), name);
templateToFile(":/example/res/template/src/main.cpp.in", projectDir.filePath("src/main.cpp"),
name);
templateToFile(":/example/res/template/src/main.qml.in", projectDir.filePath("src/main.qml"),
name);
templateToFile(":/example/res/template/src/en_US.ts.in",
projectDir.filePath("src/" + name + "_en_US.ts"), name);
templateToFile(":/example/res/template/src/zh_CN.ts.in",
projectDir.filePath("src/" + name + "_zh_CN.ts"), name);
copyFile(":/example/res/template/src/App.qml.in", projectDir.filePath("src/App.qml"));
copyFile(":/example/res/template/src/qml.qrc.in", projectDir.filePath("src/qml.qrc"));
copyFile(":/example/res/template/src/logo.ico.in", projectDir.filePath("src/logo.ico"));
copyFile(":/example/res/template/src/README.md.in", projectDir.filePath("src/README.md"));
return this->success(projectPath+"/CMakeLists.txt");
return this->success(projectPath + "/CMakeLists.txt");
}
Loading

0 comments on commit 8d1ee6f

Please sign in to comment.