need to modify item delegate to properly hide passwords when editing
This commit is contained in:
parent
4bbb82d898
commit
2e522b44ad
|
@ -0,0 +1,38 @@
|
|||
#include "fielddelegate.h"
|
||||
|
||||
#include "../model/fieldmodel.h"
|
||||
|
||||
#include <passwordfile/io/field.h>
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
using namespace std;
|
||||
using namespace Io;
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
FieldDelegate::FieldDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
{}
|
||||
|
||||
void FieldDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if(auto *lineEdit = qobject_cast<QLineEdit *>(editor)) {
|
||||
const auto *model = index.model();
|
||||
lineEdit->setText(model->data(index, Qt::EditRole).toString());
|
||||
if(const auto *fieldModel = qobject_cast<const FieldModel *>(model)) {
|
||||
if(fieldModel->passwordVisibility() == PasswordVisibility::Never) {
|
||||
lineEdit->setEchoMode(fieldModel->field(static_cast<size_t>(index.row()))->type() != FieldType::Password ? QLineEdit::Normal : QLineEdit::Password);
|
||||
} else {
|
||||
lineEdit->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
} else {
|
||||
lineEdit->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
} else {
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace QtGui
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef QTGUI_FIELDDELEGATE_H
|
||||
#define QTGUI_FIELDDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
class FieldDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
FieldDelegate(QObject *parent = nullptr);
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
};
|
||||
|
||||
} // namespace QtGui
|
||||
|
||||
#endif // QTGUI_FIELDDELEGATE_H
|
|
@ -1,4 +1,5 @@
|
|||
#include "./mainwindow.h"
|
||||
#include "./fielddelegate.h"
|
||||
|
||||
#include "../model/fieldmodel.h"
|
||||
#include "../model/entrymodel.h"
|
||||
|
@ -18,16 +19,12 @@
|
|||
#include <QMessageBox>
|
||||
#include <QInputDialog>
|
||||
#include <QDesktopServices>
|
||||
#include <QAction>
|
||||
#include <QActionGroup>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QClipboard>
|
||||
#include <QSettings>
|
||||
#include <QCloseEvent>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QTimerEvent>
|
||||
#include <QPushButton>
|
||||
#include <QHeaderView>
|
||||
#include <QUndoStack>
|
||||
#include <QUndoView>
|
||||
#include <QMimeData>
|
||||
|
@ -143,6 +140,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
// setup models, tree and table view
|
||||
m_ui->treeView->setModel(m_entryFilterModel = new EntryFilterModel(this));
|
||||
m_ui->tableView->setModel(m_fieldModel = new FieldModel(m_undoStack, this));
|
||||
m_ui->tableView->setItemDelegate(new FieldDelegate(this));
|
||||
m_entryFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_entryFilterModel->setSourceModel(m_entryModel = new EntryModel(m_undoStack, this));
|
||||
#ifdef Q_OS_WIN32
|
||||
|
|
|
@ -191,6 +191,9 @@
|
|||
<string>Fi&le</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuRecent">
|
||||
<property name="toolTip">
|
||||
<string>Recently opened files</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>&Recent</string>
|
||||
</property>
|
||||
|
@ -246,6 +249,9 @@
|
|||
<string>&View</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuPassword_visibility">
|
||||
<property name="toolTip">
|
||||
<string>Sets the visibility of fields marked as "password field"</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Password &visibility</string>
|
||||
</property>
|
||||
|
@ -432,6 +438,9 @@
|
|||
<property name="text">
|
||||
<string>&Export ...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Export passwords to plain text files</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShowContainingDirectory">
|
||||
<property name="icon">
|
||||
|
@ -489,7 +498,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>show always</string>
|
||||
<string>&show always</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShowOnlyWhenEditing">
|
||||
|
@ -497,7 +506,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>show only when editing</string>
|
||||
<string>show &only when editing</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionHideAlways">
|
||||
|
@ -505,7 +514,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>hide always</string>
|
||||
<string>&hide always</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
|
|
@ -76,24 +76,12 @@ QVariant FieldModel::data(const QModelIndex &index, int role) const
|
|||
switch(index.column()) {
|
||||
case 0:
|
||||
return QString::fromStdString(m_fields->at(index.row()).name());
|
||||
case 1: {
|
||||
bool showPassword = m_fields->at(index.row()).type() != FieldType::Password;
|
||||
if(!showPassword) {
|
||||
switch(m_passwordVisibility) {
|
||||
case PasswordVisibility::Always:
|
||||
showPassword = true;
|
||||
break;
|
||||
case PasswordVisibility::OnlyWhenEditing:
|
||||
showPassword = role == Qt::EditRole;
|
||||
break;
|
||||
case PasswordVisibility::Never:
|
||||
showPassword = false;
|
||||
}
|
||||
}
|
||||
return showPassword
|
||||
case 1:
|
||||
return (m_passwordVisibility == PasswordVisibility::Always
|
||||
|| role == Qt::EditRole
|
||||
|| m_fields->at(index.row()).type() != FieldType::Password)
|
||||
? QString::fromStdString(m_fields->at(index.row()).value())
|
||||
: QString(m_fields->at(index.row()).value().size(), QChar(0x2022));
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ guiqtwidgets {
|
|||
gui/passwordgeneratordialog.cpp \
|
||||
gui/undocommands.cpp \
|
||||
gui/stacksupport.cpp \
|
||||
gui/initiatequi.cpp
|
||||
gui/initiatequi.cpp \
|
||||
gui/fielddelegate.cpp
|
||||
|
||||
FORMS += gui/mainwindow.ui \
|
||||
gui/passwordgeneratordialog.ui
|
||||
|
@ -57,14 +58,15 @@ HEADERS += model/entrymodel.h \
|
|||
model/fieldmodel.h \
|
||||
model/entryfiltermodel.h \
|
||||
util/testroutines.h \
|
||||
cli/cli.h \
|
||||
gui/initiategui.h
|
||||
cli/cli.h
|
||||
|
||||
guiqtwidgets {
|
||||
HEADERS += gui/mainwindow.h \
|
||||
gui/passwordgeneratordialog.h \
|
||||
gui/undocommands.h \
|
||||
gui/stacksupport.h
|
||||
gui/stacksupport.h \
|
||||
gui/initiategui.h \
|
||||
gui/fielddelegate.h
|
||||
}
|
||||
|
||||
guiqtquick {
|
||||
|
|
Loading…
Reference in New Issue