Ejemplo n.º 1
0
void QueryResultsNode::update(Snapshot &updates)
{
    typedef QMap<QueryResultItem *, Union> Map;
    qint32 lastColumn = columnCount(QModelIndex()) - 1;
    QueryResultPropertyItem *property;
    QueryResultItem *item;
    Map map;

    for (Snapshot::iterator i = updates.begin(), end = updates.end(); i != end; i = updates.erase(i))
    {
        item = (*i).first.as<QueryResultItem>();
        property = static_cast<QueryResultPropertyItem *>(item->parent());
        map[property].add(property->indexOf(item));

        if (item->size())
        {
            beginRemoveRows(Model::index(item), 0, item->size() - 1);
            static_cast<QueryResultRootPathValueItem *>(item)->update((*i).second);
            endRemoveRows();
        }
        else
            static_cast<QueryResultRootPathValueItem *>(item)->update((*i).second);

        static_cast<QueryResultValueItem *>(item)->unlock();
    }

    for (Map::const_iterator i = map.constBegin(), end = map.constEnd(); i != end; ++i)
        for (Union::List::size_type q = 0, size = (*i).size(); q < size; ++q)
            emit dataChanged(createIndex((*i).at(q).top(), 0, i.key()->at((*i).at(q).top())),
                             createIndex((*i).at(q).bottom(), lastColumn, i.key()->at((*i).at(q).bottom())));
}
Ejemplo n.º 2
0
BaseField::Ptr Registry::create(const io::Node& node) const {
  Map::const_iterator it = mMap.find(node.getName());
  if(it == mMap.end()) {
    throw KeyError(node.getName() + ": not a registered field type");
  }
  return it->second(node);
}
Ejemplo n.º 3
0
 bool dispatch (Request& req)
 {
     Map::const_iterator const iter (m_map.find (req.method));
     if (iter == m_map.end())
         return false;
     iter->second (req);
     return true;
 }
Ejemplo n.º 4
0
void golem::data::HandlerTrajectory::ImportState::extract(const Map& inp, Map& out) {
	Map buf;
	for (Map::const_iterator i = inp.begin(); i != inp.end(); ++i) {
		buf.clear();
		i->extract(buf);
		out.insert(out.end(), buf.begin(), buf.end());
	}
	//for (auto &i : out)
	//	printf("%i: %i->%i, off=%f, s=%f\n", (int)i.type, i.inp, i.out, i.offset, i.scale);
}
Ejemplo n.º 5
0
void PolyglotBook::writeEntry(const Map::const_iterator& it,
			      QDataStream& out) const
{
	quint32 learn = 0;
	quint64 key = it.key();
	quint16 pgMove = moveToBits(it.value().move);
	quint16 weight = it.value().weight;
	
	// Store the data. Again, big-endian is used by default.
	out << key << pgMove << weight << learn;
}
Ejemplo n.º 6
0
void* Album::extraData(const void* key) const
{
    typedef QMap<const void*, void*> Map;
    Map::const_iterator it = m_extraMap.constFind(key);

    if (it == m_extraMap.constEnd())
    {
        return 0;
    }

    return it.value();
}
Ejemplo n.º 7
0
/*!
    Applies \a values to the \a row in the model. The source and
    target fields are mapped by field name, not by position in
    the record.

    Note that the generated flags in \a values are preserved
    and determine whether the corresponding fields are used when
    changes are submitted to the database. The caller should
    remember to set the generated flag to FALSE for fields
    where the database is meant to supply the value, such as an
    automatically incremented ID.

    For edit strategies OnFieldChange and OnRowChange, a row may
    receive a change only if no other row has a cached change.
    Changes are submitted immediately. Submitted changes are not
    reverted upon failure.

    Returns \c true if all the values could be set; otherwise returns
    false.

    \sa record(), editStrategy()
*/
bool QSqlTableModel::setRecord(int row, const QSqlRecord &values)
{
    Q_D(QSqlTableModel);
    Q_ASSERT_X(row >= 0, "QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0");
    if (d->busyInsertingRows)
        return false;

    if (row >= rowCount())
        return false;

    if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete)
        return false;

    if (d->strategy != OnManualSubmit && d->cache.value(row).submitted() && isDirty())
        return false;

    // Check field names and remember mapping
    typedef QMap<int, int> Map;
    Map map;
    for (int i = 0; i < values.count(); ++i) {
        int idx = d->nameToIndex(values.fieldName(i));
        if (idx == -1)
            return false;
        map[i] = idx;
    }

    QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row];
    if (mrow.op() == QSqlTableModelPrivate::None)
        mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update,
                                                  QSqlQueryModel::record(row));

    Map::const_iterator i = map.constBegin();
    const Map::const_iterator e = map.constEnd();
    for ( ; i != e; ++i) {
        // have to use virtual setData() here rather than mrow.setValue()
        EditStrategy strategy = d->strategy;
        d->strategy = OnManualSubmit;
        QModelIndex cIndex = createIndex(row, i.value());
        setData(cIndex, values.value(i.key()));
        d->strategy = strategy;
        // setData() sets generated to TRUE, but source record should prevail.
        if (!values.isGenerated(i.key()))
            mrow.recRef().setGenerated(i.value(), false);
    }

    if (d->strategy != OnManualSubmit)
        return submit();

    return true;
}
Ejemplo n.º 8
0
void QueryResultsNode::unlock(const Snapshot &snapshot)
{
    typedef QMap<QueryResultItem *, Union> Map;
    qint32 lastColumn = columnCount(QModelIndex()) - 1;
    QueryResultPropertyItem *property;
    Map map;

    for (Snapshot::const_iterator i = snapshot.begin(), end = snapshot.end(); i != end; ++i)
    {
        property = static_cast<QueryResultPropertyItem *>((*i).first->parent());
        map[property].add(property->indexOf((*i).first.data()));
        (*i).first.as<QueryResultValueItem>()->unlock();
    }

    for (Map::const_iterator i = map.constBegin(), end = map.constEnd(); i != end; ++i)
        for (Union::List::size_type q = 0, size = (*i).size(); q < size; ++q)
            emit dataChanged(createIndex((*i).at(q).top(), 0, i.key()->at((*i).at(q).top())),
                             createIndex((*i).at(q).bottom(), lastColumn, i.key()->at((*i).at(q).bottom())));
}