Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adress more code smells #111

Merged
merged 1 commit into from
Oct 28, 2023
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/qt_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
check-qt-updates:
name: Check Qt updates
runs-on: ubuntu-latest

permissions:
Dismissed Show dismissed Hide dismissed
actions: read
contents: read

steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand Down
9 changes: 7 additions & 2 deletions doc/screenshot.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"AuditMode": false,
"Boot": {
"0000": {
"attributes": 1,
Expand All @@ -10,7 +11,7 @@
"partition_number": 1,
"partition_signature": "{721c8b66-426c-4e86-8e99-3457c46ab0b9}",
"partition_size": "0x32",
"partition_start": "0x1cd6",
"partition_start": "0x1CD6",
"signature_type": 2,
"subtype": "HD",
"type": "MEDIA"
Expand Down Expand Up @@ -185,5 +186,9 @@
0,
1
],
"Timeout": 10
"DeployedMode": false,
"SecureBoot": true,
"SetupMode": false,
"Timeout": 10,
"VendorKeys": false
}
2 changes: 1 addition & 1 deletion include/bootentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class End
mutable QString string = "";

public:
uint8_t _subtype = EFIBoot::File_path::End_entire::SUBTYPE;
uint8_t _subtype = 0;

public:
End() = default;
Expand Down
2 changes: 1 addition & 1 deletion include/bootentrylistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BootEntryListModel: public QAbstractListModel
friend class MoveBootEntryFilePathCommand;

public:
enum Option
enum class Option : uint8_t
{
ReadOnly = 0x1,
IsBoot = 0x2,
Expand Down
2 changes: 1 addition & 1 deletion include/bootentrylistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BootEntryListView: public QListView
BootEntryListView(const BootEntryListView &) = delete;
BootEntryListView &operator=(const BootEntryListView &) = delete;

virtual void setModel(QAbstractItemModel *model) override { QListView::setModel(model); }
void setModel(QAbstractItemModel *model) override { QListView::setModel(model); }
void setModel(BootEntryListModel *model);

protected:
Expand Down
24 changes: 7 additions & 17 deletions include/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
#include "efibootdata.h"
#include <QUndoCommand>

template <class Type>
template <class Type, class SignalPtr>
class SetEFIBootDataValueCommand: public QUndoCommand
{
using PropertyPtr = Type EFIBootData::*;
using SignalPtr = void (EFIBootData::*)(const Type &);

EFIBootData &data;
const QString name;
Expand Down Expand Up @@ -50,7 +49,7 @@ class SetEFIBootDataValueCommand: public QUndoCommand

bool mergeWith(const QUndoCommand *command) override
{
auto cmd = static_cast<const SetEFIBootDataValueCommand<Type> *>(command);
const auto cmd = static_cast<add_const_t<decltype(this)>>(command);
if(&cmd->data != &data)
return false;

Expand All @@ -68,6 +67,9 @@ class SetEFIBootDataValueCommand: public QUndoCommand
}
};

template <class Type, class SignalPtr>
SetEFIBootDataValueCommand(EFIBootData &data_, const QString &name_, typename SetEFIBootDataValueCommand<Type, SignalPtr>::PropertyPtr property_, SignalPtr signal_, const Type &value_, QUndoCommand *parent) -> SetEFIBootDataValueCommand<Type, SignalPtr>;

class InsertRemoveBootEntryCommand: public QUndoCommand
{
protected:
Expand Down Expand Up @@ -129,18 +131,6 @@ class MoveBootEntryCommand: public QUndoCommand
bool mergeWith(const QUndoCommand *command) override;
};

template <class Type>
struct type_identity
{
using type = Type;
};

template <class Type>
struct underlying_type
{
using type = typename std::conditional_t<std::is_enum_v<Type>, std::underlying_type<Type>, type_identity<Type>>::type;
};

template <class Type>
class SetBootEntryValueCommand: public QUndoCommand
{
Expand All @@ -163,7 +153,7 @@ class SetBootEntryValueCommand: public QUndoCommand
, property{property_}
, value{value_}
{
setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast<typename underlying_type<Type>::type>(value)));
setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast<underlying_type_t<Type>>(value)));
}

SetBootEntryValueCommand(const SetBootEntryValueCommand &) = delete;
Expand Down Expand Up @@ -204,7 +194,7 @@ class SetBootEntryValueCommand: public QUndoCommand
if(value == entry.*property)
setObsolete(true);

setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast<typename underlying_type<Type>::type>(entry.*property)));
setText(QObject::tr("Change %1 entry \"%2\" %3 to \"%4\"").arg(model.name, title, name).arg(static_cast<underlying_type_t<Type>>(entry.*property)));
return true;
}
};
Expand Down
18 changes: 16 additions & 2 deletions include/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ inline bool toUnicode(QString &output, const Container &input, const char *codec
output = decoder.decode(input);
return !decoder.hasError();
#else
QTextCodec *codec = QTextCodec::codecForName(codec_name);
auto codec = QTextCodec::codecForName(codec_name);
QTextCodec::ConverterState state;
output = codec->toUnicode(reinterpret_cast<const char *>(input.data()), static_cast<int>(input.size()), &state);
output = codec->toUnicode(reinterpret_cast<const char *>(std::data(input)), static_cast<int>(std::size(input)), &state);
return state.invalidChars == 0;
#endif
}
Expand All @@ -211,6 +211,20 @@ inline QByteArray fromUnicode(const QString &input, const char *codec_name = "UT
return encoder->fromUnicode(input);
#endif
}

template <class Type>
struct type_identity
{
using type = Type;
};

// Like std::underlying_type but also works for non enums
template <class Type>
using underlying_type_t = typename std::conditional_t<std::is_enum_v<Type>, std::underlying_type<Type>, type_identity<Type>>::type;

// like std::add_const but forces const also for pointer types
template <class Type>
using add_const_t = typename std::conditional_t<std::is_pointer_v<Type>, std::add_pointer_t<std::add_const_t<std::remove_pointer_t<Type>>>, std::add_const_t<Type>>;
#endif

#if defined(__clang__)
Expand Down
2 changes: 1 addition & 1 deletion include/devicepathview.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DevicePathView: public QListView
Q_OBJECT

private:
FilePathDelegate delegate;
FilePathDelegate delegate{};
std::unique_ptr<FilePathDialog> dialog = nullptr;
bool readonly = false;

Expand Down
7 changes: 2 additions & 5 deletions include/disableundoredo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ class DisableUndoRedo: public QObject
{
Q_OBJECT

public:
explicit DisableUndoRedo(QObject *parent = nullptr)
: QObject{parent}
{
}
using QObject::QObject;

public:
DisableUndoRedo(const DisableUndoRedo &) = delete;
DisableUndoRedo &operator=(const DisableUndoRedo &) = delete;

Expand Down
Loading
Loading