void CSMWorld::IdTableProxyModel::sourceRowsInserted(const QModelIndex &parent, int /*start*/, int end) { refreshFilter(); if (!parent.isValid()) { emit rowAdded(getRecordId(end).toUtf8().constData()); } }
std::string DataStore::jsCreateStore() { std::string store; switch (dataLocation_) { case ClientSide: store += "new Ext.data.SimpleStore({fields:["; for (unsigned i = 0; i < columns_.size(); ++i) { if (i != 0) store += ","; store += "{name:'c" + boost::lexical_cast<std::string>(i) + "'," "mapping:" + boost::lexical_cast<std::string>(i+1) + "}"; } store += "],data:["; for (int i = 0; i < model_->rowCount(); ++i) { if (i != 0) store += ","; store += "[" + boost::lexical_cast<std::string>(getRecordId(i)); for (unsigned j = 0; j < columns_.size(); ++j) store += "," + dataAsJSLiteral(i, columns_[j].modelColumn); store += "]"; } store += "],id:0})"; break; case ServerSide: store = "new Ext.data.Store({" "proxy: new Ext.data.HttpProxy({" "url:'" + generateUrl() + "'" "})," "reader: new Ext.data.JsonReader({" "totalProperty:'count'," "root:'data'," "id:'id'" "},["; for (unsigned i = 0; i < columns_.size(); ++i) { if (i != 0) store += ","; store += "{name:'c" + boost::lexical_cast<std::string>(i) + "'}"; } store +="])})"; } rowsInserted_ = false; rowsDeleted_.clear(); jsChanges_.clear(); return store; }
std::string DataStore::jsGetUpdates(const std::string& storeVar) { if (dataLocation_ == ClientSide) { if (jsChanges_.empty() && rowsDeleted_.empty() && !rowsInserted_) return std::string(); std::stringstream result; result << "{var store=" << storeVar << ";store.clearFilter();var RD=store.recordDef;"; result << jsChanges_; jsChanges_.clear(); for (int i = rowsDeleted_.size() - 1; i >= 0; --i) { result << "store.remove(store.getById(" << rowsDeleted_[i] << "));"; } rowsDeleted_.clear(); if (rowsInserted_) { for (int i = 0; i < model_->rowCount(); ++i) { if (recordIds_[i] == -1) { result << "store.insert(" << i << ",[new RD({"; for (unsigned j = 0; j < columns_.size(); ++j) { if (j != 0) result << ','; result << "'c" << j << "':" << dataAsJSLiteral(i, columns_[j].modelColumn); } result << "}," << getRecordId(i) << ")]);"; } } rowsInserted_ = false; } result << "};"; return result.str(); } else { if (needRefresh_) { needRefresh_ = false; return storeVar + ".reload();"; } else return std::string(); } }
void CSMWorld::InfoTableProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { refreshFilter(); if (mLastAddedSourceRow != -1 && topLeft.row() <= mLastAddedSourceRow && bottomRight.row() >= mLastAddedSourceRow) { // Now the topic of the last added row is set, // so we can re-sort the model to ensure the corrent position of this row int column = sortColumn(); Qt::SortOrder order = sortOrder(); sort(mInfoColumnIndex); // Restore the correct position of an added row sort(column, order); // Restore the original sort order emit rowAdded(getRecordId(mLastAddedSourceRow).toUtf8().constData()); // Make sure that we perform a re-sorting only in the first dataChanged() after a row insertion mLastAddedSourceRow = -1; } }
UdrRecordId retrieveObject(UdrDbi *dbi, U2RawData &object, U2OpStatus &os) { UdrRecordId recId = getRecordId(dbi, object.id, os); CHECK_OP(os, recId); UdrRecord record = dbi->getRecord(recId, os); CHECK_OP(os, recId); U2Object obj; dbi->getRootDbi()->getObjectDbi()->getObject(obj, object.id, os); CHECK_OP(os, recId); object.visualName = obj.visualName; object.version = obj.version; CHECK_OP(os, recId); object.serializer = record.getString(SERIALIZER, os); CHECK_OP(os, recId); return recId; }
void DataStore::handleRequest(const Http::Request& request, Http::Response& response) { response.setMimeType("text/x-json"); WModelIndexList matches; if (modelFilterColumn_ != -1) { WString query; const std::string *queryE = request.getParameter("query"); if (queryE) query = WString::fromUTF8(*queryE); matches = model_->match(model_->index(0, modelFilterColumn_), DisplayRole, boost::any(query)); } int start = 0; int rowCount = (modelFilterColumn_ == -1 ? model_->rowCount() : matches.size()); int limit = rowCount; const std::string *s; s = request.getParameter("start"); if (s) try { start = std::max(0, std::min(limit, boost::lexical_cast<int>(*s))); } catch (boost::bad_lexical_cast& e) { LOG_ERROR("start '" << *s << "' is not-a-number."); } s = request.getParameter("limit"); if (s) try { limit = std::max(0, std::min(limit - start, boost::lexical_cast<int>(*s))); } catch (boost::bad_lexical_cast& e) { LOG_ERROR("limit '" << *s << "' is not-a-number."); } std::ostream& o = response.out(); o << "{" << "'count':" << rowCount << "," << "'data':["; for (int row = start; row < start + limit; ++row) { if (row != start) o << ","; o << "{"; int modelRow = modelFilterColumn_ == -1 ? row : matches[row].row(); o << "'id':" << getRecordId(modelRow); for (unsigned j = 0; j < columns_.size(); ++j) o << ",'" << columns_[j].fieldName << "':" << dataAsJSLiteral(modelRow, columns_[j].modelColumn); o << "}"; } o << "]}"; }