mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-22 05:34:40 -04:00
parent
e53850627f
commit
bbdfbe64da
7 changed files with 64 additions and 0 deletions
|
@ -112,6 +112,13 @@ void EntryAttachments::remove(const QStringList& keys)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntryAttachments::rename(const QString& key, const QString& newKey)
|
||||||
|
{
|
||||||
|
const QByteArray val = value(key);
|
||||||
|
remove(key);
|
||||||
|
set(newKey, val);
|
||||||
|
}
|
||||||
|
|
||||||
bool EntryAttachments::isEmpty() const
|
bool EntryAttachments::isEmpty() const
|
||||||
{
|
{
|
||||||
return m_attachments.isEmpty();
|
return m_attachments.isEmpty();
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
void set(const QString& key, const QByteArray& value);
|
void set(const QString& key, const QByteArray& value);
|
||||||
void remove(const QString& key);
|
void remove(const QString& key);
|
||||||
void remove(const QStringList& keys);
|
void remove(const QStringList& keys);
|
||||||
|
void rename(const QString& key, const QString& newKey);
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
void clear();
|
void clear();
|
||||||
void copyDataFrom(const EntryAttachments* other);
|
void copyDataFrom(const EntryAttachments* other);
|
||||||
|
|
|
@ -101,6 +101,28 @@ QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EntryAttachmentsModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
|
{
|
||||||
|
if (!m_readOnly && index.column() == Columns::NameColumn) {
|
||||||
|
const QString key = value.toString().trimmed();
|
||||||
|
if (key.isEmpty() || m_entryAttachments->hasKey(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_entryAttachments->rename(keyByIndex(index), key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QAbstractListModel::setData(index, value, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags EntryAttachmentsModel::flags(const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
Qt::ItemFlags flags = QAbstractListModel::flags(index);
|
||||||
|
if (!m_readOnly && index.column() == Columns::NameColumn) {
|
||||||
|
flags = flags | Qt::ItemIsEditable;
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
QString EntryAttachmentsModel::keyByIndex(const QModelIndex& index) const
|
QString EntryAttachmentsModel::keyByIndex(const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
|
@ -150,3 +172,8 @@ void EntryAttachmentsModel::reset()
|
||||||
{
|
{
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntryAttachmentsModel::setReadOnly(bool readOnly)
|
||||||
|
{
|
||||||
|
m_readOnly = readOnly;
|
||||||
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ public:
|
||||||
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||||
QString keyByIndex(const QModelIndex& index) const;
|
QString keyByIndex(const QModelIndex& index) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -50,10 +52,12 @@ private slots:
|
||||||
void attachmentRemove();
|
void attachmentRemove();
|
||||||
void aboutToReset();
|
void aboutToReset();
|
||||||
void reset();
|
void reset();
|
||||||
|
void setReadOnly(bool readOnly);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EntryAttachments* m_entryAttachments;
|
EntryAttachments* m_entryAttachments;
|
||||||
QStringList m_headers;
|
QStringList m_headers;
|
||||||
|
bool m_readOnly = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_ENTRYATTACHMENTSMODEL_H
|
#endif // KEEPASSX_ENTRYATTACHMENTSMODEL_H
|
||||||
|
|
|
@ -49,12 +49,14 @@ EntryAttachmentsWidget::EntryAttachmentsWidget(QWidget* parent)
|
||||||
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
|
||||||
SLOT(updateButtonsEnabled()));
|
SLOT(updateButtonsEnabled()));
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
connect(this, SIGNAL(readOnlyChanged(bool)), m_attachmentsModel, SLOT(setReadOnly(bool)));
|
||||||
|
|
||||||
connect(m_ui->attachmentsView, SIGNAL(doubleClicked(QModelIndex)), SLOT(openAttachment(QModelIndex)));
|
connect(m_ui->attachmentsView, SIGNAL(doubleClicked(QModelIndex)), SLOT(openAttachment(QModelIndex)));
|
||||||
connect(m_ui->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveSelectedAttachments()));
|
connect(m_ui->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveSelectedAttachments()));
|
||||||
connect(m_ui->openAttachmentButton, SIGNAL(clicked()), SLOT(openSelectedAttachments()));
|
connect(m_ui->openAttachmentButton, SIGNAL(clicked()), SLOT(openSelectedAttachments()));
|
||||||
connect(m_ui->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachments()));
|
connect(m_ui->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachments()));
|
||||||
connect(m_ui->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeSelectedAttachments()));
|
connect(m_ui->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeSelectedAttachments()));
|
||||||
|
connect(m_ui->renameAttachmentButton, SIGNAL(clicked()), SLOT(renameSelectedAttachments()));
|
||||||
|
|
||||||
updateButtonsVisible();
|
updateButtonsVisible();
|
||||||
updateButtonsEnabled();
|
updateButtonsEnabled();
|
||||||
|
@ -184,6 +186,11 @@ void EntryAttachmentsWidget::removeSelectedAttachments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntryAttachmentsWidget::renameSelectedAttachments()
|
||||||
|
{
|
||||||
|
m_ui->attachmentsView->edit(m_ui->attachmentsView->selectionModel()->selectedIndexes().first());
|
||||||
|
}
|
||||||
|
|
||||||
void EntryAttachmentsWidget::saveSelectedAttachments()
|
void EntryAttachmentsWidget::saveSelectedAttachments()
|
||||||
{
|
{
|
||||||
const QModelIndexList indexes = m_ui->attachmentsView->selectionModel()->selectedRows(0);
|
const QModelIndexList indexes = m_ui->attachmentsView->selectionModel()->selectedRows(0);
|
||||||
|
@ -289,6 +296,7 @@ void EntryAttachmentsWidget::updateButtonsEnabled()
|
||||||
|
|
||||||
m_ui->addAttachmentButton->setEnabled(!m_readOnly);
|
m_ui->addAttachmentButton->setEnabled(!m_readOnly);
|
||||||
m_ui->removeAttachmentButton->setEnabled(hasSelection && !m_readOnly);
|
m_ui->removeAttachmentButton->setEnabled(hasSelection && !m_readOnly);
|
||||||
|
m_ui->renameAttachmentButton->setEnabled(hasSelection && !m_readOnly);
|
||||||
|
|
||||||
m_ui->saveAttachmentButton->setEnabled(hasSelection);
|
m_ui->saveAttachmentButton->setEnabled(hasSelection);
|
||||||
m_ui->openAttachmentButton->setEnabled(hasSelection);
|
m_ui->openAttachmentButton->setEnabled(hasSelection);
|
||||||
|
|
|
@ -45,6 +45,7 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void insertAttachments();
|
void insertAttachments();
|
||||||
void removeSelectedAttachments();
|
void removeSelectedAttachments();
|
||||||
|
void renameSelectedAttachments();
|
||||||
void saveSelectedAttachments();
|
void saveSelectedAttachments();
|
||||||
void openAttachment(const QModelIndex& index);
|
void openAttachment(const QModelIndex& index);
|
||||||
void openSelectedAttachments();
|
void openSelectedAttachments();
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
<property name="accessibleName">
|
<property name="accessibleName">
|
||||||
<string>Attachments</string>
|
<string>Attachments</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -74,6 +77,19 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="renameAttachmentButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="accessibleName">
|
||||||
|
<string>Rename selected attachment</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rename</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="openAttachmentButton">
|
<widget class="QPushButton" name="openAttachmentButton">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue