1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Fixed deleting history entries in history manager.

- also significally improved performance when deleting more
  entries at once
This commit is contained in:
nowrep 2012-03-10 12:21:45 +01:00
parent c9d39d06ee
commit 6ed52fd732
7 changed files with 77 additions and 48 deletions

View File

@ -124,30 +124,45 @@ void HistoryManager::copyUrl()
void HistoryManager::deleteItem() void HistoryManager::deleteItem()
{ {
QList<int> list;
foreach(QTreeWidgetItem * item, ui->historyTree->selectedItems()) { foreach(QTreeWidgetItem * item, ui->historyTree->selectedItems()) {
if (!item) { if (!item) {
return; continue;
} }
if (!item->parent()) { if (!item->parent()) {
QList<QTreeWidgetItem*> items;
for (int i = 0; i < item->childCount(); i++) { for (int i = 0; i < item->childCount(); i++) {
QTreeWidgetItem* children = item->child(i); QTreeWidgetItem* children = item->child(i);
int id = children->whatsThis(1).toInt(); if (children->isHidden()) {
m_historyModel->deleteHistoryEntry(id); continue;
ui->historyTree->deleteItem(children);
m_ignoredIds.append(id);
} }
ui->historyTree->deleteItem(item);
int id = children->whatsThis(1).toInt();
list.append(id);
m_ignoredIds.append(id);
items.append(children);
}
if (item->childCount() == 0) {
items.append(item);
}
ui->historyTree->deleteItems(items);
} }
else { else {
int id = item->whatsThis(1).toInt(); int id = item->whatsThis(1).toInt();
m_historyModel->deleteHistoryEntry(id);
list.append(id);
m_ignoredIds.append(id);
ui->historyTree->deleteItem(item); ui->historyTree->deleteItem(item);
m_ignoredIds.append(id);
} }
} }
m_historyModel->deleteHistoryEntry(list);
} }
void HistoryManager::historyEntryAdded(const HistoryEntry &entry) void HistoryManager::historyEntryAdded(const HistoryEntry &entry)

View File

@ -19,10 +19,10 @@
#include "tabbedwebview.h" #include "tabbedwebview.h"
#include "qupzilla.h" #include "qupzilla.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "databasewriter.h"
#include "settings.h" #include "settings.h"
#include <QThread> #include <QSqlDatabase>
#include <QSqlQuery>
HistoryModel::HistoryModel(QupZilla* mainClass) HistoryModel::HistoryModel(QupZilla* mainClass)
: QObject() : QObject()
@ -31,14 +31,8 @@ HistoryModel::HistoryModel(QupZilla* mainClass)
{ {
loadSettings(); loadSettings();
qRegisterMetaType<HistoryEntry>("HistoryEntry");
QThread* t = new QThread(this);
t->start();
moveToThread(t);
connect(this, SIGNAL(signalAddHistoryEntry(QUrl, QString)), this, SLOT(slotAddHistoryEntry(QUrl, QString))); connect(this, SIGNAL(signalAddHistoryEntry(QUrl, QString)), this, SLOT(slotAddHistoryEntry(QUrl, QString)));
connect(this, SIGNAL(signalDeleteHistoryEntry(int)), this, SLOT(slotDeleteHistoryEntry(int))); connect(this, SIGNAL(signalDeleteHistoryEntry(QList<int>)), this, SLOT(slotDeleteHistoryEntry(QList<int>)));
} }
void HistoryModel::loadSettings() void HistoryModel::loadSettings()
@ -123,7 +117,15 @@ void HistoryModel::slotAddHistoryEntry(const QUrl &url, QString title)
// DeleteHistoryEntry // DeleteHistoryEntry
void HistoryModel::deleteHistoryEntry(int index) void HistoryModel::deleteHistoryEntry(int index)
{ {
emit signalDeleteHistoryEntry(index); QList<int> list;
list.append(index);
deleteHistoryEntry(list);
}
void HistoryModel::deleteHistoryEntry(const QList<int> &list)
{
emit signalDeleteHistoryEntry(list);
} }
void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title) void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
@ -138,15 +140,20 @@ void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
deleteHistoryEntry(id); deleteHistoryEntry(id);
} }
} }
#include <QDebug>
void HistoryModel::slotDeleteHistoryEntry(int index) void HistoryModel::slotDeleteHistoryEntry(const QList<int> &list)
{ {
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
foreach (int index, list) {
QSqlQuery query; QSqlQuery query;
query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?"); query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?");
query.bindValue(0, index); query.bindValue(0, index);
query.exec(); query.exec();
if (!query.next()) { if (!query.next()) {
return; qDebug() << "invalid id" << index;
continue;
} }
HistoryEntry entry; HistoryEntry entry;
@ -159,11 +166,15 @@ void HistoryModel::slotDeleteHistoryEntry(int index)
query.prepare("DELETE FROM history WHERE id=?"); query.prepare("DELETE FROM history WHERE id=?");
query.bindValue(0, index); query.bindValue(0, index);
query.exec(); query.exec();
query.prepare("DELETE FROM icons WHERE url=?"); query.prepare("DELETE FROM icons WHERE url=?");
query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment)); query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment));
query.exec(); query.exec();
emit historyEntryDeleted(entry); emit historyEntryDeleted(entry);
}
db.commit();
} }
bool HistoryModel::urlIsStored(const QString &url) bool HistoryModel::urlIsStored(const QString &url)

View File

@ -50,6 +50,7 @@ public:
void addHistoryEntry(const QUrl &url, QString title); void addHistoryEntry(const QUrl &url, QString title);
void deleteHistoryEntry(int index); void deleteHistoryEntry(int index);
void deleteHistoryEntry(const QList<int> &list);
void deleteHistoryEntry(const QString &url, const QString &title); void deleteHistoryEntry(const QString &url, const QString &title);
bool urlIsStored(const QString &url); bool urlIsStored(const QString &url);
@ -65,7 +66,7 @@ public:
private slots: private slots:
void slotAddHistoryEntry(const QUrl &url, QString title); void slotAddHistoryEntry(const QUrl &url, QString title);
void slotDeleteHistoryEntry(int index); void slotDeleteHistoryEntry(const QList<int> &list);
signals: signals:
void historyEntryAdded(HistoryEntry entry); void historyEntryAdded(HistoryEntry entry);
@ -75,7 +76,7 @@ signals:
void historyClear(); void historyClear();
void signalAddHistoryEntry(QUrl url, QString title); void signalAddHistoryEntry(QUrl url, QString title);
void signalDeleteHistoryEntry(int index); void signalDeleteHistoryEntry(QList<int> list);
private: private:
bool m_isSaving; bool m_isSaving;

View File

@ -17,15 +17,11 @@
* ============================================================ */ * ============================================================ */
#include "databasewriter.h" #include "databasewriter.h"
#include <QThread>
#include <QTimer> #include <QTimer>
DatabaseWriter::DatabaseWriter() DatabaseWriter::DatabaseWriter()
: QObject() : QObject()
{ {
QThread* t = new QThread(this);
t->start();
moveToThread(t);
} }
void DatabaseWriter::executeQuery(const QSqlQuery &query) void DatabaseWriter::executeQuery(const QSqlQuery &query)

View File

@ -28,8 +28,6 @@ namespace Ui
class PageScreen; class PageScreen;
} }
class QAbstractButton;
class WebView; class WebView;
class QT_QUPZILLA_EXPORT PageScreen : public QDialog class QT_QUPZILLA_EXPORT PageScreen : public QDialog

View File

@ -213,3 +213,10 @@ void TreeWidget::deleteItem(QTreeWidgetItem* item)
delete item; delete item;
} }
void TreeWidget::deleteItems(const QList<QTreeWidgetItem *> &items)
{
m_refreshAllItemsNeeded = true;
qDeleteAll(items);
}

View File

@ -41,6 +41,7 @@ public:
void insertTopLevelItems(int index, const QList<QTreeWidgetItem*> &items); void insertTopLevelItems(int index, const QList<QTreeWidgetItem*> &items);
void deleteItem(QTreeWidgetItem* item); void deleteItem(QTreeWidgetItem* item);
void deleteItems(const QList<QTreeWidgetItem*> &items);
signals: signals:
void itemControlClicked(QTreeWidgetItem* item); void itemControlClicked(QTreeWidgetItem* item);