Skip to content

Commit

Permalink
Add undo/redo support (#59)
Browse files Browse the repository at this point in the history
* Add undo/redo support

* Update Qt to 6.4.3 in CI
  • Loading branch information
Neverous authored Mar 21, 2023
1 parent 44e52c8 commit 5babe69
Show file tree
Hide file tree
Showing 27 changed files with 3,346 additions and 1,667 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
BraceWrapping:
BeforeLambdaBody: 'true'

...
6 changes: 3 additions & 3 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- GCC
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- MSVC
Expand Down Expand Up @@ -200,7 +200,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- GCC
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- MSVC
Expand Down Expand Up @@ -177,7 +177,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang

Expand Down Expand Up @@ -238,7 +238,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- GCC
Expand Down Expand Up @@ -302,7 +302,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang
- MSVC
Expand Down Expand Up @@ -349,7 +349,7 @@ jobs:
qt_version:
- 5.15.2 # OS LTS
- 6.2.4 # LTS Standard
- 6.4.2 # latest
- 6.4.3 # latest
compiler:
- Clang

Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ if(WIN32)
# Enable all warnings in application code
/Wall /permissive- /WX
# Disable some warnings
# C4371: 'classname': layout of class may have changed from a previous version of the compiler due to better packing of member 'member'
/wd4371
# C4464: relative include path contains '..
/wd4464
# C4702: unreachable code
Expand Down Expand Up @@ -215,6 +217,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/devicepathview.cpp
src/devicepathproxymodel.cpp
src/driveinfo.cpp
src/efibootdata.cpp
src/efibooteditor.cpp
)

Expand Down Expand Up @@ -252,13 +255,16 @@ target_sources(${PROJECT_NAME} PRIVATE
include/bootentrylistmodel.h
include/bootentrylistview.h
include/bootentrywidget.h
include/commands.h
include/compat.h
include/disableundoredo.h
include/filepathdelegate.h
include/filepathdialog.h
include/devicepathview.h
include/devicepathproxymodel.h
include/driveinfo.h
include/efiboot.h
include/efibootdata.h
include/efibooteditor.h
include/efivar-lite/efiboot-loadopt.h
include/efivar-lite/efivar-dp.h
Expand Down
5 changes: 3 additions & 2 deletions include/bootentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class BootEntry
QString description = "New entry";
QVector<File_path::ANY> device_path = {};
QString optional_data = "";
EFIBoot::Load_option_attribute attributes = EFIBoot::Load_option_attribute::EMPTY;
uint32_t attributes = EFIBoot::Load_option_attribute::EMPTY;
uint32_t efi_attributes = EFIBoot::EFI_VARIABLE_ATTRIBUTE_DEFAULTS;

bool is_current_boot = false;
Expand All @@ -516,8 +516,9 @@ class BootEntry
QJsonObject toJSON() const;

QString formatDevicePath(bool refresh = true) const;
QString getTitle() const;

bool changeOptionalDataFormat(OptionalDataFormat format);
bool changeOptionalDataFormat(OptionalDataFormat format, bool test = false);

private:
QByteArray getRawOptionalData() const;
Expand Down
29 changes: 15 additions & 14 deletions include/bootentryform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class BootEntryForm: public QWidget
{
Q_OBJECT

private:
std::unique_ptr<Ui::BootEntryForm> ui;
BootEntryListModel *entries_list_model{nullptr};
DevicePathProxyModel device_path_proxy_model{};
QModelIndex current_index{};
const BootEntry *current_item{nullptr};
bool changing_optional_data_format{false};

public:
explicit BootEntryForm(QWidget *parent = nullptr);
BootEntryForm(const BootEntryForm &) = delete;
Expand All @@ -28,20 +36,13 @@ class BootEntryForm: public QWidget
void setBootEntryListModel(BootEntryListModel &model);
void setItem(const QModelIndex &index, const BootEntry *item);

private:
std::unique_ptr<Ui::BootEntryForm> ui;
BootEntryListModel *entries_list_model = nullptr;
DevicePathProxyModel device_path_proxy_model{};
QModelIndex current_index = {};
const BootEntry *current_item = nullptr;

private slots:
void indexEdited(const QString &text);
void descriptionEdited(const QString &text);
void optionalDataFormatChanged(int format);
void setIndex(const QString &text);
void setDescription(const QString &text);
void setOptionalDataFormat(int format);
void optionalDataEdited();
void attributeActiveChanged(int state);
void attributeHiddenChanged(int state);
void attributeForceReconnectChanged(int state);
void categoryChanged(int index);
void setAttribute(int state);

private:
uint32_t getAttributes() const;
};
45 changes: 40 additions & 5 deletions include/bootentrylistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,71 @@
#include "bootentry.h"
#include <QAbstractListModel>
#include <QList>
#include <QUndoStack>

typedef std::function<bool(BootEntry &)> Change_fn;

class BootEntryListModel: public QAbstractListModel
{
Q_OBJECT

friend class EFIBootData;
friend class InsertRemoveBootEntryCommand;
friend class InsertBootEntryCommand;
friend class RemoveBootEntryCommand;
friend class MoveBootEntryCommand;

template <class Type>
friend class SetBootEntryValueCommand;
friend class ChangeOptionalDataFormatCommand;
friend class SetBootEntryFilePathCommand;
friend class InsertRemoveBootEntryFilePathCommand;
friend class InsertBootEntryFilePathCommand;
friend class RemoveBootEntryFilePathCommand;
friend class MoveBootEntryFilePathCommand;

public:
const QString name;
const bool readonly;

private:
QVector<BootEntry> entries = {};
QModelIndex next_boot = {};
QVector<BootEntry> entries{};
QModelIndex next_boot{};
QUndoStack *undo_stack{nullptr};

public:
explicit BootEntryListModel(QObject *parent = nullptr, bool readonly_ = false);
explicit BootEntryListModel(const QString &name_, bool readonly_ = false, QObject *parent = nullptr);
BootEntryListModel(const BootEntryListModel &) = delete;
BootEntryListModel &operator=(const BootEntryListModel &) = delete;

void setUndoStack(QUndoStack *undo_stack_);
QUndoStack *getUndoStack() const;

// Header:
QVariant headerData(int, Qt::Orientation, int = Qt::DisplayRole) const override { return {}; }

// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool changeData(const QModelIndex &index, const Change_fn &change_fn, int role = Qt::EditRole);
void setNextBootEntry(const QModelIndex &index, bool value);

void setEntryFilePath(const QModelIndex &index, int row, const File_path::ANY &file_path);
void insertEntryFilePath(const QModelIndex &index, int row, const File_path::ANY &file_path);
void removeEntryFilePath(const QModelIndex &index, int row);
void moveEntryFilePath(const QModelIndex &index, int source_row, int destination_row);
void clearEntryDevicePath(const QModelIndex &index);
void setEntryIndex(const QModelIndex &index, uint16_t value);
void setEntryDescription(const QModelIndex &index, const QString &text);
bool changeEntryOptionalDataFormat(const QModelIndex &index, int format);
void setEntryOptionalData(const QModelIndex &index, const QString &text);
void setEntryAttributes(const QModelIndex &index, uint32_t value);
void setEntryNextBoot(const QModelIndex &index, bool value);

Qt::ItemFlags flags(const QModelIndex &index) const override;

// Add data:
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool appendRow(const BootEntry &data, const QModelIndex &parent = QModelIndex());

// Remove data:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
Expand All @@ -47,4 +79,7 @@ class BootEntryListModel: public QAbstractListModel
void clear();

const QVector<BootEntry> &getEntries() const { return entries; }

private:
bool appendRow(const BootEntry &data, const QModelIndex &parent = QModelIndex());
};
3 changes: 3 additions & 0 deletions include/bootentrylistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ public slots:
void removeCurrentRow();
void moveCurrentRowUp();
void moveCurrentRowDown();

void rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow);
void rowsChanged(const QModelIndex &parent, int first, int last);
};
Loading

0 comments on commit 5babe69

Please sign in to comment.