Esempio n. 1
0
void KRunnerModel::matchesChanged(const QList< Plasma::QueryMatch > & m)
{
    QList< Plasma::QueryMatch > matches = m;

    qSort(matches.begin(), matches.end());

    clear();

    while (matches.size()) {
        Plasma::QueryMatch match = matches.takeLast();

        appendRow(
            StandardItemFactory::createItem(
                match.icon(),
                match.text(),
                match.subtext(),
                QString("krunner://") + match.runner()->id() + "/" + ::runnerManager()->query() + "#" + match.id(),
                match.relevance(),
                CommonModel::AddAction
                )
            );
    }

    sort(0, Qt::DescendingOrder);
}
Esempio n. 2
0
QVariant SourcesModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid())
        return QVariant();

    if (index.row() >= m_size)
        return QVariant();

    Plasma::QueryMatch m = fetchMatch(index.row());
    Q_ASSERT(m.runner());

    switch(role) {
        case Qt::DisplayRole:
            return m.text();

        case Qt::DecorationRole:
            if (!m.iconName().isEmpty()) {
                return m.iconName();
            }

            return m.icon();

        case TypeRole:
            return m.matchCategory();

        case SubtextRole:
            return m.subtext();

        case ActionsRole: {
            const auto &actions = m_manager->actionsForMatch(m);
            if (actions.isEmpty()) {
                return QVariantList();
            }

            QVariantList actionsList;
            actionsList.reserve(actions.size());

            for (QAction *action : actions) {
                actionsList.append(QVariant::fromValue(action));
            }

            return actionsList;
        }
        case DuplicateRole:
            return m_duplicates.value(m.text());

            /*
        case PreviewTypeRole:
            return m.previewType();

        case PreviewUrlRole:
            return m.previewUrl();

        case PreviewLabelRole:
            return m.previewLabel();
            */
    }

    return QVariant();
}
QueryMatchItem::QueryMatchItem(const Plasma::QueryMatch &match, QGraphicsWidget *parent)
    : MatchItem(match.icon(), match.text(), match.subtext(), parent),
      m_match(match)
{}