mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-12 00:11:37 -04:00
Icon model fixes.
This commit is contained in:
parent
0d2ce4c038
commit
8204f2007a
4 changed files with 28 additions and 26 deletions
|
@ -177,7 +177,6 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupN
|
||||||
int iconNumber = entry->iconNumber();
|
int iconNumber = entry->iconNumber();
|
||||||
m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
|
m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
|
||||||
m_iconsUi->defaultIconsRadio->setChecked(true);
|
m_iconsUi->defaultIconsRadio->setChecked(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QModelIndex index = m_customIconModel->indexFromUuid(iconUuid);
|
QModelIndex index = m_customIconModel->indexFromUuid(iconUuid);
|
||||||
|
@ -425,16 +424,17 @@ void EditEntryWidget::addCustomIcon()
|
||||||
if (m_metadata) {
|
if (m_metadata) {
|
||||||
QString filename = QFileDialog::getOpenFileName(
|
QString filename = QFileDialog::getOpenFileName(
|
||||||
this, tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
|
this, tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
|
||||||
|
if (!filename.isEmpty()) {
|
||||||
QImage image(filename);
|
QImage image(filename);
|
||||||
if (!image.isNull()) {
|
if (!image.isNull()) {
|
||||||
m_metadata->addCustomIcon(Uuid::random(), image.scaled(16, 16));
|
m_metadata->addCustomIcon(Uuid::random(), image.scaled(16, 16));
|
||||||
m_customIconModel->setIcons(m_metadata->customIcons());
|
m_customIconModel->setIcons(m_metadata->customIcons());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
; // TODO show error
|
// TODO: show error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditEntryWidget::removeCustomIcon()
|
void EditEntryWidget::removeCustomIcon()
|
||||||
|
@ -442,12 +442,10 @@ void EditEntryWidget::removeCustomIcon()
|
||||||
if (m_metadata) {
|
if (m_metadata) {
|
||||||
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
|
// TODO: check if the icon is used in history items or other entries
|
||||||
m_metadata->removeCustomIcon(m_customIconModel->uuidFromIndex(index));
|
m_metadata->removeCustomIcon(m_customIconModel->uuidFromIndex(index));
|
||||||
m_customIconModel->setIcons(m_metadata->customIcons());
|
m_customIconModel->setIcons(m_metadata->customIcons());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// TODO show error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,8 +453,7 @@ void EditEntryWidget::updateIndexDefaultIcons(bool check)
|
||||||
{
|
{
|
||||||
if (check) {
|
if (check) {
|
||||||
QModelIndex index = m_iconsUi->defaultIconsView->currentIndex();
|
QModelIndex index = m_iconsUi->defaultIconsView->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid()) {
|
||||||
{
|
|
||||||
m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
|
m_iconsUi->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,9 +463,8 @@ void EditEntryWidget::updateIndexCustomIcons(bool check)
|
||||||
{
|
{
|
||||||
if (check) {
|
if (check) {
|
||||||
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
QModelIndex index = m_iconsUi->customIconsView->currentIndex();
|
||||||
if (!index.isValid())
|
if (!index.isValid()) {
|
||||||
{
|
m_iconsUi->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0));
|
||||||
m_iconsUi->customIconsView->setCurrentIndex(m_customIconModel->index(0, 0));;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
<height>300</height>
|
<height>300</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Form</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRadioButton" name="defaultIconsRadio">
|
<widget class="QRadioButton" name="defaultIconsRadio">
|
||||||
|
|
|
@ -26,8 +26,12 @@ DefaultIconModel::DefaultIconModel(QObject* parent) :
|
||||||
|
|
||||||
int DefaultIconModel::rowCount(const QModelIndex& parent) const
|
int DefaultIconModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
if (!parent.isValid()) {
|
||||||
return databaseIcons()->iconCount();
|
return databaseIcons()->iconCount();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
|
QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
|
||||||
|
@ -69,8 +73,12 @@ void CustomIconModel::setIcons(QHash<Uuid, QImage> icons)
|
||||||
|
|
||||||
int CustomIconModel::rowCount(const QModelIndex& parent) const
|
int CustomIconModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
if (!parent.isValid()) {
|
||||||
return m_icons.size();
|
return m_icons.size();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CustomIconModel::data(const QModelIndex& index, int role) const
|
QVariant CustomIconModel::data(const QModelIndex& index, int role) const
|
||||||
|
@ -98,7 +106,7 @@ QModelIndex CustomIconModel::indexFromUuid(const Uuid& uuid) const
|
||||||
QHash<int, Uuid>::const_iterator iter;
|
QHash<int, Uuid>::const_iterator iter;
|
||||||
for (iter = m_uuids.constBegin(); iter != m_uuids.constEnd(); ++iter) {
|
for (iter = m_uuids.constBegin(); iter != m_uuids.constEnd(); ++iter) {
|
||||||
if (iter.value() == uuid) {
|
if (iter.value() == uuid) {
|
||||||
return createIndex(iter.key(), 0);
|
return index(iter.key(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
class DefaultIconModel : public QAbstractListModel
|
class DefaultIconModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DefaultIconModel(QObject* parent = 0);
|
explicit DefaultIconModel(QObject* parent = 0);
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ public:
|
||||||
class CustomIconModel : public QAbstractListModel
|
class CustomIconModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CustomIconModel(QObject* parent = 0);
|
explicit CustomIconModel(QObject* parent = 0);
|
||||||
|
|
||||||
|
@ -48,7 +50,6 @@ public:
|
||||||
private:
|
private:
|
||||||
QHash<Uuid, QImage> m_icons;
|
QHash<Uuid, QImage> m_icons;
|
||||||
QHash<int, Uuid> m_uuids;
|
QHash<int, Uuid> m_uuids;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_ICONMODELS_H
|
#endif // KEEPASSX_ICONMODELS_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue