ReturnValue Container::queryMaxCount(int32_t index, const Thing& thing, uint32_t count, uint32_t& maxQueryCount, uint32_t flags) const { const Item* item = thing.getItem(); if (item == nullptr) { maxQueryCount = 0; return RETURNVALUE_NOTPOSSIBLE; } if (hasBitSet(FLAG_NOLIMIT, flags)) { maxQueryCount = std::max<uint32_t>(1, count); return RETURNVALUE_NOERROR; } int32_t freeSlots = std::max<int32_t>(capacity() - size(), 0); if (item->isStackable()) { uint32_t n = 0; if (index == INDEX_WHEREEVER) { //Iterate through every item and check how much free stackable slots there is. uint32_t slotIndex = 0; for (Item* containerItem : itemlist) { if (containerItem != item && containerItem->equals(item) && containerItem->getItemCount() < 100) { uint32_t remainder = (100 - containerItem->getItemCount()); if (queryAdd(slotIndex++, *item, remainder, flags) == RETURNVALUE_NOERROR) { n += remainder; } } } } else { const Item* destItem = getItemByIndex(index); if (item->equals(destItem) && destItem->getItemCount() < 100) { uint32_t remainder = 100 - destItem->getItemCount(); if (queryAdd(index, *item, remainder, flags) == RETURNVALUE_NOERROR) { n = remainder; } } } maxQueryCount = freeSlots * 100 + n; if (maxQueryCount < count) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } } else { maxQueryCount = freeSlots; if (maxQueryCount == 0) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } } return RETURNVALUE_NOERROR; }
bool ProfileDB::addProfile(int profileID, const QString &fullName, const QString &photo, const QString &description, int scrapbookID) { bool success = false; QSqlQuery queryAdd(QSqlDatabase::database(connectionName)); queryAdd.prepare("INSERT INTO Profiles (ProfileID, FullName, Photo, Description, ScrapbookID) VALUES (:ProfileID, :FullName, :Photo, :Description, :ScrapbookID)"); queryAdd.bindValue(":ProfileID", profileID); queryAdd.bindValue(":FullName", fullName); queryAdd.bindValue(":Photo", photo); queryAdd.bindValue(":Description", description); queryAdd.bindValue(":ScrapbookID", scrapbookID); if(queryAdd.exec()) { success = true; } else { //qDebug() << "add profile failed: " << queryAdd.lastError(); } return success; }