Skip to content

Commit

Permalink
Merge branch 'feature/sysinfo' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Jul 24, 2023
2 parents 0d6474b + 3a74b5f commit c1623ee
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 10 deletions.
409 changes: 409 additions & 0 deletions src/app/command_system_information.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/app/commands_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Command::Command(IAppContext* context)

Application* Command::app() const
{
return m_context->guiApp()->application().get();
return m_context ? m_context->guiApp()->application().get() : nullptr;
}

GuiDocument* Command::currentGuiDocument() const
Expand All @@ -39,7 +39,7 @@ GuiDocument* Command::currentGuiDocument() const

int Command::currentDocumentIndex() const
{
return this->context()->findDocumentIndex(this->currentDocument());
return m_context ? m_context->findDocumentIndex(this->currentDocument()) : -1;
}

void Command::setCurrentDocument(const DocumentPtr& doc)
Expand Down
8 changes: 4 additions & 4 deletions src/app/commands_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class Command : public QObject {

protected:
Application* app() const;
GuiApplication* guiApp() const { return m_context->guiApp(); }
TaskManager* taskMgr() const { return m_context->taskMgr(); }
QWidget* widgetMain() const { return m_context->widgetMain(); }
Document::Identifier currentDocument() const { return m_context->currentDocument(); }
GuiApplication* guiApp() const { return m_context ? m_context->guiApp() : nullptr; }
TaskManager* taskMgr() const { return m_context ? m_context->taskMgr() : nullptr; }
QWidget* widgetMain() const { return m_context ? m_context->widgetMain() : nullptr; }
Document::Identifier currentDocument() const { return m_context ? m_context->currentDocument() : -1; }
GuiDocument* currentGuiDocument() const;
int currentDocumentIndex() const;

Expand Down
6 changes: 4 additions & 2 deletions src/app/commands_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

#include "dialog_about.h"
#include "qtwidgets_utils.h"
#include "qstring_conv.h"

#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtGui/QDesktopServices>
#include <QtWidgets/QApplication>
#include <QtCore/QCoreApplication>

namespace Mayo {

Expand All @@ -32,7 +34,7 @@ CommandAbout::CommandAbout(IAppContext* context)
: Command(context)
{
auto action = new QAction(this);
action->setText(Command::tr("About %1").arg(QApplication::applicationName()));
action->setText(Command::tr("About %1").arg(QCoreApplication::applicationName()));
this->setAction(action);
}

Expand Down
10 changes: 10 additions & 0 deletions src/app/commands_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ class CommandReportBug : public Command {
static constexpr std::string_view Name = "report-bug";
};

class CommandSystemInformation : public Command {
public:
CommandSystemInformation(IAppContext* context);
void execute() override;

static QString data();

static constexpr std::string_view Name = "system-info";
};

class CommandAbout : public Command {
public:
CommandAbout(IAppContext* context);
Expand Down
16 changes: 15 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../gui/gui_application.h"
#include "app_module.h"
#include "cli_export.h"
#include "commands_help.h"
#include "console.h"
#include "document_tree_node_properties_providers.h"
#include "filepath_conv.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ struct CommandLineArguments {
std::vector<FilePath> listFilepathToExport;
std::vector<FilePath> listFilepathToOpen;
bool cliProgressReport = true;
bool showSystemInformation = false;
};

// Provides customization of Qt message handler
Expand Down Expand Up @@ -228,6 +230,12 @@ static CommandLineArguments processCommandLine()
);
cmdParser.addOption(cmdCliNoProgress);

const QCommandLineOption cmdSysInfo(
QStringList{ "system-info" },
Main::tr("Show detailed system information and quit")
);
cmdParser.addOption(cmdSysInfo);

cmdParser.addPositionalArgument(
Main::tr("files"),
Main::tr("Files to open at startup, optionally"),
Expand Down Expand Up @@ -268,6 +276,7 @@ static CommandLineArguments processCommandLine()
args.includeDebugLogs = cmdParser.isSet(cmdDebugLogs);
#endif
args.cliProgressReport = !cmdParser.isSet(cmdCliNoProgress);
args.showSystemInformation = cmdParser.isSet(cmdSysInfo);

return args;
}
Expand Down Expand Up @@ -396,7 +405,6 @@ static void initGui(GuiApplication* guiApp)
if (!propForceOpenGlFallbackWidget && hasQGuiApplication) { // QOpenGL requires QGuiApplication
const std::string strGlVersion = queryGlVersionString();
const QVersionNumber glVersion = parseSemanticVersionString(strGlVersion);
qInfo() << fmt::format("OpenGL v{}.{}", glVersion.majorVersion(), glVersion.minorVersion()).c_str();
if (!glVersion.isNull() && glVersion.majorVersion() >= 2) { // Requires at least OpenGL version >= 2.0
setFunctionCreateGraphicsDriver(&QOpenGLWidgetOccView::createCompatibleGraphicsDriver);
IWidgetOccView::setCreator(&QOpenGLWidgetOccView::create);
Expand Down Expand Up @@ -490,6 +498,12 @@ static int runApp(QCoreApplication* qtApp)
appModule->properties()->retranslate();

// Process CLI
if (args.showSystemInformation) {
CommandSystemInformation cmdSysInfo(nullptr);
cmdSysInfo.execute();
return qtApp->exec();
}

if (!args.listFilepathToExport.empty()) {
if (args.listFilepathToOpen.empty())
fnCriticalExit(Main::tr("No input files -> nothing to export"));
Expand Down
2 changes: 2 additions & 0 deletions src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void MainWindow::createCommands()

// "Help" commands
this->addCommand<CommandReportBug>();
this->addCommand<CommandSystemInformation>();
this->addCommand<CommandAbout>();
}

Expand Down Expand Up @@ -193,6 +194,7 @@ void MainWindow::createMenus()
{ // Help
auto menu = m_ui->menu_Help;
fnAddAction(menu, CommandReportBug::Name);
fnAddAction(menu, CommandSystemInformation::Name);
menu->addSeparator();
fnAddAction(menu, CommandAbout::Name);
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/qstring_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ template<> struct StringConv<std::string, QString> {
static auto to(const std::string& str) { return QString::fromStdString(str); }
};

// std::wstring -> QString
template<> struct StringConv<std::wstring, QString> {
static auto to(const std::wstring& str) { return QString::fromStdWString(str); }
};

// std::string_view -> QString
template<> struct StringConv<std::string_view, QString> {
static auto to(std::string_view str) { return QString::fromUtf8(str.data(), int(str.size())); }
Expand Down Expand Up @@ -97,6 +102,11 @@ template<> struct StringConv<QString, std::u16string_view> {
}
};

// QString -> std::wstring
template<> struct StringConv<QString, std::wstring> {
static auto to(const QString& str) { return str.toStdWString(); }
};

// QString -> TCollection_ExtendedString
template<> struct StringConv<QString, TCollection_ExtendedString> {
static auto to(const QString& str) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/widget_occ_view_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void QOpenGLWidgetOccView_createOpenGlContext(std::function<void(Aspect_Renderin
return;
}

fnCallback(glCtx->RenderingContext());
if (fnCallback)
fnCallback(glCtx->RenderingContext());
}

Handle_Graphic3d_GraphicDriver QOpenGLWidgetOccView_createCompatibleGraphicsDriver()
Expand Down

0 comments on commit c1623ee

Please sign in to comment.