void TestEntryModel::testCustomIconModel() { CustomIconModel* model = new CustomIconModel(this); ModelTest* modelTest = new ModelTest(model, this); QCOMPARE(model->rowCount(), 0); QHash<Uuid, QImage> icons; QList<Uuid> iconsOrder; Uuid iconUuid(QByteArray(16, '2')); QImage icon; icons.insert(iconUuid, icon); iconsOrder << iconUuid; Uuid iconUuid2(QByteArray(16, '1')); QImage icon2; icons.insert(iconUuid2, icon2); iconsOrder << iconUuid2; model->setIcons(icons, iconsOrder); QCOMPARE(model->uuidFromIndex(model->index(0, 0)), iconUuid); QCOMPARE(model->uuidFromIndex(model->index(1, 0)), iconUuid2); delete modelTest; delete model; }
void Group::setParent(Group* parent, int index) { Q_ASSERT(parent); Q_ASSERT(index >= -1 && index <= parent->children().size()); // setting a new parent for root groups is not allowed Q_ASSERT(!m_db || (m_db->rootGroup() != this)); bool moveWithinDatabase = (m_db && m_db == parent->m_db); if (index == -1) { index = parent->children().size(); if (parentGroup() == parent) { index--; } } if (m_parent == parent && parent->children().indexOf(this) == index) { return; } if (!moveWithinDatabase) { cleanupParent(); m_parent = parent; if (m_db) { recCreateDelObjects(); // copy custom icon to the new database if (!iconUuid().isNull() && parent->m_db && m_db->metadata()->containsCustomIcon(iconUuid()) && !parent->m_db->metadata()->containsCustomIcon(iconUuid())) { parent->m_db->metadata()->addCustomIcon(iconUuid(), icon()); } } if (m_db != parent->m_db) { recSetDatabase(parent->m_db); } QObject::setParent(parent); Q_EMIT aboutToAdd(this, index); Q_ASSERT(index <= parent->m_children.size()); parent->m_children.insert(index, this); } else { Q_EMIT aboutToMove(this, parent, index); m_parent->m_children.removeAll(this); m_parent = parent; QObject::setParent(parent); Q_ASSERT(index <= parent->m_children.size()); parent->m_children.insert(index, this); } if (m_updateTimeinfo) { m_data.timeInfo.setLocationChanged(Tools::currentDateTimeUtc()); } Q_EMIT modified(); if (!moveWithinDatabase) { Q_EMIT added(); } else { Q_EMIT moved(); } }