Fix enabling undo support without Qt Widgets GUI
This commit is contained in:
parent
06c280768d
commit
78a868fc9e
|
@ -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()
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#define PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
class StackAbsorper;
|
||||
|
|
|
@ -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<int, QVariant> 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<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)
|
||||
{
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
if (undoStack()) {
|
||||
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)
|
||||
{
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
if (undoStack()) {
|
||||
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)
|
||||
{
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
if (undoStack()) {
|
||||
return push(make_unique<EntryModelMoveRowsCommand>(this, sourceParent, sourceRow, count, destinationParent, destinationChild));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<int, QVariant> 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<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)
|
||||
{
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
if (undoStack()) {
|
||||
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)
|
||||
{
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||
if (undoStack()) {
|
||||
return push(make_unique<FieldModelRemoveRowsCommand>(this, row, count));
|
||||
}
|
||||
|
|
|
@ -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<int>() << Qt::DisplayRole << Qt::EditRole);
|
||||
emit dataChanged(index(0, 1), index(m_fields->size() - 1, 1), QVector<int>({Qt::DisplayRole, Qt::EditRole}));
|
||||
}
|
||||
}
|
||||
} // namespace QtGui
|
||||
|
|
|
@ -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 <QUndoStack>
|
||||
#else
|
||||
QT_FORWARD_DECLARE_CLASS(QUndoStack)
|
||||
#include "../gui/stacksupport.h"
|
||||
#endif
|
||||
|
||||
namespace QtGui {
|
||||
|
|
Loading…
Reference in New Issue