Beispiel #1
0
bool TransferModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int,
                                 const QModelIndex &parent) {
    if ((!data) || (!data->hasFormat(MIME_TYPE)) || (action != Qt::MoveAction)) {
        return false;
    }

    const int max = rowCount(parent);
    
    if ((row < 0) || (row > max)) {
        row = max;
    }

    QByteArray encoded = data->data(MIME_TYPE);
    QDataStream stream(&encoded, QIODevice::ReadOnly);
    
    while (!stream.atEnd()) {
        int r;
        int pr;
        stream >> r >> pr;

        if (!moveRows(pr == -1 ? QModelIndex() : index(pr, 0), r, 1, parent, row)) {
            return false;
        }
    }
    
    return true;
}
bool AttachedFiltersModel::removeRows(int row, int , const QModelIndex &parent)
{
    if (m_producer && m_producer->is_valid() && m_dropRow >= 0 && row != m_dropRow) {
        bool result = moveRows(parent, row, 1, parent, m_dropRow);
        m_dropRow = -1;
        return result;
    } else {
        return false;
    }
}
bool AttachedFiltersModel::move(int fromRow, int toRow)
{
    QModelIndex parent = QModelIndex();

    if (fromRow < 0 || toRow < 0) {
        return false;
    }

    if (toRow > fromRow) {
        // Moving down: put it under the destination index
        toRow++;
    }

    return moveRows(parent, fromRow, 1, parent, toRow);
}
Beispiel #4
0
void LauncherModel::handleApplicationFocused(const QString &appId)
{
    for (int i = 0; i < m_list.size(); i++) {
        Application *app = m_list.at(i);
        if (app->appId() == appId) {
            app->setFocused(true);
            QModelIndex modelIndex = index(i);
            emit dataChanged(modelIndex, modelIndex);

            if (!m_includePinnedApps) {
                moveRows(i, 1, 0);
            }

            break;
        }
    }
}
Beispiel #5
0
void LauncherModel::pin(const QString &appId)
{
    if (!m_includePinnedApps)
        return;

    Application *found = Q_NULLPTR;

    int pinAtIndex = 0;

    Q_FOREACH (Application *item, m_list) {
        if (item->isPinned())
            pinAtIndex++;

        if (item->appId() != appId)
            continue;

        found = item;
        break;
    }

    if (!found)
        return;

    Q_ASSERT(!found->isPinned());

    found->setPinned(true);

    int foundIndex = m_list.indexOf(found);

    if (foundIndex != pinAtIndex) {
        moveRows(foundIndex, 1, pinAtIndex);
    } else {
        QModelIndex modelIndex = index(foundIndex);
        Q_EMIT dataChanged(modelIndex, modelIndex);
    }

    pinLauncher(appId, true);
}
Beispiel #6
0
void LauncherModel::unpin(const QString &appId)
{
    if (!m_includePinnedApps)
        return;

    Application *found = Q_NULLPTR;

    Q_FOREACH (Application *item, m_list) {
        if (!item->isPinned())
            break;

        if (item->appId() != appId)
            continue;

        found = item;
    }

    if (!found)
        return;

    Q_ASSERT(found->isPinned());

    int i = m_list.indexOf(found);

    // Remove the item when unpinned and not running
    if (found->isRunning()) {
        found->setPinned(false);
        moveRows(i, 1, m_list.size() - 1);
    } else {
        beginRemoveRows(QModelIndex(), i, i);
        m_list.takeAt(i)->deleteLater();
        endRemoveRows();
    }

    pinLauncher(appId, false);
}
Beispiel #7
0
bool TransferModel::moveRows(const QVariant &sourceParent, int sourceRow, int count,
                             const QVariant &destinationParent, int destinationChild) {
    return moveRows(sourceParent.value<QModelIndex>(), sourceRow, count, destinationParent.value<QModelIndex>(),
                    destinationChild);
}
Beispiel #8
0
bool LauncherModel::moveRows(int sourceRow, int count, int destinationChild)
{
    return moveRows(QModelIndex(), sourceRow, count, QModelIndex(), destinationChild);
}