diff options
Diffstat (limited to 'src/history.cpp')
-rw-r--r-- | src/history.cpp | 310 |
1 files changed, 180 insertions, 130 deletions
diff --git a/src/history.cpp b/src/history.cpp index 5c545b10..96efd3e5 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -46,12 +46,12 @@ static const unsigned int HISTORY_VERSION = 23; HistoryManager::HistoryManager(QObject *parent) - : QWebHistoryInterface(parent) - , m_saveTimer(new AutoSaver(this)) - , m_historyLimit(30) - , m_historyModel(0) - , m_historyFilterModel(0) - , m_historyTreeModel(0) + : QWebHistoryInterface(parent) + , m_saveTimer(new AutoSaver(this)) + , m_historyLimit(30) + , m_historyModel(0) + , m_historyFilterModel(0) + , m_historyTreeModel(0) { m_expiredTimer.setSingleShot(true); connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); @@ -106,9 +106,12 @@ void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAn checkForExpired(); - if (loadedAndSorted) { + if (loadedAndSorted) + { m_lastSavedUrl = m_history.value(0).url; - } else { + } + else + { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); } @@ -142,13 +145,17 @@ void HistoryManager::checkForExpired() QDateTime now = QDateTime::currentDateTime(); int nextTimeout = 0; - while (!m_history.isEmpty()) { + while (!m_history.isEmpty()) + { QDateTime checkForExpired = m_history.last().dateTime; checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit)); - if (now.daysTo(checkForExpired) > 7) { + if (now.daysTo(checkForExpired) > 7) + { // check at most in a week to prevent int overflows on the timer nextTimeout = 7 * 86400; - } else { + } + else + { nextTimeout = now.secsTo(checkForExpired); } if (nextTimeout > 0) @@ -179,9 +186,9 @@ void HistoryManager::addHistoryItem(const HistoryItem &item) void HistoryManager::updateHistoryItem(const KUrl &url, const QString &title) { - for (int i = 0; i < m_history.count(); ++i) + for (int i = 0; i < m_history.count(); ++i) { - if (url == m_history.at(i).url) + if (url == m_history.at(i).url) { m_history[i].title = title; m_saveTimer->changeOccurred(); @@ -223,16 +230,16 @@ void HistoryManager::clear() void HistoryManager::loadSettings() { int historyExpire = ReKonfig::expireHistory(); - int days; - switch (historyExpire) + int days; + switch (historyExpire) { - case 0: days = 1; break; - case 1: days = 7; break; - case 2: days = 14; break; - case 3: days = 30; break; - case 4: days = 365; break; - case 5: days = -1; break; - default: days = -1; + case 0: days = 1; break; + case 1: days = 7; break; + case 2: days = 14; break; + case 3: days = 30; break; + case 4: days = 365; break; + case 5: days = -1; break; + default: days = -1; } m_historyLimit = days; } @@ -243,10 +250,10 @@ void HistoryManager::load() loadSettings(); QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile( historyFilePath ); + QFile historyFile(historyFilePath); if (!historyFile.exists()) return; - if (!historyFile.open(QFile::ReadOnly)) + if (!historyFile.open(QFile::ReadOnly)) { kWarning() << "Unable to open history file" << historyFile.fileName(); return; @@ -261,7 +268,7 @@ void HistoryManager::load() QDataStream stream; QBuffer buffer; stream.setDevice(&buffer); - while ( !historyFile.atEnd() ) + while (!historyFile.atEnd()) { in >> data; buffer.close(); @@ -279,26 +286,26 @@ void HistoryManager::load() if (!item.dateTime.isValid()) continue; - if ( item == lastInsertedItem ) + if (item == lastInsertedItem) { if (lastInsertedItem.title.isEmpty() && !list.isEmpty()) list[0].title = item.title; continue; } - if ( !needToSort && !list.isEmpty() && lastInsertedItem < item ) + if (!needToSort && !list.isEmpty() && lastInsertedItem < item) needToSort = true; list.prepend(item); lastInsertedItem = item; } if (needToSort) - qSort( list.begin(), list.end() ); + qSort(list.begin(), list.end()); setHistory(list, true); // If we had to sort re-write the whole history sorted - if (needToSort) + if (needToSort) { m_lastSavedUrl = QString(); m_saveTimer->changeOccurred(); @@ -310,12 +317,12 @@ void HistoryManager::save() { bool saveAll = m_lastSavedUrl.isEmpty(); int first = m_history.count() - 1; - if (!saveAll) + if (!saveAll) { // find the first one to save - for (int i = 0; i < m_history.count(); ++i) + for (int i = 0; i < m_history.count(); ++i) { - if (m_history.at(i).url == m_lastSavedUrl) + if (m_history.at(i).url == m_lastSavedUrl) { first = i - 1; break; @@ -326,30 +333,30 @@ void HistoryManager::save() saveAll = true; QString historyFilePath = KStandardDirs::locateLocal("appdata" , "history"); - QFile historyFile( historyFilePath ); + QFile historyFile(historyFilePath); // When saving everything use a temporary file to prevent possible data loss. QTemporaryFile tempFile; tempFile.setAutoRemove(false); bool open = false; - if (saveAll) + if (saveAll) { open = tempFile.open(); } - else + else { open = historyFile.open(QFile::Append); } - if (!open) + if (!open) { kWarning() << "Unable to open history file for saving" - << (saveAll ? tempFile.fileName() : historyFile.fileName()); + << (saveAll ? tempFile.fileName() : historyFile.fileName()); return; } QDataStream out(saveAll ? &tempFile : &historyFile); - for (int i = first; i >= 0; --i) + for (int i = first; i >= 0; --i) { QByteArray data; QDataStream stream(&data, QIODevice::WriteOnly); @@ -359,7 +366,7 @@ void HistoryManager::save() } tempFile.close(); - if (saveAll) + if (saveAll) { if (historyFile.exists() && !historyFile.remove()) kWarning() << "History: error removing old history." << historyFile.errorString(); @@ -374,8 +381,8 @@ void HistoryManager::save() HistoryModel::HistoryModel(HistoryManager *history, QObject *parent) - : QAbstractTableModel(parent) - , m_history(history) + : QAbstractTableModel(parent) + , m_history(history) { Q_ASSERT(m_history); connect(m_history, SIGNAL(historyReset()), this, SLOT(historyReset())); @@ -408,12 +415,12 @@ void HistoryModel::entryUpdated(int offset) QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal - && role == Qt::DisplayRole) + && role == Qt::DisplayRole) { - switch (section) + switch (section) { - case 0: return i18n("Title"); - case 1: return i18n("Address"); + case 0: return i18n("Title"); + case 1: return i18n("Address"); } } return QAbstractTableModel::headerData(section, orientation, role); @@ -427,7 +434,7 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const return QVariant(); const HistoryItem &item = lst.at(index.row()); - switch (role) + switch (role) { case DateTimeRole: return item.dateTime; @@ -438,23 +445,27 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const case UrlStringRole: return item.url; case Qt::DisplayRole: - case Qt::EditRole: { - switch (index.column()) { - case 0: - // when there is no title try to generate one from the url - if (item.title.isEmpty()) { - QString page = QFileInfo(QUrl(item.url).path()).fileName(); - if (!page.isEmpty()) - return page; - return item.url; - } - return item.title; - case 1: + case Qt::EditRole: + { + switch (index.column()) + { + case 0: + // when there is no title try to generate one from the url + if (item.title.isEmpty()) + { + QString page = QFileInfo(QUrl(item.url).path()).fileName(); + if (!page.isEmpty()) + return page; return item.url; + } + return item.title; + case 1: + return item.url; } - } + } case Qt::DecorationRole: - if (index.column() == 0) { + if (index.column() == 0) + { return Application::instance()->icon(item.url); } } @@ -502,8 +513,8 @@ bool HistoryModel::removeRows(int row, int count, const QModelIndex &parent) Maps the first bunch of items of the source model to the root */ HistoryMenuModel::HistoryMenuModel(HistoryTreeModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent) - , m_treeModel(sourceModel) + : QAbstractProxyModel(parent) + , m_treeModel(sourceModel) { setSourceModel(sourceModel); } @@ -529,16 +540,18 @@ int HistoryMenuModel::rowCount(const QModelIndex &parent) const if (parent.column() > 0) return 0; - if (!parent.isValid()) { + if (!parent.isValid()) + { int folders = sourceModel()->rowCount(); int bumpedItems = bumpedRows(); if (bumpedItems <= MOVEDROWS - && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) + && bumpedItems == sourceModel()->rowCount(sourceModel()->index(0, 0))) --folders; return bumpedItems + folders; } - if (parent.internalId() == -1) { + if (parent.internalId() == -1) + { if (parent.row() < bumpedRows()) return 0; } @@ -565,7 +578,8 @@ QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const if (!proxyIndex.isValid()) return QModelIndex(); - if (proxyIndex.internalId() == -1) { + if (proxyIndex.internalId() == -1) + { int bumpedItems = bumpedRows(); if (proxyIndex.row() < bumpedItems) return m_treeModel->index(proxyIndex.row(), proxyIndex.column(), m_treeModel->index(0, 0)); @@ -583,8 +597,8 @@ QModelIndex HistoryMenuModel::mapToSource(const QModelIndex &proxyIndex) const QModelIndex HistoryMenuModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 - || column < 0 || column >= columnCount(parent) - || parent.column() > 0) + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) return QModelIndex(); if (!parent.isValid()) return createIndex(row, column, -1); @@ -625,8 +639,8 @@ QModelIndex HistoryMenuModel::parent(const QModelIndex &index) const HistoryMenu::HistoryMenu(QWidget *parent) - : ModelMenu(parent) - , m_history(0) + : ModelMenu(parent) + , m_history(0) { connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); setHoverRole(HistoryModel::UrlStringRole); @@ -641,7 +655,7 @@ void HistoryMenu::activated(const QModelIndex &index) bool HistoryMenu::prePopulated() { - if (!m_history) + if (!m_history) { m_history = Application::historyManager(); m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); @@ -663,11 +677,11 @@ void HistoryMenu::postPopulated() if (m_history->history().count() > 0) addSeparator(); - KAction *showAllAction = new KAction( i18n("Show All History"), this); + KAction *showAllAction = new KAction(i18n("Show All History"), this); connect(showAllAction, SIGNAL(triggered()), this, SLOT(showHistoryDialog())); addAction(showAllAction); - KAction *clearAction = new KAction( i18n("Clear History"), this); + KAction *clearAction = new KAction(i18n("Clear History"), this); connect(clearAction, SIGNAL(triggered()), m_history, SLOT(clear())); addAction(clearAction); } @@ -746,12 +760,13 @@ void HistoryDialog::customContextMenuRequested(const QPoint &pos) QMenu menu; QModelIndex index = tree->indexAt(pos); index = index.sibling(index.row(), 0); - if (index.isValid() && !tree->model()->hasChildren(index)) { - menu.addAction( i18n("Open"), this, SLOT(open())); + if (index.isValid() && !tree->model()->hasChildren(index)) + { + menu.addAction(i18n("Open"), this, SLOT(open())); menu.addSeparator(); - menu.addAction( i18n("Copy"), this, SLOT(copy())); + menu.addAction(i18n("Copy"), this, SLOT(copy())); } - menu.addAction( i18n("Delete"), tree, SLOT(removeOne())); + menu.addAction(i18n("Delete"), tree, SLOT(removeOne())); menu.exec(QCursor::pos()); } @@ -780,8 +795,8 @@ void HistoryDialog::copy() // --------------------------------------------------------------------------------------------------------------- HistoryFilterModel::HistoryFilterModel(QAbstractItemModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent), - m_loaded(false) + : QAbstractProxyModel(parent), + m_loaded(false) { setSourceModel(sourceModel); } @@ -804,23 +819,25 @@ QVariant HistoryFilterModel::data(const QModelIndex &index, int role) const void HistoryFilterModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (sourceModel()) { + if (sourceModel()) + { m_loaded = false; connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); + this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), @@ -885,8 +902,10 @@ QModelIndex HistoryFilterModel::mapFromSource(const QModelIndex &sourceIndex) co int realRow = -1; int sourceModelRow = sourceModel()->rowCount() - sourceIndex.row(); - for (int i = 0; i < m_sourceRow.count(); ++i) { - if (m_sourceRow.at(i) == sourceModelRow) { + for (int i = 0; i < m_sourceRow.count(); ++i) + { + if (m_sourceRow.at(i) == sourceModelRow) + { realRow = i; break; } @@ -902,7 +921,7 @@ QModelIndex HistoryFilterModel::index(int row, int column, const QModelIndex &pa { load(); if (row < 0 || row >= rowCount(parent) - || column < 0 || column >= columnCount(parent)) + || column < 0 || column >= columnCount(parent)) return QModelIndex(); return createIndex(row, column, m_sourceRow[row]); @@ -922,10 +941,12 @@ void HistoryFilterModel::load() const m_sourceRow.clear(); m_historyHash.clear(); m_historyHash.reserve(sourceModel()->rowCount()); - for (int i = 0; i < sourceModel()->rowCount(); ++i) { + for (int i = 0; i < sourceModel()->rowCount(); ++i) + { QModelIndex idx = sourceModel()->index(i, 0); QString url = idx.data(HistoryModel::UrlStringRole).toString(); - if (!m_historyHash.contains(url)) { + if (!m_historyHash.contains(url)) + { m_sourceRow.append(sourceModel()->rowCount() - i); m_historyHash[url] = sourceModel()->rowCount() - i; } @@ -942,7 +963,8 @@ void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start return; QModelIndex idx = sourceModel()->index(start, 0, parent); QString url = idx.data(HistoryModel::UrlStringRole).toString(); - if (m_historyHash.contains(url)) { + if (m_historyHash.contains(url)) + { int sourceRow = sourceModel()->rowCount() - m_historyHash[url]; int realRow = mapFromSource(sourceModel()->index(sourceRow, 0)).row(); beginRemoveRows(QModelIndex(), realRow, realRow); @@ -975,7 +997,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren return false; int lastRow = row + count - 1; disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); beginRemoveRows(parent, row, lastRow); int oldCount = rowCount(); int start = sourceModel()->rowCount() - m_sourceRow.value(row); @@ -983,7 +1005,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren sourceModel()->removeRows(start, end - start + 1); endRemoveRows(); connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); m_loaded = false; if (oldCount - count != rowCount()) reset(); @@ -995,7 +1017,7 @@ bool HistoryFilterModel::removeRows(int row, int count, const QModelIndex &paren HistoryCompletionModel::HistoryCompletionModel(QObject *parent) - : QAbstractProxyModel(parent) + : QAbstractProxyModel(parent) { } @@ -1003,12 +1025,14 @@ HistoryCompletionModel::HistoryCompletionModel(QObject *parent) QVariant HistoryCompletionModel::data(const QModelIndex &index, int role) const { if (sourceModel() - && (role == Qt::EditRole || role == Qt::DisplayRole) - && index.isValid()) { + && (role == Qt::EditRole || role == Qt::DisplayRole) + && index.isValid()) + { QModelIndex idx = mapToSource(index); idx = idx.sibling(idx.row(), 1); QString urlString = idx.data(HistoryModel::UrlStringRole).toString(); - if (index.row() % 2) { + if (index.row() % 2) + { QUrl url = urlString; QString s = url.toString(QUrl::RemoveScheme | QUrl::RemoveUserInfo @@ -1052,7 +1076,7 @@ QModelIndex HistoryCompletionModel::mapToSource(const QModelIndex &proxyIndex) c QModelIndex HistoryCompletionModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 || row >= rowCount(parent) - || column < 0 || column >= columnCount(parent)) + || column < 0 || column >= columnCount(parent)) return QModelIndex(); return createIndex(row, column, 0); } @@ -1066,17 +1090,19 @@ QModelIndex HistoryCompletionModel::parent(const QModelIndex &) const void HistoryCompletionModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceReset())); + this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceReset())); + this, SLOT(sourceReset())); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (newSourceModel) { + if (newSourceModel) + { connect(newSourceModel, SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceReset())); @@ -1098,7 +1124,7 @@ void HistoryCompletionModel::sourceReset() HistoryTreeModel::HistoryTreeModel(QAbstractItemModel *sourceModel, QObject *parent) - : QAbstractProxyModel(parent) + : QAbstractProxyModel(parent) { setSourceModel(sourceModel); } @@ -1112,25 +1138,30 @@ QVariant HistoryTreeModel::headerData(int section, Qt::Orientation orientation, QVariant HistoryTreeModel::data(const QModelIndex &index, int role) const { - if ((role == Qt::EditRole || role == Qt::DisplayRole)) { + if ((role == Qt::EditRole || role == Qt::DisplayRole)) + { int start = index.internalId(); - if (start == 0) { + if (start == 0) + { int offset = sourceDateRow(index.row()); - if (index.column() == 0) { + if (index.column() == 0) + { QModelIndex idx = sourceModel()->index(offset, 0); QDate date = idx.data(HistoryModel::DateRole).toDate(); if (date == QDate::currentDate()) return i18n("Earlier Today"); return date.toString(QLatin1String("dddd, MMMM d, yyyy")); } - if (index.column() == 1) { + if (index.column() == 1) + { return QString(rowCount(index.sibling(index.row(), 0))) + i18n(" items") ; } } } if (role == Qt::DecorationRole && index.column() == 0 && !index.parent().isValid()) return KIcon("view-history"); - if (role == HistoryModel::DateRole && index.column() == 0 && index.internalId() == 0) { + if (role == HistoryModel::DateRole && index.column() == 0 && index.internalId() == 0) + { int offset = sourceDateRow(index.row()); QModelIndex idx = sourceModel()->index(offset, 0); return idx.data(HistoryModel::DateRole); @@ -1148,22 +1179,25 @@ int HistoryTreeModel::columnCount(const QModelIndex &parent) const int HistoryTreeModel::rowCount(const QModelIndex &parent) const { - if ( parent.internalId() != 0 - || parent.column() > 0 - || !sourceModel()) + if (parent.internalId() != 0 + || parent.column() > 0 + || !sourceModel()) return 0; // row count OF dates - if (!parent.isValid()) { + if (!parent.isValid()) + { if (!m_sourceRowCache.isEmpty()) return m_sourceRowCache.count(); QDate currentDate; int rows = 0; int totalRows = sourceModel()->rowCount(); - for (int i = 0; i < totalRows; ++i) { + for (int i = 0; i < totalRows; ++i) + { QDate rowDate = sourceModel()->index(i, 0).data(HistoryModel::DateRole).toDate(); - if (rowDate != currentDate) { + if (rowDate != currentDate) + { m_sourceRowCache.append(i); currentDate = rowDate; ++rows; @@ -1189,7 +1223,8 @@ int HistoryTreeModel::sourceDateRow(int row) const if (m_sourceRowCache.isEmpty()) rowCount(QModelIndex()); - if (row >= m_sourceRowCache.count()) { + if (row >= m_sourceRowCache.count()) + { if (!sourceModel()) return 0; return sourceModel()->rowCount(); @@ -1211,8 +1246,8 @@ QModelIndex HistoryTreeModel::mapToSource(const QModelIndex &proxyIndex) const QModelIndex HistoryTreeModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 - || column < 0 || column >= columnCount(parent) - || parent.column() > 0) + || column < 0 || column >= columnCount(parent) + || parent.column() > 0) return QModelIndex(); if (!parent.isValid()) @@ -1252,13 +1287,17 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent) if (row < 0 || count <= 0 || row + count > rowCount(parent)) return false; - if (parent.isValid()) { + if (parent.isValid()) + { // removing pages int offset = sourceDateRow(parent.row()); return sourceModel()->removeRows(offset + row, count); - } else { + } + else + { // removing whole dates - for (int i = row + count - 1; i >= row; --i) { + for (int i = row + count - 1; i >= row; --i) + { QModelIndex dateParent = index(i, 0); int offset = sourceDateRow(dateParent.row()); if (!sourceModel()->removeRows(offset, rowCount(dateParent))) @@ -1271,18 +1310,20 @@ bool HistoryTreeModel::removeRows(int row, int count, const QModelIndex &parent) void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel) { - if (sourceModel()) { + if (sourceModel()) + { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); + this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } QAbstractProxyModel::setSourceModel(newSourceModel); - if (newSourceModel) { + if (newSourceModel) + { connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), @@ -1306,7 +1347,8 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, { Q_UNUSED(parent); // Avoid warnings when compiling release Q_ASSERT(!parent.isValid()); - if (start != 0 || start != end) { + if (start != 0 || start != end) + { m_sourceRowCache.clear(); reset(); return; @@ -1315,10 +1357,13 @@ void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, m_sourceRowCache.clear(); QModelIndex treeIndex = mapFromSource(sourceModel()->index(start, 0)); QModelIndex treeParent = treeIndex.parent(); - if (rowCount(treeParent) == 1) { + if (rowCount(treeParent) == 1) + { beginInsertRows(QModelIndex(), 0, 0); endInsertRows(); - } else { + } + else + { beginInsertRows(treeParent, treeIndex.row(), treeIndex.row()); endInsertRows(); } @@ -1349,11 +1394,13 @@ void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, i Q_ASSERT(!parent.isValid()); if (m_sourceRowCache.isEmpty()) return; - for (int i = end; i >= start;) { + for (int i = end; i >= start;) + { QList<int>::iterator it; it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), i); // playing it safe - if (it == m_sourceRowCache.end()) { + if (it == m_sourceRowCache.end()) + { m_sourceRowCache.clear(); reset(); return; @@ -1366,11 +1413,14 @@ void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, i QModelIndex dateParent = index(row, 0); // If we can remove all the rows in the date do that and skip over them int rc = rowCount(dateParent); - if (i - rc + 1 == offset && start <= i - rc + 1) { + if (i - rc + 1 == offset && start <= i - rc + 1) + { beginRemoveRows(QModelIndex(), row, row); m_sourceRowCache.removeAt(row); i -= rc + 1; - } else { + } + else + { beginRemoveRows(dateParent, i - offset, i - offset); ++row; --i; |