/** 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; }
static void saveMessage(const QXmppMessage &message, const QDateTime &now, bool received) { const QString localJid = QXmppUtils::jidToBareJid(received ? message.to() : message.from()); const QString remoteJid = QXmppUtils::jidToBareJid(received ? message.from() : message.to()); // get or create collection int chatId; QDjangoQuerySet<ArchiveMessage> qs; qs = qs.filter(QDjangoWhere("chat__jid", QDjangoWhere::Equals, localJid)); qs = qs.filter(QDjangoWhere("chat__with", QDjangoWhere::Equals, remoteJid)); qs = qs.orderBy(QStringList() << "-date").limit(0, 1); ArchiveMessage tmp; if (qs.size() > 0 && qs.at(0, &tmp) && tmp.date().secsTo(now) < 3600) { chatId = tmp.property("chat_id").toInt(); } else { ArchiveChat chat; chat.setJid(localJid); chat.setWith(remoteJid); chat.setStart(now); chat.save(); chatId = chat.pk().toInt(); } // save outgoing message ArchiveMessage msg; msg.setProperty("chat_id", chatId); msg.setBody(message.body()); msg.setDate(now); msg.setReceived(received); msg.save(); }
void GroupsWidget::renderData() { FUNCTION QDjangoQuerySet<Group> gqs = QDjangoQuerySet<Group>().all(); ui->groupsTW->setRowCount(gqs.size()); for(qint32 i = 0; i < gqs.size(); ++i) { Group* group = gqs.at(i); _groups.append(group); QTableWidgetItem* item0 = new QTableWidgetItem(group->name()); Normal* normal = QDjangoQuerySet<Normal>().get(QDjangoWhere("group_id", QDjangoWhere::Equals, group->pk())); QTableWidgetItem* item1 = new QTableWidgetItem(QString::number(normal->speed())); qint32 userCount = QDjangoQuerySet<User>().filter(QDjangoWhere("group_id", QDjangoWhere::Equals, group->pk())).size(); QTableWidgetItem* item2 = new QTableWidgetItem(QString::number(userCount)); ui->groupsTW->setItem(i, 0, item0); ui->groupsTW->setItem(i, 1, item1); ui->groupsTW->setItem(i, 2, item2); } }
QString LoggerSettingsModel::getCurrentName() { QDjangoQuerySet<LoggerSettingsQDjangoModel> settings; LoggerSettingsQDjangoModel setting; for (int i = 0; i < settings.size(); ++i) { if (settings.at(i, &setting)) { return setting.currentLoggerName(); } } return QString(""); }
bool NouveauxProduitsDialog::existe( QString code ) { QDjangoQuerySet< Core::Produit > produits; int l = produits.size(); for( int i = 0; i < l; ++i ) { Core::Produit *p = produits.at( i ); if( p->getCode() == code ) return true; } return false; }
void LoggerSettingsModel::setCurrentName(const QString ¤tName) { QDjangoQuerySet<LoggerSettingsQDjangoModel> settings; for (int i = 0; i < settings.size(); ++i) { LoggerSettingsQDjangoModel setting; if (settings.at(i, &setting)) { setting.setCurrentLoggerName(currentName); setting.save(); return; } } LoggerSettingsQDjangoModel *setting = new LoggerSettingsQDjangoModel; setting->setCurrentLoggerName(currentName); setting->save(); }
void NouveauxProduitsDialog::on_btValider_clicked() { QDjangoQuerySet< Core::Temp > produits; int l = produits.size(); for( int i = 0; i < l; ++i ) { Core::Temp *t = produits.at( i ); Core::Produit *p = new Core::Produit(); p->setCode( t->getCode() ); p->setConstructeur( t->getConstructeur() ); p->setNom( t->getNom() ); p->setDescription( t->getDescription() ); p->setType( t->getType() ); p->setPrixUnitaire( t->getPrixUnitaire() ); p->save(); } produits.remove(); }
void rsmFilter(QDjangoQuerySet<T1> &qs, const QXmppResultSetQuery &rsmQuery, QList<T2> &results, QXmppResultSetReply &rsmReply) { // if count was requested, stop here if (rsmQuery.max() == 0) { rsmReply.setCount(qs.count()); return; } rsmReply.setCount(qs.size()); T1 result; if (rsmQuery.before().isNull()) { // page forwards bool rsmAfterReached = rsmQuery.after().isEmpty(); for (int i = 0; i < qs.size(); ++i) { if (rsmQuery.max() >= 0 && results.size() >= rsmQuery.max()) break; // fetch from database if (!qs.at(i, &result)) break; const QString uid = result.pk().toString(); // if an "after" was specified, check it was reached if (!rsmAfterReached) { if (uid == rsmQuery.after()) rsmAfterReached = true; continue; } if (results.isEmpty()) { rsmReply.setFirst(uid); rsmReply.setIndex(i); } rsmReply.setLast(uid); results << result; } } else { // page backwards bool rsmBeforeReached = rsmQuery.before().isEmpty(); for (int i = qs.size() - 1; i >= 0; --i) { if (rsmQuery.max() >= 0 && results.size() >= rsmQuery.max()) break; // fetch from database if (!qs.at(i, &result)) break; const QString uid = result.pk().toString(); // if a "before" was specified, check it was reached if (!rsmBeforeReached) { if (uid == rsmQuery.before()) rsmBeforeReached = true; continue; } if (results.isEmpty()) rsmReply.setLast(uid); rsmReply.setFirst(uid); rsmReply.setIndex(i); results.prepend(result); } } }