1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 10:48:33 +01:00

Simplify Prev/NextEditableIndex a bit. Thanks christoph.gysin

This commit is contained in:
David Sansome 2010-03-26 00:32:44 +00:00
parent 766429c860
commit 5b468823d6

View File

@ -407,31 +407,23 @@ QList<int> PlaylistView::GetEditableColumns() {
QModelIndex PlaylistView::NextEditableIndex(const QModelIndex& current) {
QList<int> columns = GetEditableColumns();
QHeaderView* h = header();
int col = h->visualIndex(current.column());
QList<int> columns_left = columns.mid(columns.indexOf(col)+1);
int index = columns.indexOf(h->visualIndex(current.column()));
QModelIndex index;
if(columns_left.empty())
index = model()->index(current.row()+1, h->logicalIndex(columns.first()));
else
index = model()->index(current.row(), h->logicalIndex(columns_left.first()));
if(index+1 >= columns.size())
return model()->index(current.row()+1, h->logicalIndex(columns.first()));
return index;
return model()->index(current.row(), h->logicalIndex(columns[index+1]));
}
QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex& current) {
QList<int> columns = GetEditableColumns();
QHeaderView* h = header();
int col = h->visualIndex(current.column());
QList<int> columns_left = columns.mid(0, columns.indexOf(col));
int index = columns.indexOf(h->visualIndex(current.column()));
QModelIndex index;
if(columns_left.empty())
index = model()->index(current.row()-1, h->logicalIndex(columns.last()));
else
index = model()->index(current.row(), h->logicalIndex(columns_left.last()));
if(index-1 < 0)
return model()->index(current.row()-1, h->logicalIndex(columns.last()));
return index;
return model()->index(current.row(), h->logicalIndex(columns[index-1]));
}
void PlaylistView::closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint) {