diff --git a/CMakeLists.txt b/CMakeLists.txt index b1756dc..2d8d071 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,9 +169,14 @@ if(ANDROID AND QUICK_GUI) option(ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI "enables with undo/redo support for the Qt Quick GUI (requires Qt Widgets)" ON) if(ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) list(APPEND ADDITIONAL_QT_MODULES Widgets) - set_property( - SOURCE quickgui/controller.cpp - APPEND PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI + list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) + list(APPEND QML_HEADER_FILES + gui/stacksupport.h + gui/undocommands.h + ) + list(APPEND QML_SRC_FILES + gui/stacksupport.cpp + gui/undocommands.cpp ) endif() endif() diff --git a/gui/stacksupport.h b/gui/stacksupport.h index 0b19108..38a8ecb 100644 --- a/gui/stacksupport.h +++ b/gui/stacksupport.h @@ -7,6 +7,8 @@ #include +#define PASSWORD_MANAGER_UNDO_SUPPORT + namespace QtGui { class StackAbsorper; diff --git a/model/entrymodel.cpp b/model/entrymodel.cpp index bb102c4..f374d36 100644 --- a/model/entrymodel.cpp +++ b/model/entrymodel.cpp @@ -1,6 +1,6 @@ #include "./entrymodel.h" -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT #include "../gui/undocommands.h" #endif @@ -41,7 +41,7 @@ EntryModel::EntryModel(QObject *parent) { } -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT /*! * \brief Constructs a new entry model with the specified \a undoStack. * @@ -267,7 +267,7 @@ QMap EntryModel::itemData(const QModelIndex &index) const bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int role) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, index, value, role)); } @@ -395,7 +395,7 @@ int EntryModel::columnCount(const QModelIndex &) const bool EntryModel::insertRows(int row, int count, const QModelIndex &parent) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, row, count, parent)); } @@ -428,7 +428,7 @@ bool EntryModel::insertRows(int row, int count, const QModelIndex &parent) bool EntryModel::removeRows(int row, int count, const QModelIndex &parent) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, row, count, parent)); } @@ -448,7 +448,7 @@ bool EntryModel::removeRows(int row, int count, const QModelIndex &parent) bool EntryModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, sourceParent, sourceRow, count, destinationParent, destinationChild)); } diff --git a/model/entrymodel.h b/model/entrymodel.h index 91f75a1..4e58b85 100644 --- a/model/entrymodel.h +++ b/model/entrymodel.h @@ -1,7 +1,7 @@ #ifndef ENTRYMODEL_H #define ENTRYMODEL_H -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) #include "../gui/stacksupport.h" #endif @@ -26,7 +26,7 @@ enum EntryModelRoles { }; class EntryModel : public QAbstractItemModel -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT , public StackSupport #endif @@ -37,7 +37,7 @@ class EntryModel : public QAbstractItemModel public: explicit EntryModel(QObject *parent = nullptr); -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT explicit EntryModel(QUndoStack *undoStack, QObject *parent = nullptr); #endif @@ -96,7 +96,7 @@ inline Io::NodeEntry *EntryModel::rootEntry() inline void EntryModel::setRootEntry(Io::NodeEntry *entry) { if (m_rootEntry != entry) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT clearUndoStack(); #endif beginResetModel(); diff --git a/model/fieldmodel.cpp b/model/fieldmodel.cpp index cd5e14b..e96c15e 100644 --- a/model/fieldmodel.cpp +++ b/model/fieldmodel.cpp @@ -1,6 +1,6 @@ #include "./fieldmodel.h" -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT #include "../gui/undocommands.h" #endif @@ -36,7 +36,7 @@ FieldModel::FieldModel(QObject *parent) { } -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT /*! * \brief Constructs a new field model with the specified \a undoStack. * @@ -167,7 +167,7 @@ QMap FieldModel::itemData(const QModelIndex &index) const bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int role) { -#if PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, index, value, role)); } @@ -297,7 +297,7 @@ int FieldModel::columnCount(const QModelIndex &parent) const bool FieldModel::insertRows(int row, int count, const QModelIndex &parent) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, row, count)); } @@ -313,7 +313,7 @@ bool FieldModel::insertRows(int row, int count, const QModelIndex &parent) bool FieldModel::removeRows(int row, int count, const QModelIndex &parent) { -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT if (undoStack()) { return push(make_unique(this, row, count)); } diff --git a/model/fieldmodel.h b/model/fieldmodel.h index 953f7a9..3ec5b60 100644 --- a/model/fieldmodel.h +++ b/model/fieldmodel.h @@ -1,7 +1,7 @@ #ifndef FIELDMODEL_H #define FIELDMODEL_H -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) #include "../gui/stacksupport.h" #endif @@ -39,7 +39,7 @@ enum PasswordVisibility { }; class FieldModel : public QAbstractTableModel -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT , public StackSupport #endif @@ -50,7 +50,7 @@ class FieldModel : public QAbstractTableModel public: explicit FieldModel(QObject *parent = nullptr); -#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS +#ifdef PASSWORD_MANAGER_UNDO_SUPPORT explicit FieldModel(QUndoStack *undoStack, QObject *parent = nullptr); #endif @@ -139,7 +139,7 @@ inline void FieldModel::setPasswordVisibility(PasswordVisibility passwordVisibil { m_passwordVisibility = passwordVisibility; if (m_fields) { - emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector() << Qt::DisplayRole << Qt::EditRole); + emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector({Qt::DisplayRole, Qt::EditRole})); } } } // namespace QtGui diff --git a/quickgui/controller.h b/quickgui/controller.h index f26d77a..739e434 100644 --- a/quickgui/controller.h +++ b/quickgui/controller.h @@ -13,10 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QSettings) #if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) -#define PASSWORD_MANAGER_UNDO_SUPPORT -#include -#else -QT_FORWARD_DECLARE_CLASS(QUndoStack) +#include "../gui/stacksupport.h" #endif namespace QtGui {