コード例 #1
0
ファイル: tst_qlist.cpp プロジェクト: KDE/android-qt
void tst_QList::lastIndexOf() const
{
    QList<QString> list;
    list << "foo" << "bar" << "baz";

    // one instance of the target item
    QVERIFY(list.lastIndexOf(QLatin1String("baz")) == 2);

    // shouldn't find this
    QVERIFY(list.lastIndexOf(QLatin1String("shouldntfindme")) == -1);

    // multiple instances
    list.append("baz");
    list.append("baz");
    QVERIFY(list.lastIndexOf(QLatin1String("baz")) == 4);

    // search from the middle to find the last one
    QVERIFY(list.lastIndexOf(QLatin1String("baz"), 3) == 3);

    // try find none
    QVERIFY(list.lastIndexOf(QLatin1String("baz"), 1) == -1);
}
コード例 #2
0
ファイル: KisNodeDelegate.cpp プロジェクト: hshrimali/krita
QList<OptionalProperty> KisNodeDelegate::Private::rightmostProperties(const KisBaseNode::PropertyList &props) const
{
    QList<OptionalProperty> list;
    QList<OptionalProperty> prependList;
    list << OptionalProperty(0);
    list << OptionalProperty(0);
    list << OptionalProperty(0);

    KisBaseNode::PropertyList::const_iterator it = props.constBegin();
    KisBaseNode::PropertyList::const_iterator end = props.constEnd();
    for (; it != end; ++it) {
        if (!it->isMutable) continue;

        if (it->id == KisLayerPropertiesIcons::visible.id()) {
            // noop...
        } else if (it->id == KisLayerPropertiesIcons::locked.id()) {
            list[0] = OptionalProperty(&(*it));
        } else if (it->id == KisLayerPropertiesIcons::inheritAlpha.id()) {
            list[1] = OptionalProperty(&(*it));
        } else if (it->id == KisLayerPropertiesIcons::alphaLocked.id()) {
            list[2] = OptionalProperty(&(*it));
        } else {
            prependList.prepend(OptionalProperty(&(*it)));
        }
    }

    {
        QMutableListIterator<OptionalProperty> i(prependList);
        i.toBack();
        while (i.hasPrevious()) {
            OptionalProperty val = i.previous();

            int emptyIndex = list.lastIndexOf(0);
            if (emptyIndex < 0) break;

            list[emptyIndex] = val;
            i.remove();
        }
    }

    return prependList + list;
}