Exemplo n.º 1
0
void IrcUserModelPrivate::insertUser(int index, IrcUser* user, bool notify)
{
    Q_Q(IrcUserModel);
    if (index == -1)
        index = userList.count();
    if (sortMethod != Irc::SortByHand) {
        QList<IrcUser*>::iterator it;
        if (sortOrder == Qt::AscendingOrder)
            it = qUpperBound(userList.begin(), userList.end(), user, IrcUserLessThan(q, sortMethod));
        else
            it = qUpperBound(userList.begin(), userList.end(), user, IrcUserGreaterThan(q, sortMethod));
        index = it - userList.begin();
    }
    if (notify)
        emit q->aboutToBeAdded(user);
    q->beginInsertRows(QModelIndex(), index, index);
    userList.insert(index, user);
    updateTitles();
    q->endInsertRows();
    if (notify) {
        emit q->added(user);
        emit q->namesChanged(IrcChannelPrivate::get(channel)->names);
        emit q->titlesChanged(titles);
        emit q->usersChanged(userList);
        emit q->countChanged(userList.count());
        if (userList.count() == 1)
            emit q->emptyChanged(false);
    }
}
Exemplo n.º 2
0
TableCell PageItem_Table::cellAt(const QPointF& point) const
{
	QPointF gridPoint = getTransform().inverted().map(point) - gridOffset();

	if (!QRectF(0, 0, tableWidth(), tableHeight()).contains(gridPoint))
		return TableCell(); // Outside table grid.

	return cellAt(
		qUpperBound(m_rowPositions, gridPoint.y()) - m_rowPositions.begin() - 1,
		qUpperBound(m_columnPositions, gridPoint.x()) - m_columnPositions.begin() - 1);
}
Exemplo n.º 3
0
void KateLineLayoutMap::slotEditDone(int fromLine, int toLine, int shiftAmount)
{
  LineLayoutMap::iterator start =
      qLowerBound(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(fromLine, KateLineLayoutPtr()), lessThan);
  LineLayoutMap::iterator end =
      qUpperBound(start, m_lineLayouts.end(), LineLayoutPair(toLine, KateLineLayoutPtr()), lessThan);
  LineLayoutMap::iterator it;

  if (shiftAmount != 0) {
    for (it = end; it != m_lineLayouts.end(); ++it) {
      (*it).first += shiftAmount;
      (*it).second->setLine((*it).second->line() + shiftAmount);
    }

    for (it = start; it != end; ++it) {
      (*it).second->clear();
    }

    m_lineLayouts.erase(start, end);
  } else {
    for (it = start; it != end; ++it) {
      (*it).second->setLayoutDirty();
    }
  }
}
Exemplo n.º 4
0
    void updateEntry(const QString &address, const QString &label, bool isMine, int status)
    {
        // Find address / label in model
        QList<AddressTableEntry>::iterator lower = qLowerBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        QList<AddressTableEntry>::iterator upper = qUpperBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        int lowerIndex = (lower - cachedAddressTable.begin());
        int upperIndex = (upper - cachedAddressTable.begin());
        bool inModel = (lower != upper);
        AddressTableEntry::Type newEntryType = isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending;

        switch(status)
        {
        case CT_NEW:
        {
            if(inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_NEW, but entry is already in model\n");
                break;
            }
            parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);

            std::string pmkey = "";
            std::string a;
            a = address.toStdString();
            int i;
            if (isMine)
            {
                i = SecureMsgGetLocalPublicKey(a, pmkey);
                if (i)
                    printf("Can't get PM Key for some reason\n");
            }

            cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address, QString::fromStdString(pmkey)));
            parent->endInsertRows();
            break;
        }
        case CT_UPDATED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
                break;
            }
            lower->type = newEntryType;
            lower->label = label;
            parent->emitDataChanged(lowerIndex);
            break;
        case CT_DELETED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedAddressTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 5
0
int main()
{
  QList<int> list;
  list << 3 << 3 << 6 << 6 << 6 << 8;

  QList<int>::iterator it;
  it = qLowerBound(list.begin(), list.end(), 5);
  list.insert(it, 5);
  qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8 )

  it = qLowerBound(list.begin(), list.end(), 12);
  list.insert(it, 12);
  qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12 )

  it = qLowerBound(list.begin(), list.end(), 12);
  list.insert(it, 12);
  qDebug() << list; // output: ( 3, 3, 5, 6, 6, 6, 8, 12, 12 )
  QVector<int> vect;
  vect << 3 << 3 << 6 << 6 << 6 << 8;
  QVector<int>::iterator begin6 =
        qLowerBound(vect.begin(), vect.end(), 6);
  QVector<int>::iterator end6 =
        qUpperBound(vect.begin(), vect.end(), 6);
  QVector<int> vect2(end6-begin6);
  qCopy(begin6, end6, vect2.begin());
  qDebug() << vect2; // output: ( 6, 6, 6 )
  int count6 = 0;
  qCount(vect.begin(), vect.end(), 6, count6);
  qDebug() << count6; // output: 3
  return 0;
}
Exemplo n.º 6
0
int BooksBookModel::Data::pickPage(const BooksPos& aPagePos,
    const BooksPos& aNextPagePos, int aPageCount) const
{
    int page = 0;
    if (aPagePos.valid()) {
        if (!aNextPagePos.valid()) {
            // Last page stays the last
            page = iPageMarks.count() - 1;
            HDEBUG("last page" << page);
        } else {
            BooksPos::ConstIterator it = qFind(iPageMarks, aPagePos);
            if (it == iPageMarks.end()) {
                // Two 90-degrees rotations should return the reader
                // back to the same page. That's what this is about.
                const BooksPos& pos = (iPageMarks.count() > aPageCount) ?
                    aPagePos : aNextPagePos;
                it = qUpperBound(iPageMarks, pos);
                page = (int)(it - iPageMarks.begin());
                if (page > 0) page--;
                HDEBUG("using page" << page << "for" << pos);
            } else {
                page = it - iPageMarks.begin();
                HDEBUG("found" << aPagePos << "at page" << page);
            }
        }
    }
    return page;
}
Exemplo n.º 7
0
double DepthModel::getVolumeByPrice(double price, bool isAsk)
{
    if (priceList.count() == 0)
        return 0.0;

    int currentIndex;
    int outside = 1;

    if (isAsk)
    {
        currentIndex = qUpperBound(priceList.begin(), priceList.end(), price) - priceList.begin();
        --currentIndex;

        if (currentIndex < 0)
            return 0.0;

        if (currentIndex >= priceList.count() - 1 && price > priceList.last())
            outside = -1;
    }
    else
    {
        currentIndex = qLowerBound(priceList.begin(), priceList.end(), price) - priceList.begin();

        if (currentIndex >= priceList.count())
            return 0.0;

        if (currentIndex == 0 && price < priceList[0])
            outside = -1;
    }

    return sizeListAt(currentIndex) * outside;
}
Exemplo n.º 8
0
double DepthModel::getVolumeByPrice(double price)
{
    if(priceList.count()==0)return 0.0;
    int currentIndex=qUpperBound(priceList.begin(),priceList.end(),price)-priceList.begin();
    if(currentIndex<0)return 0.0;
    if(currentIndex>=priceList.count())currentIndex=priceList.count()-1;
    return sizeListAt(currentIndex)*(currentIndex==priceList.count()-1?-1:1)*(currentIndex==0?-1:1);
}
Exemplo n.º 9
0
    void refreshName(const std::vector<unsigned char> &inName)
    {

        LOCK(cs_main);

        NameTableEntry nameObj(ValtypeToString(inName),
                               std::string(""),
                               NameTableEntry::NAME_NON_EXISTING);

        CNameData data;
        {
            LOCK (cs_main);
            if (!pcoinsTip->GetName (inName, data))
            {
                LogPrintf ("name not found: '%s'\n", ValtypeToString (inName).c_str());
                return;
            }

            nameObj = NameTableEntry(ValtypeToString(inName),
                                     ValtypeToString(data.getValue ()),
                                     data.getHeight ());
        }

        // Find name in model
        QList<NameTableEntry>::iterator lower = qLowerBound(
            cachedNameTable.begin(), cachedNameTable.end(), nameObj.name, NameTableEntryLessThan());
        QList<NameTableEntry>::iterator upper = qUpperBound(
            cachedNameTable.begin(), cachedNameTable.end(), nameObj.name, NameTableEntryLessThan());
        bool inModel = (lower != upper);

        if (inModel)
        {
            // In model - update or delete
            if (nameObj.nHeight != NameTableEntry::NAME_NON_EXISTING)
            {
                LogPrintf ("refreshName result : %s - refreshed in the table\n", qPrintable(nameObj.name));
                updateEntry(nameObj.name, nameObj.value, nameObj.nHeight, CT_UPDATED);
            }
            else
            {
                LogPrintf("refreshName result : %s - deleted from the table\n", qPrintable(nameObj.name));
                updateEntry(nameObj.name, nameObj.value, nameObj.nHeight, CT_DELETED);
            }
        }
        else
        {
            // Not in model - add or do nothing
            if (nameObj.nHeight != NameTableEntry::NAME_NON_EXISTING)
            {
                LogPrintf("refreshName result : %s - added to the table\n", qPrintable(nameObj.name));
                updateEntry(nameObj.name, nameObj.value, nameObj.nHeight, CT_NEW);
            }
            else
            {
                LogPrintf("refreshName result : %s - ignored (not in the table)\n", qPrintable(nameObj.name));
            }
        }
    }
Exemplo n.º 10
0
    /* Update our model of the wallet incrementally, to synchronize our model of the wallet
       with that of the core.

       Call with transaction that was added, removed or changed.
     */
    void updateWallet(const uint256 &hash, int status, bool showTransaction)
    {
        qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);

        // Find bounds of this transaction in model
        QList<TransactionRecord>::iterator lower = qLowerBound(
            cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
        QList<TransactionRecord>::iterator upper = qUpperBound(
            cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
        int lowerIndex = (lower - cachedWallet.begin());
        int upperIndex = (upper - cachedWallet.begin());
        bool inModel = (lower != upper);

        if(status == CT_UPDATED)
        {
            if(showTransaction && !inModel)
                status = CT_NEW; /* Not in model, but want to show, treat as new */
            if(!showTransaction && inModel)
                status = CT_DELETED; /* In model, but want to hide, treat as deleted */
        }

        qDebug() << "    inModel=" + QString::number(inModel) +
                    " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) +
                    " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status);

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
                break;
            }
            if(showTransaction)
            {
                LOCK2(cs_main, wallet->cs_wallet);
                // Find transaction in wallet
                std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(hash);
                if(mi == wallet->mapWallet.end())
                {
                    qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
                    break;
                }
                // Added -- insert at the right position
                QList<TransactionRecord> toInsert =
                        TransactionRecord::decomposeTransaction(wallet, mi->second);
                if(!toInsert.isEmpty()) /* only if something to insert */
                {
                    parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
                    int insert_idx = lowerIndex;
                    foreach(const TransactionRecord &rec, toInsert)
                    {
                        cachedWallet.insert(insert_idx, rec);
                        insert_idx += 1;
                    }
                    parent->endInsertRows();
                }
            }
Exemplo n.º 11
0
    void
    updateEntry(const QString &name, const QString &value,
                int nHeight, int status, int *outNewRowIndex = NULL)
    {
        // Find name in model
        QList<NameTableEntry>::iterator lower = qLowerBound(
            cachedNameTable.begin(), cachedNameTable.end(), name, NameTableEntryLessThan());
        QList<NameTableEntry>::iterator upper = qUpperBound(
            cachedNameTable.begin(), cachedNameTable.end(), name, NameTableEntryLessThan());
        int lowerIndex = (lower - cachedNameTable.begin());
        int upperIndex = (upper - cachedNameTable.begin());
        bool inModel = (lower != upper);

        switch(status)
        {
        case CT_NEW:
            if (inModel)
            {
                if (outNewRowIndex)
                {
                    *outNewRowIndex = parent->index(lowerIndex, 0).row();
                    // HACK: ManageNamesPage uses this to ensure updating and get selected row,
                    // so we do not write warning into the log in this case
                }
                else {
                    LogPrintf ("Warning: NameTablePriv::updateEntry: Got CT_NOW, but entry is already in model\n");
                }
                break;
            }
            parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
            cachedNameTable.insert(lowerIndex, NameTableEntry(name, value, nHeight));
            parent->endInsertRows();
            if (outNewRowIndex)
                *outNewRowIndex = parent->index(lowerIndex, 0).row();
            break;
        case CT_UPDATED:
            if (!inModel)
            {
                LogPrintf ("Warning: NameTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
                break;
            }
            lower->name = name;
            lower->value = value;
            lower->nHeight = nHeight;
            parent->emitDataChanged(lowerIndex);
            break;
        case CT_DELETED:
            if (!inModel)
            {
                LogPrintf ("Warning: NameTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedNameTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 12
0
        void insertItem( QwtPlotItem *item )
        {
            if ( item == NULL )
                return;

            QList<QwtPlotItem *>::iterator it =
                qUpperBound( begin(), end(), item, LessZThan() );
            insert( it, item );
        }
Exemplo n.º 13
0
double DepthModel::getPriceByVolume(double amount)
{
    if(sizeList.count()==0)return 0.0;
    int currentIndex=qUpperBound(sizeList.begin(),sizeList.end(),amount)-sizeList.begin();
    if(currentIndex<0)return 0.0;
    if(currentIndex>=sizeList.count())currentIndex=sizeList.count()-1;
    if(!originalIsAsk)currentIndex=priceList.count()-currentIndex-1;
    return priceList.at(currentIndex)*(currentIndex==priceList.count()-1?-1:1)*(currentIndex==0?-1:1);
}
Exemplo n.º 14
0
void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
{
    if (runnable->autoDelete())
        ++runnable->ref;

    // put it on the queue
    QList<QPair<QRunnable *, int> >::iterator at =
        qUpperBound(queue.begin(), queue.end(), priority);
    queue.insert(at, qMakePair(runnable, priority));
}
Exemplo n.º 15
0
void KateLineLayoutMap::insert(int realLine, const KateLineLayoutPtr& lineLayoutPtr)
{
  LineLayoutMap::iterator it =
    qBinaryFind(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(realLine,KateLineLayoutPtr()), lessThan);
  if (it != m_lineLayouts.end()) {
    (*it).second = lineLayoutPtr;
  } else {
    it = qUpperBound(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(realLine,KateLineLayoutPtr()), lessThan);
    m_lineLayouts.insert(it, LineLayoutPair(realLine, lineLayoutPtr));
  }
}
Exemplo n.º 16
0
void KateLineLayoutMap::relayoutLines(int startRealLine, int endRealLine)
{
  LineLayoutMap::iterator start =
      qLowerBound(m_lineLayouts.begin(), m_lineLayouts.end(), LineLayoutPair(startRealLine, KateLineLayoutPtr()), lessThan);
  LineLayoutMap::iterator end =
      qUpperBound(start, m_lineLayouts.end(), LineLayoutPair(endRealLine, KateLineLayoutPtr()), lessThan);

  while (start != end) {
    (*start).second->setLayoutDirty();
    ++start;
  }
}
Exemplo n.º 17
0
void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
{
    if (runnable->autoDelete())
        ++runnable->ref;

    // put it on the queue
    QList<QPair<QRunnable *, int> >::const_iterator begin = queue.constBegin();
    QList<QPair<QRunnable *, int> >::const_iterator it = queue.constEnd();
    if (it != begin && priority < (*(it - 1)).second)
        it = qUpperBound(begin, --it, priority);
    queue.insert(it - begin, qMakePair(runnable, priority));
    runnableReady.wakeOne();
}
Exemplo n.º 18
0
    void updateEntry(const QString &address, const QString &label, bool isMine, int status)
    {
        // Find address / label in model
        QList<AddressTableEntry>::iterator lower = qLowerBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        QList<AddressTableEntry>::iterator upper = qUpperBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        int lowerIndex = (lower - cachedAddressTable.begin());
        int upperIndex = (upper - cachedAddressTable.begin());
        bool inModel = (lower != upper);
        AddressTableEntry::Type newEntryType = isMine ? AddressTableEntry::Receiving : AddressTableEntry::Sending;

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_NOW, but entry is already in model\n");
                break;
            }
            {
                CBitcoinAddress addr(address.toStdString());
                AddressTableEntry::Category cate = IsMyShare(*wallet, addr.Get()) ? AddressTableEntry::MultiSig : AddressTableEntry::Normal;

                parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
                cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address, cate));
                parent->endInsertRows();
            }
            break;
        case CT_UPDATED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
                break;
            }
            lower->type = newEntryType;
            lower->label = label;
            parent->emitDataChanged(lowerIndex);
            break;
        case CT_DELETED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: AddressTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedAddressTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 19
0
int BooksBookModel::Data::pickPage(const BooksPos& aPagePos) const
{
    int page = 0;
    if (aPagePos.valid()) {
        BooksPos::ConstIterator it = qFind(iPageMarks, aPagePos);
        if (it == iPageMarks.end()) {
            it = qUpperBound(iPageMarks, aPagePos);
            page = (int)(it - iPageMarks.begin()) - 1;
            HDEBUG("using page" << page << "for" << aPagePos);
        } else {
            page = it - iPageMarks.begin();
            HDEBUG("found" << aPagePos << "at page" << page);
        }
    }
    return page;
}
Exemplo n.º 20
0
void QGeoMapGroupObjectPrivate::childChangedZValue(int zValue)
{
    Q_UNUSED(zValue);
    QGeoMapObject *child = qobject_cast<QGeoMapObject*>(sender());
    if (!child)
        return;

    if (children.removeAll(child) > 0) {
        QList<QGeoMapObject*>::iterator i = qUpperBound(children.begin(),
                                                        children.end(),
                                                        child,
                                                        mapObjectLessThan);
        children.insert(i, child);
        emit q_ptr->childUpdated(child);
    }
}
Exemplo n.º 21
0
    void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
    {
        // Find address / label in model
        QList<AddressTableEntry>::iterator lower = qLowerBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        QList<AddressTableEntry>::iterator upper = qUpperBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        int lowerIndex = (lower - cachedAddressTable.begin());
        int upperIndex = (upper - cachedAddressTable.begin());
        bool inModel = (lower != upper);
        AddressTableEntry::Type newEntryType = translateTransactionType(purpose, isMine);

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_NEW, but entry is already in model";
                break;
            }
            parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
            cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address));
            parent->endInsertRows();
            break;
        case CT_UPDATED:
            if(!inModel)
            {
                qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
                break;
            }
            lower->type = newEntryType;
            lower->label = label;
            parent->emitDataChanged(lowerIndex);
            break;
        case CT_DELETED:
            if(!inModel)
            {
                qWarning() << "AddressTablePriv::updateEntry : Warning: Got CT_DELETED, but entry is not in model";
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedAddressTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 22
0
    void updateEntry(const QString &address, const QString &label, const QString &nation, int status)
    {
        // Find address / label in model
        QList<VotingTableEntry>::iterator lower = qLowerBound(
            cachedVotingTable.begin(), cachedVotingTable.end(), address, VotingTableEntryLessThan());
        QList<VotingTableEntry>::iterator upper = qUpperBound(
            cachedVotingTable.begin(), cachedVotingTable.end(), address, VotingTableEntryLessThan());
        int lowerIndex = (lower - cachedVotingTable.begin());
        int upperIndex = (upper - cachedVotingTable.begin());
        bool inModel = (lower != upper);

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                OutputDebugStringF("Warning: VotingTablePriv::updateEntry: Got CT_NOW, but entry is already in model\n");
                break;
            }
            parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
            cachedVotingTable.insert(lowerIndex, VotingTableEntry(label, address, nation));
            parent->endInsertRows();
            break;
        case CT_UPDATED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: VotingTablePriv::updateEntry: Got CT_UPDATED, but entry is not in model\n");
                break;
            }
            lower->label = label;
            lower->nation = nation;
            parent->emitDataChanged(lowerIndex);
            break;
        case CT_DELETED:
            if(!inModel)
            {
                OutputDebugStringF("Warning: VotingTablePriv::updateEntry: Got CT_DELETED, but entry is not in model\n");
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedVotingTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 23
0
/*!
    Adds \a childObject to the list of children of this map object.

    The children objects are drawn in order of the QGeoMapObject::zValue()
    value.  Children objects having the same z value will be drawn
    in the order they were added.

    The map object will take ownership of \a childObject.
    \since 1.1
*/
void QGeoMapGroupObject::addChildObject(QGeoMapObject *childObject)
{
    if (!childObject || d_ptr->children.contains(childObject))
        return;

    childObject->setMapData(mapData());
    childObject->d_func()->serial = d_func()->serial++;

    //binary search
    QList<QGeoMapObject*>::iterator i = qUpperBound(d_ptr->children.begin(),
                                                    d_ptr->children.end(),
                                                    childObject,
                                                    mapObjectLessThan);
    d_ptr->children.insert(i, childObject);

    connect(childObject, SIGNAL(zValueChanged(int)),
            d_ptr, SLOT(childChangedZValue(int)));

    emit childAdded(childObject);
}
Exemplo n.º 24
0
double BeatUtils::calculateOffset(
    const QVector<double> beats1, const double bpm1,
    const QVector<double> beats2, const int SampleRate) {
    /*
     * Here we compare to beats vector and try to determine the best offset
     * based on the occurences, i.e. by assuming that the almost correct beats
     * are more than the "false" ones.
     */
    const double beatlength1 = (60.0 * SampleRate / bpm1);
    const double beatLength1Epsilon = beatlength1 * 0.02;

    int bestFreq = 1;
    double bestOffset = beats1.at(0) - beats2.at(0);

    // Sweep offset from [-beatlength1/2, beatlength1/2]
    double offset = floor(-beatlength1 / 2);
    while (offset < (beatlength1 / 2)) {
        int freq = 0;
        for (int i = 0; i < beats2.size(); i += 4) {
            double beats2_beat = beats2.at(i);
            QVector<double>::const_iterator it = qUpperBound(
                beats1.begin(), beats1.end(), beats2_beat);
            if (fabs(*it - beats2_beat - offset) <= beatLength1Epsilon) {
                freq++;
            }
        }
        if (freq > bestFreq) {
            bestFreq = freq;
            bestOffset = offset;
        }
        offset++;
    }

    if (sDebug) {
        qDebug() << "Best offset " << bestOffset << "guarantees that"
                << bestFreq << "over" << beats1.size()/4
                << "beats almost coincides.";
    }

    return floor(bestOffset + beatLength1Epsilon);
}
Exemplo n.º 25
0
QList<ShellCommand*>::iterator CommandsModel::getInsertPosition(CommandsModel::SortType type, ShellCommand* command
                                                                , QList<ShellCommand*> &searchlist )
{
    switch(type)
    {
    case ByLeastRuns:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::lessUsedThan);
        break;
    case ByMostRuns:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::moreUsedThan);
        break;
    case ByName:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::alphabeticallyBefore);
        break;
    case ByNameReverse:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::alphabeticallyAfter);
        break;
    case ByNewestCreated:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::newerThan);
        break;
    case ByOldestCreated:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::olderThan);
        break;
    case ByNewestRun:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::moreRecentThan);
        break;
    case ByOldestRun:
        return qUpperBound(searchlist.begin(), searchlist.end(), command, ShellCommand::lessRecentThan);
        break;
    case ByIsRunning:
        return binaryBound(searchlist.begin(), searchlist.end());
        break;
    default:
        break;
    }
}
Exemplo n.º 26
0
QList<BookmarkInfo> Bookmarks::getBookmarksInRange(qint64 low, qint64 high)
{
    BookmarkInfo info;
    info.frequency=low;
    QList<BookmarkInfo>::const_iterator lb = qLowerBound(m_BookmarkList, info);
    info.frequency=high;
    QList<BookmarkInfo>::const_iterator ub = qUpperBound(m_BookmarkList, info);

    QList<BookmarkInfo> found;

    while (lb != ub)
    {
        const BookmarkInfo& info = *lb;
        //if(info.IsActive())
        {
          found.append(info);
        }
        lb++;
    }

    return found;

}
Exemplo n.º 27
0
    /* Update our model of the wallet incrementally, to synchronize our model of the wallet
       with that of the core.

       Call with transaction that was added, removed or changed.
     */
    void updateWallet(const uint256 &hash, int status)
    {
        OutputDebugStringF("updateWallet %s %i\n", hash.ToString().c_str(), status);
        {
            LOCK(wallet->cs_wallet);

            // Find transaction in wallet
            std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(hash);
            bool inWallet = mi != wallet->mapWallet.end();

            // Find bounds of this transaction in model
            QList<TransactionRecord>::iterator lower = qLowerBound(
                cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
            QList<TransactionRecord>::iterator upper = qUpperBound(
                cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
            int lowerIndex = (lower - cachedWallet.begin());
            int upperIndex = (upper - cachedWallet.begin());
            bool inModel = (lower != upper);

            // Determine whether to show transaction or not
            bool showTransaction = (inWallet && TransactionRecord::showTransaction(mi->second));

            if(status == CT_UPDATED)
            {
                if(showTransaction && !inModel)
                    status = CT_NEW; /* Not in model, but want to show, treat as new */
                if(!showTransaction && inModel)
                    status = CT_DELETED; /* In model, but want to hide, treat as deleted */
            }

            OutputDebugStringF("   inWallet=%i inModel=%i Index=%i-%i showTransaction=%i derivedStatus=%i\n",
                     inWallet, inModel, lowerIndex, upperIndex, showTransaction, status);

            switch(status)
            {
            case CT_NEW:
                if(inModel)
                {
                    OutputDebugStringF("Warning: updateWallet: Got CT_NEW, but transaction is already in model\n");
                    break;
                }
                if(!inWallet)
                {
                    OutputDebugStringF("Warning: updateWallet: Got CT_NEW, but transaction is not in wallet\n");
                    break;
                }
                if(showTransaction)
                {
                    // Added -- insert at the right position
                    QList<TransactionRecord> toInsert =
                            TransactionRecord::decomposeTransaction(wallet, mi->second);
                    if(!toInsert.isEmpty()) /* only if something to insert */
                    {
                        parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
                        int insert_idx = lowerIndex;
                        foreach(const TransactionRecord &rec, toInsert)
                        {
                            cachedWallet.insert(insert_idx, rec);
                            insert_idx += 1;
                        }
                        parent->endInsertRows();
                    }
                }
                break;
            case CT_DELETED:
                if(!inModel)
                {
                    OutputDebugStringF("Warning: updateWallet: Got CT_DELETED, but transaction is not in model\n");
                    break;
                }
                // Removed -- remove entire transaction from table
                parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
                cachedWallet.erase(lower, upper);
                parent->endRemoveRows();
                break;
            case CT_UPDATED:
                // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for
                // visible transactions.
                break;
            }
    void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
    {
        // Find address / label in model
        QList<AddressTableEntry>::iterator lower = qLowerBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        QList<AddressTableEntry>::iterator upper = qUpperBound(
            cachedAddressTable.begin(), cachedAddressTable.end(), address, AddressTableEntryLessThan());
        int lowerIndex = (lower - cachedAddressTable.begin());
        int upperIndex = (upper - cachedAddressTable.begin());
        bool inModel = (lower != upper);
        AddressTableEntry::Type newEntryType = translateTransactionType(purpose, isMine);

		CMnemonicAddress bitcoinAddress;
		bitcoinAddress.SetString( address.toStdString() );
		CKeyID keyID;
		bitcoinAddress.GetKeyID(keyID);

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_NOW, but entry is already in model";
                break;
            }
            parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);

            cachedAddressTable.insert(lowerIndex, AddressTableEntry(newEntryType, label, address,QString::number ( wallet->AvailableCoinsAmount(keyID))));
            parent->endInsertRows();
            break;
        case CT_UPDATED:
            if(!inModel)
            {
                qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
                break;
            }
            lower->type = newEntryType;
            lower->label = label;
            parent->emitDataChanged(lowerIndex);
            break;
		case CT_BALANCE:
			if(!inModel)
			{
				qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_UPDATED, but entry is not in model";
				break;
			}
			lower->balance = CDimsUnits::format(0, wallet->AvailableCoinsAmount(keyID));
			parent->emitDataChanged(lowerIndex);
			break;
        case CT_DELETED:
            if(!inModel)
            {
                qDebug() << "AddressTablePriv::updateEntry : Warning: Got CT_DELETED, but entry is not in model";
                break;
            }
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedAddressTable.erase(lower, upper);
            parent->endRemoveRows();
            break;
        }
    }
Exemplo n.º 29
0
    /* Update our model of the wallet incrementally, to synchronize our model of the wallet
       with that of the core.

       Call with transaction that was added, removed or changed.
     */
    void updateWallet(interfaces::Wallet& wallet, const uint256 &hash, int status, bool showTransaction)
    {
        qDebug() << "TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.ToString()) + " " + QString::number(status);

        // Find bounds of this transaction in model
        QList<TransactionRecord>::iterator lower = qLowerBound(
            cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
        QList<TransactionRecord>::iterator upper = qUpperBound(
            cachedWallet.begin(), cachedWallet.end(), hash, TxLessThan());
        int lowerIndex = (lower - cachedWallet.begin());
        int upperIndex = (upper - cachedWallet.begin());
        bool inModel = (lower != upper);

        if(status == CT_UPDATED)
        {
            if(showTransaction && !inModel)
                status = CT_NEW; /* Not in model, but want to show, treat as new */
            if(!showTransaction && inModel)
                status = CT_DELETED; /* In model, but want to hide, treat as deleted */
        }

        qDebug() << "    inModel=" + QString::number(inModel) +
                    " Index=" + QString::number(lowerIndex) + "-" + QString::number(upperIndex) +
                    " showTransaction=" + QString::number(showTransaction) + " derivedStatus=" + QString::number(status);

        switch(status)
        {
        case CT_NEW:
            if(inModel)
            {
                qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
                break;
            }
            if(showTransaction)
            {
                // Find transaction in wallet
                interfaces::WalletTx wtx = wallet.getWalletTx(hash);
                if(!wtx.tx)
                {
                    qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
                    break;
                }
                // Added -- insert at the right position
                QList<TransactionRecord> toInsert =
                        TransactionRecord::decomposeTransaction(wtx);
                if(!toInsert.isEmpty()) /* only if something to insert */
                {
                    parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
                    int insert_idx = lowerIndex;
                    for (const TransactionRecord &rec : toInsert)
                    {
                        cachedWallet.insert(insert_idx, rec);
                        insert_idx += 1;
                    }
                    parent->endInsertRows();
                }
            }
            break;
        case CT_DELETED:
            if(!inModel)
            {
                qWarning() << "TransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
                break;
            }
            // Removed -- remove entire transaction from table
            parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
            cachedWallet.erase(lower, upper);
            parent->endRemoveRows();
            break;
        case CT_UPDATED:
            // Miscellaneous updates -- nothing to do, status update will take care of this, and is only computed for
            // visible transactions.
            for (int i = lowerIndex; i < upperIndex; i++) {
                TransactionRecord *rec = &cachedWallet[i];
                rec->status.needsUpdate = true;
            }
            break;
        }
    }
Exemplo n.º 30
0
void
FilterModel::setData (const GenericFilter & filter)
{
	QList<GenericFilter>::iterator cursor = qUpperBound(rawData.begin(), rawData.end(), filter );
	rawData.insert(cursor, filter);
}