Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
1.2 KB
Raw Blame
/*
 *  SPDX-FileCopyrightText: 2019 Tusooa Zhu <[email protected]>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "KisSnapshotView.h"
#include "KisSnapshotModel.h"

#include <kis_assert.h>

struct KisSnapshotView::Private
{
    KisSnapshotModel *model;
};

KisSnapshotView::KisSnapshotView()
    : QListView()
    , m_d(new Private)
{
    setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
}

KisSnapshotView::~KisSnapshotView()
{
}

void KisSnapshotView::setModel(QAbstractItemModel *model)
{
    KisSnapshotModel *snapshotModel = dynamic_cast<KisSnapshotModel *>(model);
    if (snapshotModel) {
        QListView::setModel(model);
        m_d->model = snapshotModel;
    }
}

void KisSnapshotView::slotSwitchToSelectedSnapshot()
{
    KIS_ASSERT_RECOVER_RETURN(m_d->model);
    QModelIndexList indexes = selectedIndexes();
    if (indexes.size() != 1) {
        return;
    }
    m_d->model->slotSwitchToSnapshot(indexes[0]);
}

void KisSnapshotView::slotRemoveSelectedSnapshot()
{
    KIS_ASSERT_RECOVER_RETURN(m_d->model);
    QModelIndexList indexes = selectedIndexes();
    Q_FOREACH (QModelIndex index, indexes) {
        m_d->model->slotRemoveSnapshot(index);
    }
}