File indexing completed on 2024-12-22 04:14:57

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Tusooa Zhu <tusooa@vista.aero>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisSnapshotView.h"
0008 #include "KisSnapshotModel.h"
0009 
0010 #include <kis_assert.h>
0011 
0012 struct KisSnapshotView::Private
0013 {
0014     KisSnapshotModel *model;
0015 };
0016 
0017 KisSnapshotView::KisSnapshotView()
0018     : QListView()
0019     , m_d(new Private)
0020 {
0021     setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
0022 }
0023 
0024 KisSnapshotView::~KisSnapshotView()
0025 {
0026 }
0027 
0028 void KisSnapshotView::setModel(QAbstractItemModel *model)
0029 {
0030     KisSnapshotModel *snapshotModel = dynamic_cast<KisSnapshotModel *>(model);
0031     if (snapshotModel) {
0032         QListView::setModel(model);
0033         m_d->model = snapshotModel;
0034     }
0035 }
0036 
0037 void KisSnapshotView::slotSwitchToSelectedSnapshot()
0038 {
0039     KIS_ASSERT_RECOVER_RETURN(m_d->model);
0040     QModelIndexList indexes = selectedIndexes();
0041     if (indexes.size() != 1) {
0042         return;
0043     }
0044     m_d->model->slotSwitchToSnapshot(indexes[0]);
0045 }
0046 
0047 void KisSnapshotView::slotRemoveSelectedSnapshot()
0048 {
0049     KIS_ASSERT_RECOVER_RETURN(m_d->model);
0050     QModelIndexList indexes = selectedIndexes();
0051     Q_FOREACH (QModelIndex index, indexes) {
0052         m_d->model->slotRemoveSnapshot(index);
0053     }
0054 }
0055