Fix enabling undo support without Qt Widgets GUI

This commit is contained in:
Martchus 2018-12-03 00:29:54 +01:00
parent 06c280768d
commit 78a868fc9e
7 changed files with 30 additions and 26 deletions

View File

@ -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) 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) if(ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI)
list(APPEND ADDITIONAL_QT_MODULES Widgets) list(APPEND ADDITIONAL_QT_MODULES Widgets)
set_property( list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI)
SOURCE quickgui/controller.cpp list(APPEND QML_HEADER_FILES
APPEND PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI gui/stacksupport.h
gui/undocommands.h
)
list(APPEND QML_SRC_FILES
gui/stacksupport.cpp
gui/undocommands.cpp
) )
endif() endif()
endif() endif()

View File

@ -7,6 +7,8 @@
#include <memory> #include <memory>
#define PASSWORD_MANAGER_UNDO_SUPPORT
namespace QtGui { namespace QtGui {
class StackAbsorper; class StackAbsorper;

View File

@ -1,6 +1,6 @@
#include "./entrymodel.h" #include "./entrymodel.h"
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
#include "../gui/undocommands.h" #include "../gui/undocommands.h"
#endif #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. * \brief Constructs a new entry model with the specified \a undoStack.
* *
@ -267,7 +267,7 @@ QMap<int, QVariant> EntryModel::itemData(const QModelIndex &index) const
bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int role) bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<EntryModelSetValueCommand>(this, index, value, role)); return push(make_unique<EntryModelSetValueCommand>(this, index, value, role));
} }
@ -395,7 +395,7 @@ int EntryModel::columnCount(const QModelIndex &) const
bool EntryModel::insertRows(int row, int count, const QModelIndex &parent) bool EntryModel::insertRows(int row, int count, const QModelIndex &parent)
{ {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<EntryModelInsertRowsCommand>(this, row, count, parent)); return push(make_unique<EntryModelInsertRowsCommand>(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) bool EntryModel::removeRows(int row, int count, const QModelIndex &parent)
{ {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<EntryModelRemoveRowsCommand>(this, row, count, parent)); return push(make_unique<EntryModelRemoveRowsCommand>(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) 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()) { if (undoStack()) {
return push(make_unique<EntryModelMoveRowsCommand>(this, sourceParent, sourceRow, count, destinationParent, destinationChild)); return push(make_unique<EntryModelMoveRowsCommand>(this, sourceParent, sourceRow, count, destinationParent, destinationChild));
} }

View File

@ -1,7 +1,7 @@
#ifndef ENTRYMODEL_H #ifndef ENTRYMODEL_H
#define 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" #include "../gui/stacksupport.h"
#endif #endif
@ -26,7 +26,7 @@ enum EntryModelRoles {
}; };
class EntryModel : public QAbstractItemModel class EntryModel : public QAbstractItemModel
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
, ,
public StackSupport public StackSupport
#endif #endif
@ -37,7 +37,7 @@ class EntryModel : public QAbstractItemModel
public: public:
explicit EntryModel(QObject *parent = nullptr); explicit EntryModel(QObject *parent = nullptr);
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
explicit EntryModel(QUndoStack *undoStack, QObject *parent = nullptr); explicit EntryModel(QUndoStack *undoStack, QObject *parent = nullptr);
#endif #endif
@ -96,7 +96,7 @@ inline Io::NodeEntry *EntryModel::rootEntry()
inline void EntryModel::setRootEntry(Io::NodeEntry *entry) inline void EntryModel::setRootEntry(Io::NodeEntry *entry)
{ {
if (m_rootEntry != entry) { if (m_rootEntry != entry) {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
clearUndoStack(); clearUndoStack();
#endif #endif
beginResetModel(); beginResetModel();

View File

@ -1,6 +1,6 @@
#include "./fieldmodel.h" #include "./fieldmodel.h"
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
#include "../gui/undocommands.h" #include "../gui/undocommands.h"
#endif #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. * \brief Constructs a new field model with the specified \a undoStack.
* *
@ -167,7 +167,7 @@ QMap<int, QVariant> FieldModel::itemData(const QModelIndex &index) const
bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int role) bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
#if PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<FieldModelSetValueCommand>(this, index, value, role)); return push(make_unique<FieldModelSetValueCommand>(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) bool FieldModel::insertRows(int row, int count, const QModelIndex &parent)
{ {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<FieldModelInsertRowsCommand>(this, row, count)); return push(make_unique<FieldModelInsertRowsCommand>(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) bool FieldModel::removeRows(int row, int count, const QModelIndex &parent)
{ {
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
if (undoStack()) { if (undoStack()) {
return push(make_unique<FieldModelRemoveRowsCommand>(this, row, count)); return push(make_unique<FieldModelRemoveRowsCommand>(this, row, count));
} }

View File

@ -1,7 +1,7 @@
#ifndef FIELDMODEL_H #ifndef FIELDMODEL_H
#define 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" #include "../gui/stacksupport.h"
#endif #endif
@ -39,7 +39,7 @@ enum PasswordVisibility {
}; };
class FieldModel : public QAbstractTableModel class FieldModel : public QAbstractTableModel
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
, ,
public StackSupport public StackSupport
#endif #endif
@ -50,7 +50,7 @@ class FieldModel : public QAbstractTableModel
public: public:
explicit FieldModel(QObject *parent = nullptr); explicit FieldModel(QObject *parent = nullptr);
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS #ifdef PASSWORD_MANAGER_UNDO_SUPPORT
explicit FieldModel(QUndoStack *undoStack, QObject *parent = nullptr); explicit FieldModel(QUndoStack *undoStack, QObject *parent = nullptr);
#endif #endif
@ -139,7 +139,7 @@ inline void FieldModel::setPasswordVisibility(PasswordVisibility passwordVisibil
{ {
m_passwordVisibility = passwordVisibility; m_passwordVisibility = passwordVisibility;
if (m_fields) { if (m_fields) {
emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector<int>() << Qt::DisplayRole << Qt::EditRole); emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector<int>({Qt::DisplayRole, Qt::EditRole}));
} }
} }
} // namespace QtGui } // namespace QtGui

View File

@ -13,10 +13,7 @@
QT_FORWARD_DECLARE_CLASS(QSettings) QT_FORWARD_DECLARE_CLASS(QSettings)
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI) #if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_ENABLE_UNDO_SUPPORT_FOR_QUICK_GUI)
#define PASSWORD_MANAGER_UNDO_SUPPORT #include "../gui/stacksupport.h"
#include <QUndoStack>
#else
QT_FORWARD_DECLARE_CLASS(QUndoStack)
#endif #endif
namespace QtGui { namespace QtGui {