Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions designer/QHexEditPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

#include <QtPlugin>

QHexEditPlugin::QHexEditPlugin(QObject * parent) : QObject(parent)
QHexEditPlugin::QHexEditPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}


bool QHexEditPlugin::isContainer() const
{
return false;
Expand All @@ -45,23 +45,23 @@ QIcon QHexEditPlugin::icon() const
QString QHexEditPlugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"QHexEdit\" name=\"hexEdit\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>QHexEditWidget</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>QHexEdit widget allow to edit the data in hex view.</string>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
" <widget class=\"QHexEdit\" name=\"hexEdit\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>QHexEditWidget</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>QHexEdit widget allow to edit the data in hex view.</string>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
}

QString QHexEditPlugin::group() const
Expand Down Expand Up @@ -89,7 +89,7 @@ QString QHexEditPlugin::whatsThis() const
return "";
}

QWidget * QHexEditPlugin::createWidget(QWidget *parent)
QWidget *QHexEditPlugin::createWidget(QWidget *parent)
{
return new QHexEdit(parent);
}
Expand All @@ -102,6 +102,6 @@ void QHexEditPlugin::initialize(QDesignerFormEditorInterface * /*core*/)
initialized = true;
}

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(QHexEditPlugin, QHexEditPlugin)
#endif
7 changes: 3 additions & 4 deletions designer/QHexEditPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <QObject>

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtDesigner/QDesignerCustomWidgetInterface>
#else
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
Expand All @@ -31,12 +31,12 @@ class QHexEditPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QHexEditPlugin")
#endif

public:
QHexEditPlugin(QObject * parent = 0);
QHexEditPlugin(QObject *parent = 0);

bool isContainer() const;
bool isInitialized() const;
Expand All @@ -52,7 +52,6 @@ class QHexEditPlugin : public QObject, public QDesignerCustomWidgetInterface

private:
bool initialized;

};

#endif
63 changes: 30 additions & 33 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <QCommandLineParser>
#include <QFile>
#include <QIcon>
#include <QLibraryInfo>
#include <QLocale>
#include <QTranslator>
#include <QLibraryInfo>

#include "mainwindow.h"

Expand All @@ -33,42 +33,39 @@ struct ParsedOptions
QString file = "";
};

struct CommandLineParseResult {
enum class Status {
Ok,
Error,
VersionRequested,
HelpRequested
};
struct CommandLineParseResult
{
enum class Status { Ok, Error, VersionRequested, HelpRequested };
Status statusCode = Status::Ok;
std::optional<QString> errorString = std::nullopt;
};

CommandLineParseResult parseCommandLine(QCommandLineParser &parser, ParsedOptions *query) {
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, ParsedOptions *query)
{
using Status = CommandLineParseResult::Status;

const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption versionOption = parser.addVersionOption();
parser.addPositionalArgument("file", "File to open");

if (!parser.parse(QCoreApplication::arguments()))
return { Status::Error, parser.errorText() };
return {Status::Error, parser.errorText()};

if (parser.isSet(versionOption))
return { Status::VersionRequested };
return {Status::VersionRequested};

if (parser.isSet(helpOption))
return { Status::HelpRequested };
return {Status::HelpRequested};

const QStringList positionalArguments = parser.positionalArguments();
if (!positionalArguments.isEmpty()) {
if (positionalArguments.size() > 1)
return { Status::Error, "Several 'name' arguments specified." };
return {Status::Error, "Several 'name' arguments specified."};
query->hasFile = true;
query->file = positionalArguments.first();
}

return { Status::Ok };
return {Status::Ok};
}

int main(int argc, char *argv[])
Expand All @@ -87,11 +84,11 @@ int main(int argc, char *argv[])

QTranslator translator_qt;

#if QT_VERSION < 0x060000
#if QT_VERSION < 0x060000
QString path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
#else
#else
QString path = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
#endif
#endif

if (translator_qt.load(QLocale(), "qt", "_", path))
QCoreApplication::installTranslator(&translator_qt);
Expand All @@ -106,22 +103,22 @@ int main(int argc, char *argv[])
CommandLineParseResult parseResult = parseCommandLine(parser, &query);

switch (parseResult.statusCode) {
case Status::Ok:
break;

case Status::Error:
std::fputs(qPrintable(parseResult.errorString.value_or("Unknown error occurred")), stderr);
std::fputs("\n\n", stderr);
std::fputs(qPrintable(parser.helpText()), stderr);
return 1;

case Status::VersionRequested:
parser.showVersion();
return 0;

case Status::HelpRequested:
parser.showHelp();
return 0;
case Status::Ok:
break;

case Status::Error:
std::fputs(qPrintable(parseResult.errorString.value_or("Unknown error occurred")), stderr);
std::fputs("\n\n", stderr);
std::fputs(qPrintable(parser.helpText()), stderr);
return 1;

case Status::VersionRequested:
parser.showVersion();
return 0;

case Status::HelpRequested:
parser.showHelp();
return 0;
}

if (query.hasFile)
Expand Down
Loading