void tst_QDjango::databaseThreaded() { if (QDjango::database().databaseName() == QLatin1String(":memory:")) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QSKIP("Threaded test cannot work with in-memory SQLite database."); #else QSKIP("Threaded test cannot work with in-memory SQLite database.", SkipAll); #endif QDjangoQuerySet<Author> qs; QCOMPARE(qs.count(), 0); QEventLoop loop; Worker worker; QThread workerThread; // fire up worker worker.moveToThread(&workerThread); connect(&worker, SIGNAL(done()), &loop, SLOT(quit())); workerThread.start(); QTimer::singleShot(0, &worker, SLOT(doIt())); loop.exec(); // check database QCOMPARE(qs.count(), 1); // stop thread workerThread.quit(); workerThread.wait(); }
void Explorer::listUpdate(){ QDjangoQuerySet <Diagnostico> idDiag ,nomeD, num01, num02, idDom, definicao, cDefin, fRelac; QList<qint32> idList; QList <int> idDomList; QStringList nameList, num01List, num02List, defList, cDList, fRelList; //! Fills QLists whit content from Diagnostico ORM for(int i = 0; i < nomeD.count() && idDiag.count() && num01.count(); ++i){ idList << idDiag.at(i)->idDiag(); num01List << num01.at(i)->num01(); nameList << nomeD.at(i)->nomeDiag(); num02List << num02.at(i)->num02(); idDomList << idDom.at(i)->idDom(); defList << definicao.at(i)->definicao(); cDList << cDefin.at(i)->cDefin(); fRelList << fRelac.at(i)->fRelac(); } //! Fills the GUI TableWidget by column from Diagnos DATA for(int i = 0; i < nameList.count(); ++i){ ui->tW_showDiagnosReadyOnly->setRowCount(nameList.count()); //ui->tW_showDiagnosReadyOnly->setItem(i, 0, new QTableWidgetItem(idList.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 0, new QTableWidgetItem(num01List.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 1, new QTableWidgetItem(nameList.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 2, new QTableWidgetItem(idDomList.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 3, new QTableWidgetItem(num02List.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 4, new QTableWidgetItem(defList.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 5, new QTableWidgetItem(cDList.at(i))); ui->tW_showDiagnosReadyOnly->setItem(i, 6, new QTableWidgetItem(fRelList.at(i))); } }
/** Test eager loading of foreign keys. */ void tst_QDjangoModel::selectRelated() { // 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); } // without eager loading QDjangoQuerySet<Owner> qs; Owner *owner = qs.get(QDjangoWhere("name", QDjangoWhere::Equals, "owner")); QVERIFY(owner != 0); QCOMPARE(owner->item1()->name(), QLatin1String("first")); QCOMPARE(owner->item2()->name(), QLatin1String("second")); delete owner; // with eager loading owner = qs.selectRelated().get(QDjangoWhere("name", QDjangoWhere::Equals, "owner")); QVERIFY(owner != 0); QCOMPARE(owner->item1()->name(), QLatin1String("first")); QCOMPARE(owner->item2()->name(), QLatin1String("second")); delete owner; }
void TestModels::test_ModelAPIs_schedule() { const QDjangoQuerySet<Schedule> schedule_set; Schedule* schedule = schedule_set.get(QDjangoWhere("id", QDjangoWhere::Equals, 2)); Schedule* schedule2 = ModelAPIs::Instance()->schedule(2); QCOMPARE(schedule->start(), schedule2->start()); }
QDjangoQuerySet<Project> DatabaseController::listProjects(QDateTime from, QDateTime to=QDateTime::currentDateTime()){ QDjangoQuerySet<Project> projects; projects = projects.filter( QDjangoWhere("start_date", QDjangoWhere::GreaterOrEquals, from) && QDjangoWhere("start_date", QDjangoWhere::LessOrEquals, to) ); return projects; }
QDjangoQuerySet<Project> DatabaseController::listProjects(bool active=false){ QDjangoQuerySet<Project> projects; if(active) projects = projects.filter( QDjangoWhere("valid_until", QDjangoWhere::GreaterOrEquals, QDateTime::currentDateTime()) ); return projects; }
void TestModels::test_ModelAPIs_lastSchedule() { const QDjangoQuerySet<Schedule> schedule_set; QList< QMap<QString, QVariant> > schedule_map = schedule_set.all().values(); QCOMPARE(schedule_map.last(), ModelAPIs::Instance()->lastSchedule()); }
void NouveauxProduitsDialog::on_btAnnuler_clicked() { QDjangoQuerySet< Core::Temp > produits; produits.remove(); produitsModel->select(); effacerChamps(); btValider->setEnabled( false ); }
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(""); }
void TestModels::test_ModelAPIs_groups() { const QDjangoQuerySet<Group> groups_set; QList< QMap<QString, QVariant> > groups_map = groups_set.all().values(); QList<QString> result; for (int i = 0; i < groups_map.count(); i++){ result << groups_map[i]["name"].toString(); } QList<QString> result2; result2 = ModelAPIs::Instance()->groups(); QCOMPARE(result, result2); }
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 NouveauxProduitsDialog::on_btTerminer_clicked() { if( QMessageBox::question( this, "Question", "Voulez-vous vraiment fermer cette boîte de dialogue ?\n" "Toutes les modifications non enregistrées seront perdues", QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No ) show(); else { QDjangoQuerySet< Core::Temp > produits; produits.remove(); close(); } }
void TestModels::test_ModelAPIs_elements() { const QDjangoQuerySet<Element> elements_set; QList< QMap<QString, QVariant> > elements_map = elements_set.all().values(); //qDebug() << elements_map; QList<QString> result; for (int i = 0; i < elements_map.count(); i++){ result << elements_map[i]["name"].toString(); } QList<QString> result2; result2 = ModelAPIs::Instance()->elements(); QCOMPARE(result, result2); }
QStringList PromissionModel::selectAllPromission() { QStringList tmp; tmp.clear(); QDjango::setDatabase(*Core::Base::instance().sessionDatabase()); QDjango::registerModel<Promission>(); QDjango::createTables(); QDjangoQuerySet<Promission> proms; QList<QVariantMap> propertyMaps = proms.values(QStringList() << "name" << "signature" << "constant"); foreach (const QVariantMap &propertyMap, propertyMaps) { tmp.append(propertyMap["name"].toString()); }
void TestModels::test_ModelAPIs_units() { // Our result const QDjangoQuerySet<Unit> units_set; QList< QList<QVariant> > units = units_set.all().valuesList(); QList<QString> result; for (int i = 0; i < units.count(); i++){ result << units[i][1].toString(); } // From method QList<QString> result2; result2 = ModelAPIs::Instance()->units(); QCOMPARE(result, result2); }
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(); }
/// ModelAPIs void TestModels::test_ModelAPIs_schedules() { const QDjangoQuerySet<Schedule> schedules_set; QList< QMap<QString, QVariant> > schedule_map = schedules_set.all().values(); QVariantList schedules; schedules = ModelAPIs::Instance()->schedulesToQVariantList(); //qDebug() << schedules; QVERIFY(schedule_map.count() == schedules.count()); // If element_id is null then group_id is the title. QVERIFY(schedules[0].toMap()["title"].toString() == "pushup"); // element title QVERIFY(schedules[1].toMap()["title"].toString() == "daily"); // group title //qDebug() << schedule_map; }
/** 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 AddUserDialog::showEvent(QShowEvent *) { QDjango::setDatabase(*Core::Base::instance().sessionDatabase()); QDjango::registerModel<User>(); QDjango::createTables(); QRegExp rx("^(\\w+\\s+)$"); QValidator *validator = new QRegExpValidator(rx, this); ui->usernameEdit->setValidator(validator); ui->passwordEdit->setValidator(validator); QDjangoQuerySet<Group> groups; ui->groupBox->addItem(""); QList<QVariantMap> propertyMaps = groups.values(QStringList() << "name"); foreach (const QVariantMap &propertyMap, propertyMaps) { ui->groupBox->addItem(propertyMap["name"].toString()); }
/* * Чтение и подгрузка из БД требований. */ void BF_AnalizeForm::fillRequirements(const QString &type, QListWidget *lwgt) { lwgt->clear(); QDjango::setDatabase(*Core::Base::instance().sessionDatabase()); QDjangoQuerySet<RequirementElement> someRequirementElements; someRequirementElements = someRequirementElements.filter( QDjangoWhere("type", QDjangoWhere::Equals, type)); // retrieve usernames and passwords for matching users as maps QList<QVariantMap> propertyMaps = someRequirementElements.values( QStringList() << "id" << "type" << "name"); foreach (const QVariantMap &propertyList, propertyMaps) { QString tmp = QString("%1:%2%3-%4") .arg(propertyList["id"].toString()) .arg(propertyList["type"].toString()) .arg(propertyList["id"].toString()) .arg(propertyList["name"].toString()); lwgt->addItem(tmp); }
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); } }
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 TestModels::test_ModelAPIs_unit() { // // get an existing user // other = users.get(QDjangoWhere("username", QDjangoWhere::Equals, "foouser")); // QVERIFY(other != 0); // QCOMPARE(other->username(), QLatin1String("foouser")); // QCOMPARE(other->password(), QLatin1String("foopass")); const QDjangoQuerySet<Unit> units_set; Unit* unit = units_set.get(QDjangoWhere("name", QDjangoWhere::Equals, "second")); //qDebug() << unit->name(); Unit* unit2; unit2 = ModelAPIs::unit("second"); QCOMPARE(unit->name(), unit2->name()); // There is no element. Unit* unit3; unit3 = ModelAPIs::unit("no_exist"); QVERIFY(unit3 == 0); }
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(); }
PromissionModel::PromissionModel() { QDjango::setDatabase(*Core::Base::instance().sessionDatabase()); QDjango::registerModel<Promission>(); QDjango::createTables(); // Создаем роль по-умолчанию QDjangoQuerySet<Role> roles; roles = roles.filter(QDjangoWhere("name", QDjangoWhere::Equals, "Admin")); if (roles.count()==0) { messageLibrary msg; msg.createInfoMessage("Информация", "Роль администратора отсутствует, разрешения по-умолчанию создать не могу!"); } else { addPromission( tr("Возможность смотреть документацию приложения"), "CAN_SEE_APP_DOCS", "CONST", roles.at(0) ); addPromission( tr("Возможность смотреть настройки приложения"), "CAN_SEE_APP_SETTINGS", "CONST", roles.at(0) ); addPromission( tr("Возможность смотреть меню плагинов приложения"), "CAN_SEE_MANAGERS_MENU", "CONST", roles.at(0) ); addPromission( tr("Возможность управлять настройками плагинов"), "CAN_SEE_MANAGERS_SETTINGS", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с панелями плагинов"), "CAN_SEE_MANAGERS_TOOLBAR", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 0"), "CAN_SEE_MANAGER_CONROLS_LEVEL_0", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 1"), "CAN_SEE_MANAGER_CONROLS_LEVEL_1", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 2"), "CAN_SEE_MANAGER_CONROLS_LEVEL_2", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 0"), "CAN_SEE_MODULES_CONROLS_LEVEL_0", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 1"), "CAN_SEE_MODULES_CONROLS_LEVEL_1", "CONST", roles.at(0) ); addPromission( tr("Возможность работать с элементами управления плагина на уровне 2"), "CAN_SEE_MODULES_CONROLS_LEVEL_2", "CONST", roles.at(0) ); addPromission( tr("Возможность смотреть меню модулей приложения"), "CAN_SEE_MODULES_MENU", "CONST", roles.at(0) ); addPromission( tr("Возможность смотреть настройки модулей приложения"), "CAN_SEE_MODULES_SETTINGS", "CONST", roles.at(0) ); addPromission( tr("Возможность смотреть панели модулей приложения"), "CAN_SEE_MODULES_TOOLBAR", "CONST", roles.at(0) ); addPromission( tr("Возможность работать в отладочном режиме"), "DEBUG_MODE", "CONST", roles.at(0) ); } }
void Patient::filtred_Patients(){ ui->lw_filtredPatients->clear(); QDjangoQuerySet <Paciente> pat; if (!ui->le_patFILTER->text().isEmpty()) pat = pat.filter(QDjangoWhere("nameP", QDjangoWhere::Contains, ui->le_patFILTER->text())); else if(!ui->le_prontSearch->text().isEmpty()) pat = pat.filter(QDjangoWhere("pront", QDjangoWhere::Contains, ui->le_prontSearch->text())); for (int i = 0; i < pat.count(); ++i){ QListWidgetItem * itemP = new QListWidgetItem(pat.at(i)->nameP(), ui->lw_filtredPatients); itemP->setData(Qt::UserRole, pat.at(i)->pront()); } }
//! When a Patient is clicked those informations is showed in a QTableWidget void Patient::on_lw_filtredPatients_itemClicked(QListWidgetItem* item) { QDjangoQuerySet<Paciente> ptPront; ptPront = ptPront.filter(QDjangoWhere("nameP", QDjangoWhere::Equals, ui->lw_filtredPatients->currentItem()->text())); for(int i = 0; i < ptPront.count(); ++i){ QString t; QSqlQuery s; s.prepare("SELECT pront FROM sae.paciente WHERE nameP = :name"); s.bindValue(":name", ui->lw_filtredPatients->currentItem()->text()); s.exec(); while (s.next()){ t = s.value(0).toString(); } ui->tblW_selectedPatient->setItem(0, 0, new QTableWidgetItem(t)); ui->tblW_selectedPatient->setItem(0, 1, new QTableWidgetItem(ptPront.at(i)->rg())); ui->tblW_selectedPatient->setItem(0, 2, new QTableWidgetItem(ptPront.at(i)->dBornP().toString("dd / MM / yyyy"))); ui->tblW_selectedPatient->setItem(0, 3, new QTableWidgetItem(ptPront.at(i)->mailP())); ui->tblW_selectedPatient->setItem(0, 4, new QTableWidgetItem(ptPront.at(i)->ethn())); } }
void TestModels::test_common() { const QDjangoQuerySet<Unit> units; QList< QMap<QString, QVariant> > unit_map = units.all().values(); //QCOMPARE(unit_map.size(), 4); //See initdb() const QDjangoQuerySet<Element> elements; QList< QMap<QString, QVariant> > element_map = elements.all().values(); QCOMPARE(element_map.size(), 3); const QDjangoQuerySet<Group> groups; QList< QMap<QString, QVariant> > group_map = groups.all().values(); QCOMPARE(group_map.size(), 2); const QDjangoQuerySet<ElementGroup> elementgroups; QList< QMap<QString, QVariant> > elementgroup_map = elementgroups.all().values(); QCOMPARE(elementgroup_map.size(), 1); const QDjangoQuerySet<Schedule> schedules; QList< QMap<QString, QVariant> > schedule_map = schedules.all().values(); QCOMPARE(schedule_map.size(), 7); const QDjangoQuerySet<Record> records; QList< QMap<QString, QVariant> > record_map = records.all(). values(); QCOMPARE(record_map.size(), 1); }
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); } } }
bool XmppServerPrivate::handleStanza(const QDomElement &element) { const QString to = element.attribute("to"); if (QXmppUtils::jidToDomain(to) != server()->domain()) return false; if (element.tagName() == "iq" && PrivateStorageIq::isPrivateStorageIq(element)) { PrivateStorageIq request; request.parse(element); if (request.type() == QXmppIq::Result) return true; // check the namespace is valid const QString xmlns = request.payload().attribute("xmlns"); if (xmlns.isEmpty()) { QXmppIq response; response.setId(request.id()); response.setTo(request.from()); response.setType(QXmppIq::Error); server()->sendPacket(response); return true; } const QString bareFrom = QXmppUtils::jidToBareJid(request.from()); QDjangoQuerySet<PrivateStorage> qs; qs = qs.filter(QDjangoWhere("jid", QDjangoWhere::Equals, bareFrom)); if (request.type() == QXmppIq::Get) { PrivateStorageIq response; response.setId(request.id()); response.setTo(request.from()); response.setType(QXmppIq::Result); PrivateStorage storage; if (qs.get(QDjangoWhere("xmlns", QDjangoWhere::Equals, xmlns), &storage)) { QDomDocument doc; doc.setContent(storage.data()); response.setPayload(doc.documentElement()); } else { response.setPayload(request.payload()); } server()->sendPacket(response); } else if (request.type() == QXmppIq::Set) { PrivateStorage storage; if (!qs.get(QDjangoWhere("xmlns", QDjangoWhere::Equals, xmlns), &storage)) { storage.setJid(bareFrom); storage.setXmlns(xmlns); } storage.setXml(request.payload()); storage.save(); // reply QXmppIq response; response.setId(request.id()); response.setTo(request.from()); response.setType(QXmppIq::Result); server()->sendPacket(response); } return true; } return false; }