[app] Fixed the behavior of the position stack
It didn't do the right thing when it reached the depth limit.
This commit is contained in:
parent
e0eb60b8a1
commit
48cb24f8a1
1 changed files with 26 additions and 26 deletions
|
@ -396,40 +396,40 @@ void BooksPageStack::Private::push(BooksPos aPos, int aPage)
|
||||||
{
|
{
|
||||||
Entry last = iEntries.last();
|
Entry last = iEntries.last();
|
||||||
if (last.iPos != aPos || last.iPage != aPage) {
|
if (last.iPos != aPos || last.iPage != aPage) {
|
||||||
// We push on top of the current position. If we have reached
|
|
||||||
// the depth limit, we push the entire stack down
|
|
||||||
const int n = iEntries.count();
|
const int n = iEntries.count();
|
||||||
if (n >= MAX_DEPTH) {
|
if (n >= iCurrentIndex+2) {
|
||||||
|
// Push on top of the current position.
|
||||||
|
if (n > iCurrentIndex+2) {
|
||||||
|
// Drop unnecessary entries
|
||||||
|
iModel->beginRemoveRows(QModelIndex(), iCurrentIndex+2, n-1);
|
||||||
|
while (iEntries.count() > iCurrentIndex+2) {
|
||||||
|
iEntries.removeLast();
|
||||||
|
}
|
||||||
|
iModel->endRemoveRows();
|
||||||
|
Q_EMIT iModel->countChanged();
|
||||||
|
queueSignals(SignalCountChanged);
|
||||||
|
}
|
||||||
|
// And replace the next one
|
||||||
|
setPageAt(iCurrentIndex+1, aPage);
|
||||||
|
setCurrentIndex(iCurrentIndex+1);
|
||||||
|
} else if (n >= MAX_DEPTH) {
|
||||||
|
// We have reached the depth limit, push the entire stack down
|
||||||
|
const int oldCurrentPage = currentPage();
|
||||||
for (int i=1; i<n; i++) {
|
for (int i=1; i<n; i++) {
|
||||||
iEntries[i-1] = iEntries[i];
|
iEntries[i-1] = iEntries[i];
|
||||||
pageChanged(i-1);
|
pageChanged(i-1);
|
||||||
}
|
}
|
||||||
iEntries[n-1] = Entry(aPos, aPage);
|
iEntries[n-1] = Entry(aPos, aPage);
|
||||||
pageChanged(n-1);
|
pageChanged(n-1);
|
||||||
|
checkCurrentPage(oldCurrentPage);
|
||||||
} else {
|
} else {
|
||||||
if (n >= iCurrentIndex+2) {
|
// Just push the new one
|
||||||
if (n > iCurrentIndex+2) {
|
const int i = iCurrentIndex+1;
|
||||||
// Drop unnecessary entries
|
iModel->beginInsertRows(QModelIndex(), i, i);
|
||||||
iModel->beginRemoveRows(QModelIndex(), iCurrentIndex+2, n-1);
|
iEntries.append(Entry(aPos, aPage));
|
||||||
while (iEntries.count() > iCurrentIndex+2) {
|
iModel->endInsertRows();
|
||||||
iEntries.removeLast();
|
queueSignals(SignalCountChanged);
|
||||||
}
|
setCurrentIndex(i);
|
||||||
iModel->endRemoveRows();
|
|
||||||
Q_EMIT iModel->countChanged();
|
|
||||||
queueSignals(SignalCountChanged);
|
|
||||||
}
|
|
||||||
// And replace the next one
|
|
||||||
setPageAt(iCurrentIndex+1, aPage);
|
|
||||||
} else {
|
|
||||||
// Just push the new one
|
|
||||||
const int i = iCurrentIndex+1;
|
|
||||||
iModel->beginInsertRows(QModelIndex(), i, i);
|
|
||||||
iEntries.append(Entry(aPos, aPage));
|
|
||||||
iModel->endInsertRows();
|
|
||||||
queueSignals(SignalCountChanged);
|
|
||||||
}
|
|
||||||
// Move the current index
|
|
||||||
setCurrentIndex(iCurrentIndex+1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue