Skip to content

Commit 57b2ebc

Browse files
Add pin and remove pin in setData
1 parent a8999d4 commit 57b2ebc

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/zGui/zClipboardModel.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "include/zClipboardModel.hpp"
2-
32
#include <QImage>
43
#include <QPixmap>
54

@@ -161,9 +160,24 @@ bool zTableModel::setData(const QModelIndex &index, const QVariant &value, int r
161160
zClipboardItem &item = mData[index.row()];
162161
item.isPinned = (value.toInt() == Qt::Checked);
163162

164-
m_SqlManager.updatePinStatus(item.hash, item.isPinned);
163+
const int oldRow = index.row();
164+
const int newRow = item.isPinned ? 0 : mData.size();
165+
166+
if (oldRow == newRow) {
167+
m_SqlManager.updatePinStatus(item.hash, item.isPinned);
168+
emit dataChanged(index, index, {Qt::CheckStateRole});
169+
170+
return true;
171+
}
172+
173+
beginMoveRows(QModelIndex(), oldRow, oldRow, QModelIndex(), newRow);
174+
175+
const zClipboardItem movedItem = mData.takeAt(oldRow);
176+
const int adjustedNewRow = (oldRow < newRow) ? newRow - 1 : newRow;
177+
mData.insert(adjustedNewRow, movedItem);
178+
179+
endMoveRows();
165180

166-
emit dataChanged(index, index, {Qt::CheckStateRole});
167181
return true;
168182
}
169183

0 commit comments

Comments
 (0)