Add logging in debug build and force graphics API
This commit is contained in:
3 files changed
+69
-7
No files matched your search
+66
-4
@@ -1,17 +1,63 @@
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
#include <QFileInfo>
|
||||
#include <QIcon>
|
||||
#include <QSize>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
#include <QQuickWindow>
|
||||
#include <QSGRendererInterface>
|
||||
|
||||
#include "backend/BookController.h"
|
||||
#include "backend/ReadingModel.h"
|
||||
#include "backend/AppState.h"
|
||||
|
||||
void myMessageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss.zzz"));
|
||||
|
||||
QString level;
|
||||
switch (type) {
|
||||
case QtDebugMsg: level = QStringLiteral("DEBUG"); break;
|
||||
case QtInfoMsg: level = QStringLiteral("INFO"); break;
|
||||
case QtWarningMsg: level = QStringLiteral("WARNING"); break;
|
||||
case QtCriticalMsg: level = QStringLiteral("CRITICAL"); break;
|
||||
case QtFatalMsg: level = QStringLiteral("FATAL"); break;
|
||||
}
|
||||
|
||||
QString source;
|
||||
if (context.category && qstrcmp(context.category, "default") != 0) {
|
||||
source = QString::fromUtf8(context.category);
|
||||
} else if (context.file) {
|
||||
QString fileName = QFileInfo(QString::fromUtf8(context.file)).fileName();
|
||||
source = QStringLiteral("%1:%2").arg(fileName).arg(context.line);
|
||||
}
|
||||
|
||||
QString formattedMsg;
|
||||
if (source.isEmpty()) {
|
||||
formattedMsg = QStringLiteral("%1 [%2] %3").arg(timestamp, level, msg);
|
||||
} else {
|
||||
formattedMsg = QStringLiteral("%1 [%2] [%3] %4").arg(timestamp, level, source, msg);
|
||||
}
|
||||
|
||||
QTextStream(stdout, QIODevice::WriteOnly) << formattedMsg << Qt::endl;
|
||||
|
||||
if (type == QtFatalMsg) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qInstallMessageHandler(myMessageHandler);
|
||||
|
||||
// Select graphics API per platform
|
||||
#if defined(Q_OS_MACOS)
|
||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::Metal);
|
||||
#else
|
||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::Vulkan);
|
||||
#endif
|
||||
|
||||
QApplication app(argc, argv);
|
||||
QApplication::setApplicationName(QStringLiteral("Asteria"));
|
||||
QApplication::setOrganizationName(QStringLiteral("Asteria"));
|
||||
@@ -34,8 +80,7 @@ int main(int argc, char *argv[])
|
||||
appState.restore();
|
||||
bookController.setAppState(&appState);
|
||||
|
||||
const QStringList args = QCoreApplication::arguments();
|
||||
if (args.size() > 1) {
|
||||
if (const QStringList args = QCoreApplication::arguments(); args.size() > 1) {
|
||||
const QString& filePath = args.at(1);
|
||||
if (QFileInfo::exists(filePath))
|
||||
appState.setLastFilePath(filePath);
|
||||
@@ -53,7 +98,24 @@ int main(int argc, char *argv[])
|
||||
Qt::QueuedConnection);
|
||||
engine.load(url);
|
||||
|
||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&]() {
|
||||
if (const auto *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0))) {
|
||||
const auto api = window->rendererInterface()->graphicsApi();
|
||||
const char *apiName = [api]() {
|
||||
switch (api) {
|
||||
case QSGRendererInterface::OpenGL: return "OpenGL";
|
||||
case QSGRendererInterface::Vulkan: return "Vulkan";
|
||||
case QSGRendererInterface::Direct3D11: return "Direct3D 11";
|
||||
case QSGRendererInterface::Direct3D12: return "Direct3D 12";
|
||||
case QSGRendererInterface::Metal: return "Metal";
|
||||
case QSGRendererInterface::Software: return "Software";
|
||||
case QSGRendererInterface::Null: return "Null";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}();
|
||||
qInfo("Rendering API: %s", apiName);
|
||||
}
|
||||
|
||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&bookController, &appState, &readingModel]() {
|
||||
if (bookController.hasBook()) {
|
||||
appState.setLastFilePath(bookController.currentFilePath());
|
||||
appState.setLastChapter(readingModel.currentChapter());
|
||||
|
||||
@@ -18,7 +18,6 @@ ApplicationWindow {
|
||||
property bool sidebarOpen: appState.sidebarOpen
|
||||
onSidebarOpenChanged: appState.sidebarOpen = sidebarOpen
|
||||
property string currentPage: "starter"
|
||||
property string pageFlipMode: appState.pageFlipMode
|
||||
property bool _restoringState: false
|
||||
|
||||
onCurrentPageChanged: appState.lastPage = currentPage
|
||||
|
||||
Reference in new issue
Block a user