mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-24 04:36:34 +01:00
HistoryModel: Fixed deleting top level item (month, day)
- when it was not fetched
This commit is contained in:
parent
770a9762a9
commit
2b7b28db37
@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "historyitem.h"
|
||||
#include "globalfunctions.h"
|
||||
|
||||
HistoryItem::HistoryItem(HistoryItem* parent)
|
||||
: canFetchMore(false)
|
||||
@ -81,23 +82,19 @@ void HistoryItem::insertChild(int row, HistoryItem* child)
|
||||
|
||||
void HistoryItem::removeChild(int row)
|
||||
{
|
||||
if (m_children.count() > row) {
|
||||
if (qz_listContainsIndex(m_children, row)) {
|
||||
removeChild(m_children.at(row));
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryItem::removeChild(HistoryItem* child)
|
||||
{
|
||||
int index = m_children.indexOf(child);
|
||||
|
||||
if (index != -1) {
|
||||
m_children.removeOne(child);
|
||||
}
|
||||
}
|
||||
|
||||
HistoryItem* HistoryItem::child(int row) const
|
||||
{
|
||||
if (m_children.count() > row) {
|
||||
if (qz_listContainsIndex(m_children, row)) {
|
||||
return m_children.at(row);
|
||||
}
|
||||
|
||||
|
@ -235,6 +235,30 @@ HistoryItem* HistoryModel::itemFromIndex(const QModelIndex &index) const
|
||||
return m_rootItem;
|
||||
}
|
||||
|
||||
void HistoryModel::removeTopLevelIndexes(const QList<QPersistentModelIndex> &indexes)
|
||||
{
|
||||
foreach(const QPersistentModelIndex & index, indexes) {
|
||||
if (index.parent().isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
HistoryItem* item = m_rootItem->child(row);
|
||||
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
beginRemoveRows(QModelIndex(), row, row);
|
||||
delete item;
|
||||
endRemoveRows();
|
||||
|
||||
if (item == m_todayItem) {
|
||||
m_todayItem = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryModel::resetHistory()
|
||||
{
|
||||
beginResetModel();
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
|
||||
HistoryItem* itemFromIndex(const QModelIndex &index) const;
|
||||
|
||||
void removeTopLevelIndexes(const QList<QPersistentModelIndex> &indexes);
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
|
@ -66,6 +66,8 @@ void HistoryView::removeItems()
|
||||
QList<int> list;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
QList<QPersistentModelIndex> topLevelIndexes;
|
||||
|
||||
foreach(const QModelIndex & index, selectedIndexes()) {
|
||||
if (index.column() > 0) {
|
||||
continue;
|
||||
@ -76,6 +78,8 @@ void HistoryView::removeItems()
|
||||
qint64 end = index.data(HistoryModel::TimestampEndRole).toLongLong();
|
||||
|
||||
list.append(m_history->indexesFromTimeRange(start, end));
|
||||
|
||||
topLevelIndexes.append(index);
|
||||
}
|
||||
else {
|
||||
int id = index.data(HistoryModel::IdRole).toInt();
|
||||
@ -86,6 +90,8 @@ void HistoryView::removeItems()
|
||||
}
|
||||
|
||||
m_history->deleteHistoryEntry(list);
|
||||
m_history->model()->removeTopLevelIndexes(topLevelIndexes);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user