Resolves #1313 What this commit does: * Whenever the Apply button is pressed, and if the save was successful, then the Apply button is disabled. * Each subwidget used by EditEntryWidget has now a signal called `widgetUpdated` that is emitted when the widgets' internal content changes. The EditEntryWidget subscribes to that signal to know when to enable the Apply button (by calling `entryUpdated()`). * There are some views that are not isolated in their own widgets (`m_advancedUi`, for example) so in those cases I invoked `entryUpdated()` directly whenever I detected an update: * some updates occur directly in a Qt widget like when editing the text of a QLineItem, so in that case I connected the widget's signals directly to the `entryUpdated()` slot. * some updates occur in EditEntryWidget, so in those cases the invocation to `entryUpdated()` is made as soon as the change is detected (for example when the user has confirmed an action in a dialog). A known problem: there are some situations when the Apply button will get enabled even if there are no changes, this is because the app changes the value of a field by itself so it's considered an update (for example, clicking on the "Reveal" button changes the text shown in a text field). The solution to this can be a bit complicated: disabling temporarily the `entryUpdated()` whenever the app is going to do an action with such side-effects. So I preferred to let the Apply button get enabled in those cases.
66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#ifndef ENTRYATTACHMENTSWIDGET_H
|
|
#define ENTRYATTACHMENTSWIDGET_H
|
|
|
|
#include <QPointer>
|
|
#include <QWidget>
|
|
|
|
namespace Ui {
|
|
class EntryAttachmentsWidget;
|
|
}
|
|
|
|
class QByteArray;
|
|
class EntryAttachments;
|
|
class EntryAttachmentsModel;
|
|
|
|
class EntryAttachmentsWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged)
|
|
Q_PROPERTY(bool isButtonsVisible READ isButtonsVisible WRITE setButtonsVisible NOTIFY buttonsVisibleChanged)
|
|
public:
|
|
explicit EntryAttachmentsWidget(QWidget* parent = nullptr);
|
|
~EntryAttachmentsWidget();
|
|
|
|
const EntryAttachments* entryAttachments() const;
|
|
bool isReadOnly() const;
|
|
bool isButtonsVisible() const;
|
|
|
|
QByteArray getAttachment(const QString& name);
|
|
void setAttachment(const QString& name, const QByteArray& value);
|
|
void removeAttachment(const QString& name);
|
|
|
|
public slots:
|
|
void setEntryAttachments(const EntryAttachments* attachments);
|
|
void clearAttachments();
|
|
void setReadOnly(bool readOnly);
|
|
void setButtonsVisible(bool isButtonsVisible);
|
|
|
|
signals:
|
|
void errorOccurred(const QString& error);
|
|
void readOnlyChanged(bool readOnly);
|
|
void buttonsVisibleChanged(bool isButtonsVisible);
|
|
void widgetUpdated();
|
|
|
|
private slots:
|
|
void insertAttachments();
|
|
void removeSelectedAttachments();
|
|
void saveSelectedAttachments();
|
|
void openAttachment(const QModelIndex& index);
|
|
void openSelectedAttachments();
|
|
void updateButtonsEnabled();
|
|
|
|
private:
|
|
bool insertAttachments(const QStringList& fileNames, QString& errorMessage);
|
|
bool openAttachment(const QModelIndex& index, QString& errorMessage);
|
|
|
|
bool eventFilter(QObject* watched, QEvent* event) override;
|
|
|
|
QScopedPointer<Ui::EntryAttachmentsWidget> m_ui;
|
|
QPointer<EntryAttachments> m_entryAttachments;
|
|
QPointer<EntryAttachmentsModel> m_attachmentsModel;
|
|
bool m_readOnly;
|
|
bool m_buttonsVisible;
|
|
};
|
|
|
|
#endif // ENTRYATTACHMENTSWIDGET_H
|