21#include <QApplication>
22#include <QCommandLineParser>
27#include "nlohmann/json.hpp"
39 MainWindowOptions options = {};
40 bool maximize =
false;
43 RestoreOptions restoreOptions = {};
44 std::vector<std::string> filesToLint;
45 std::vector<MainWindow> mainWindows;
49 return filesToLint.empty();
53inline void from_json(
const nlohmann::json &j, LinterConfig::MainWindow &mw)
56 mw.
options = MainWindowOptions(j.value(
"options", 0));
57 mw.maximize = j.value(
"maximize",
false);
60inline void from_json(
const nlohmann::json &j, LinterConfig &ls)
62 ls.filesToLint = j.value(
"files", std::vector<std::string>());
63 ls.mainWindows = j.value(
"mainWindows", std::vector<LinterConfig::MainWindow>());
64 ls.restoreOptions = RestoreOptions(j.value(
"restoreOptions",
int(RestoreOption::RestoreOption_None)));
72 if (configFile.
isEmpty() && positionalArguments.isEmpty()) {
73 qWarning() <<
"Expected either a config file or positional arguments";
75 }
else if (!configFile.
isEmpty() && !positionalArguments.isEmpty()) {
76 qWarning() <<
"Expected either a config file or positional arguments, not both";
78 }
else if (!positionalArguments.isEmpty()) {
79 std::transform(positionalArguments.begin(), positionalArguments.end(), std::back_inserter(c.filesToLint),
81 return str.toStdString();
86 qWarning() <<
"Failed to open" << configFile;
91 nlohmann::json j = nlohmann::json::parse(jsonData,
nullptr,
false);
98static bool lint(
const QString &filename, LinterConfig config,
bool isVerbose)
101 qDebug() <<
"Linting" << filename <<
"with options" << config.restoreOptions;
117 for (
auto mw : config.mainWindows) {
120 qDebug() <<
"Pre-creating main window" << name <<
"with options" << mw.options;
124 mainWindow->view()->showMaximized();
126 mainWindow->view()->show();
133int main(
int argc,
char *argv[])
138 if (frontends.empty()) {
139 qWarning() <<
"Error: Your KDDockWidgets installation doesn't support any frontend!";
145 QCommandLineOption forceQtQuick = { {
"q",
"force-qtquick" },
"Forces usage of QtQuick" };
146 QCommandLineOption configFileOpt = { {
"c",
"config" },
"Linter config file",
"configfile" };
149 QCommandLineOption waitAtEndOpt = { {
"w",
"wait" },
"Waits instead of exiting. For debugging purposes." };
160#if defined(KDDW_FRONTEND_QTQUICK)
161#if defined(KDDW_FRONTEND_QTWIDGETS)
166 frontendType = FrontendType::QtQuick;
172#if defined(KDDW_FRONTEND_QTQUICK) && defined(KDDW_FRONTEND_QTWIDGETS)
173 if (parser.
isSet(forceQtQuick))
174 frontendType = FrontendType::QtQuick;
183 qWarning() <<
"Bailing out";
188 for (
const std::string &layout : lc.filesToLint) {
195 qDebug() <<
"Success";
201 if (parser.
isSet(waitAtEndOpt)) {
208 qDebug() <<
"Testing if serialize works" << !saved.
isEmpty();
Application-wide config to tune certain behaviours of the framework.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
MainWindowOptions options() const
Returns the main window options that were passed via constructor.
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
int main(int argc, char *argv[])
LinterConfig requestedLinterConfig(const QCommandLineParser &parser, const QString &configFile)
void from_json(const nlohmann::json &j, LinterConfig::MainWindow &mw)
static bool lint(const QString &filename, LinterConfig config, bool isVerbose)
bool isEmpty() const const
QCommandLineOption addHelpOption()
bool addOption(const QCommandLineOption &option)
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
bool isSet(const QString &name) const const
QStringList positionalArguments() const const
void process(const QStringList &arguments)
void setApplicationDescription(const QString &description)
QString value(const QString &optionName) const const
bool setCurrent(const QString &path)
virtual bool open(QIODevice::OpenMode mode) override
QString fromStdString(const std::string &str)
bool isEmpty() const const