/** Perform filtering on foreign keys. */ void tst_QDjangoModel::filterRelated() { // load fixtures { Item *item1 = new Item; item1->setName("first"); QCOMPARE(item1->save(), true); Item *item2 = new Item; item2->setName("second"); QCOMPARE(item2->save(), true); Owner owner; owner.setName("owner"); owner.setItem1(item1); owner.setItem2(item2); QCOMPARE(owner.save(), true); } // perform filtering QDjangoQuerySet<Owner> owners; QDjangoQuerySet<Owner> qs = owners.filter( QDjangoWhere("item1__name", QDjangoWhere::Equals, "first")); CHECKWHERE(qs.where(), QLatin1String("T0.\"name\" = ?"), QVariantList() << "first"); QCOMPARE(qs.count(), 1); QCOMPARE(qs.size(), 1); Owner *owner = qs.at(0); QVERIFY(owner != 0); QCOMPARE(owner->name(), QLatin1String("owner")); delete owner; }
void UserManager::updateUser(const Owner &owner, QTreeWidgetItem *groupItem) { // qtreewidget 不能设置model,只好构造一个userTreeWidget类来更新用户 QTreeWidgetItem* item = new QTreeWidgetItem(groupItem); groupItem->addChild(item); UserItemWidget *userItemWidget = new UserItemWidget(owner.name(), owner.ip(), item, Macai::userTreeWidget); userItemWidget->setLoginName(owner.loginName()); userItemWidget->setHostName(owner.host()); userItemWidget->setUserGroup(groupItem->text(0)); Macai::userTreeWidget->setItemWidget(item, 0, userItemWidget); }