Quick GUI: Support undo/redo
so far this requires to compile with widgets GUI support
This commit is contained in:
parent
a69a91d47e
commit
776dc06431
20
qml/main.qml
20
qml/main.qml
|
@ -167,12 +167,30 @@ Kirigami.ApplicationWindow {
|
||||||
}
|
}
|
||||||
shortcut: "Ctrl+Shift+F"
|
shortcut: "Ctrl+Shift+F"
|
||||||
},
|
},
|
||||||
|
Kirigami.Action {
|
||||||
|
text: qsTr("Undo \"%1\"").arg(nativeInterface.undoText)
|
||||||
|
visible: nativeInterface.undoText.length !== 0
|
||||||
|
&& nativeInterface.entryFilter.length === 0
|
||||||
|
enabled: visible
|
||||||
|
iconName: "edit-undo"
|
||||||
|
shortcut: StandardKey.Undo
|
||||||
|
onTriggered: nativeInterface.undo()
|
||||||
|
},
|
||||||
|
Kirigami.Action {
|
||||||
|
text: qsTr("Redo \"%1\"").arg(nativeInterface.redoText)
|
||||||
|
visible: nativeInterface.redoText.length !== 0
|
||||||
|
&& nativeInterface.entryFilter.length === 0
|
||||||
|
enabled: visible
|
||||||
|
iconName: "edit-redo"
|
||||||
|
shortcut: StandardKey.Redo
|
||||||
|
onTriggered: nativeInterface.redo()
|
||||||
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: qsTr("Close file")
|
text: qsTr("Close file")
|
||||||
enabled: nativeInterface.fileOpen
|
enabled: nativeInterface.fileOpen
|
||||||
iconName: "document-close"
|
iconName: "document-close"
|
||||||
onTriggered: nativeInterface.close()
|
|
||||||
shortcut: StandardKey.Close
|
shortcut: StandardKey.Close
|
||||||
|
onTriggered: nativeInterface.close()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Controls.Switch {
|
Controls.Switch {
|
||||||
|
|
|
@ -36,6 +36,10 @@ namespace QtGui {
|
||||||
Controller::Controller(QSettings &settings, const QString &filePath, QObject *parent)
|
Controller::Controller(QSettings &settings, const QString &filePath, QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_settings(settings)
|
, m_settings(settings)
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
, m_entryModel(&m_undoStack)
|
||||||
|
, m_fieldModel(&m_undoStack)
|
||||||
|
#endif
|
||||||
, m_fileOpen(false)
|
, m_fileOpen(false)
|
||||||
, m_fileModified(false)
|
, m_fileModified(false)
|
||||||
, m_useNativeFileDialog(false)
|
, m_useNativeFileDialog(false)
|
||||||
|
@ -51,6 +55,11 @@ Controller::Controller(QSettings &settings, const QString &filePath, QObject *pa
|
||||||
m_entryFilterModel.setSourceModel(&m_entryModel);
|
m_entryFilterModel.setSourceModel(&m_entryModel);
|
||||||
connect(&m_entryModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &Controller::handleEntriesRemoved);
|
connect(&m_entryModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &Controller::handleEntriesRemoved);
|
||||||
|
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
connect(&m_undoStack, &QUndoStack::undoTextChanged, this, &Controller::undoTextChanged);
|
||||||
|
connect(&m_undoStack, &QUndoStack::redoTextChanged, this, &Controller::redoTextChanged);
|
||||||
|
#endif
|
||||||
|
|
||||||
// share settings with main window
|
// share settings with main window
|
||||||
m_settings.beginGroup(QStringLiteral("mainwindow"));
|
m_settings.beginGroup(QStringLiteral("mainwindow"));
|
||||||
m_recentFiles = m_settings.value(QStringLiteral("recententries")).toStringList();
|
m_recentFiles = m_settings.value(QStringLiteral("recententries")).toStringList();
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||||
|
|
||||||
|
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||||
|
#define PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
#include <QUndoStack>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
|
||||||
class Controller : public QObject {
|
class Controller : public QObject {
|
||||||
|
@ -37,6 +42,9 @@ class Controller : public QObject {
|
||||||
Q_PROPERTY(QString entryFilter READ entryFilter WRITE setEntryFilter NOTIFY entryFilterChanged)
|
Q_PROPERTY(QString entryFilter READ entryFilter WRITE setEntryFilter NOTIFY entryFilterChanged)
|
||||||
Q_PROPERTY(bool hasEntryFilter READ hasEntryFilter NOTIFY hasEntryFilterChanged)
|
Q_PROPERTY(bool hasEntryFilter READ hasEntryFilter NOTIFY hasEntryFilterChanged)
|
||||||
Q_PROPERTY(bool filterAsDialog READ filterAsDialog NOTIFY filterAsDialogChanged)
|
Q_PROPERTY(bool filterAsDialog READ filterAsDialog NOTIFY filterAsDialogChanged)
|
||||||
|
Q_PROPERTY(QUndoStack *undoStack READ undoStack NOTIFY undoStackChanged)
|
||||||
|
Q_PROPERTY(QString undoText READ undoText NOTIFY undoTextChanged)
|
||||||
|
Q_PROPERTY(QString redoText READ redoText NOTIFY redoTextChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Controller(QSettings &settings, const QString &filePath = QString(), QObject *parent = nullptr);
|
explicit Controller(QSettings &settings, const QString &filePath = QString(), QObject *parent = nullptr);
|
||||||
|
@ -75,6 +83,9 @@ public:
|
||||||
void setEntryFilter(const QString &filter);
|
void setEntryFilter(const QString &filter);
|
||||||
bool hasEntryFilter() const;
|
bool hasEntryFilter() const;
|
||||||
bool filterAsDialog() const;
|
bool filterAsDialog() const;
|
||||||
|
QUndoStack *undoStack();
|
||||||
|
QString undoText() const;
|
||||||
|
QString redoText() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void init();
|
void init();
|
||||||
|
@ -88,6 +99,8 @@ public slots:
|
||||||
void handleFileSelectionAcceptedDescriptor(const QString &nativeUrl, const QString &fileName, int fileDescriptor, bool existing);
|
void handleFileSelectionAcceptedDescriptor(const QString &nativeUrl, const QString &fileName, int fileDescriptor, bool existing);
|
||||||
#endif
|
#endif
|
||||||
void handleFileSelectionCanceled();
|
void handleFileSelectionCanceled();
|
||||||
|
void undo();
|
||||||
|
void redo();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void filePathChanged(const QString &newFilePath);
|
void filePathChanged(const QString &newFilePath);
|
||||||
|
@ -110,6 +123,9 @@ signals:
|
||||||
void entryFilterChanged(const QString &newFilter);
|
void entryFilterChanged(const QString &newFilter);
|
||||||
void hasEntryFilterChanged(bool hasEntryFilter);
|
void hasEntryFilterChanged(bool hasEntryFilter);
|
||||||
void filterAsDialogChanged(bool filterAsDialog);
|
void filterAsDialogChanged(bool filterAsDialog);
|
||||||
|
void undoStackChanged(QUndoStack *undoStack);
|
||||||
|
void undoTextChanged(const QString &undoText);
|
||||||
|
void redoTextChanged(const QString &redoText);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last);
|
void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last);
|
||||||
|
@ -128,6 +144,9 @@ private:
|
||||||
QString m_password;
|
QString m_password;
|
||||||
QString m_windowTitle;
|
QString m_windowTitle;
|
||||||
Io::PasswordFile m_file;
|
Io::PasswordFile m_file;
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
QUndoStack m_undoStack;
|
||||||
|
#endif
|
||||||
EntryModel m_entryModel;
|
EntryModel m_entryModel;
|
||||||
EntryFilterModel m_entryFilterModel;
|
EntryFilterModel m_entryFilterModel;
|
||||||
FieldModel m_fieldModel;
|
FieldModel m_fieldModel;
|
||||||
|
@ -288,6 +307,47 @@ inline bool Controller::filterAsDialog() const
|
||||||
return m_filterAsDialog;
|
return m_filterAsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QUndoStack *Controller::undoStack()
|
||||||
|
{
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
return &m_undoStack;
|
||||||
|
#else
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString Controller::undoText() const
|
||||||
|
{
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
return m_undoStack.undoText();
|
||||||
|
#else
|
||||||
|
return QString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString Controller::redoText() const
|
||||||
|
{
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
return m_undoStack.redoText();
|
||||||
|
#else
|
||||||
|
return QString();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Controller::undo()
|
||||||
|
{
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
return m_undoStack.undo();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Controller::redo()
|
||||||
|
{
|
||||||
|
#ifdef PASSWORD_MANAGER_UNDO_SUPPORT
|
||||||
|
return m_undoStack.redo();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QtGui
|
} // namespace QtGui
|
||||||
|
|
||||||
#endif // QT_QUICK_GUI_CONTROLLER_H
|
#endif // QT_QUICK_GUI_CONTROLLER_H
|
||||||
|
|
Loading…
Reference in New Issue