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