1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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()
{
QList<int> list;
foreach(QTreeWidgetItem * item, ui->historyTree->selectedItems()) {
if (!item) {
return;
continue;
}
if (!item->parent()) {
QList<QTreeWidgetItem*> items;
for (int i = 0; i < item->childCount(); i++) {
QTreeWidgetItem* children = item->child(i);
int id = children->whatsThis(1).toInt();
m_historyModel->deleteHistoryEntry(id);
if (children->isHidden()) {
continue;
}
ui->historyTree->deleteItem(children);
int id = children->whatsThis(1).toInt();
list.append(id);
m_ignoredIds.append(id);
items.append(children);
}
ui->historyTree->deleteItem(item);
if (item->childCount() == 0) {
items.append(item);
}
ui->historyTree->deleteItems(items);
}
else {
int id = item->whatsThis(1).toInt();
m_historyModel->deleteHistoryEntry(id);
list.append(id);
m_ignoredIds.append(id);
ui->historyTree->deleteItem(item);
m_ignoredIds.append(id);
}
}
m_historyModel->deleteHistoryEntry(list);
}
void HistoryManager::historyEntryAdded(const HistoryEntry &entry)

View File

@ -19,10 +19,10 @@
#include "tabbedwebview.h"
#include "qupzilla.h"
#include "iconprovider.h"
#include "databasewriter.h"
#include "settings.h"
#include <QThread>
#include <QSqlDatabase>
#include <QSqlQuery>
HistoryModel::HistoryModel(QupZilla* mainClass)
: QObject()
@ -31,14 +31,8 @@ HistoryModel::HistoryModel(QupZilla* mainClass)
{
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(signalDeleteHistoryEntry(int)), this, SLOT(slotDeleteHistoryEntry(int)));
connect(this, SIGNAL(signalDeleteHistoryEntry(QList<int>)), this, SLOT(slotDeleteHistoryEntry(QList<int>)));
}
void HistoryModel::loadSettings()
@ -123,7 +117,15 @@ void HistoryModel::slotAddHistoryEntry(const QUrl &url, QString title)
// DeleteHistoryEntry
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)
@ -138,32 +140,41 @@ void HistoryModel::deleteHistoryEntry(const QString &url, const QString &title)
deleteHistoryEntry(id);
}
}
void HistoryModel::slotDeleteHistoryEntry(int index)
#include <QDebug>
void HistoryModel::slotDeleteHistoryEntry(const QList<int> &list)
{
QSqlQuery query;
query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?");
query.bindValue(0, index);
query.exec();
if (!query.next()) {
return;
QSqlDatabase db = QSqlDatabase::database();
db.transaction();
foreach (int index, list) {
QSqlQuery query;
query.prepare("SELECT id, count, date, url, title FROM history WHERE id=?");
query.bindValue(0, index);
query.exec();
if (!query.next()) {
qDebug() << "invalid id" << index;
continue;
}
HistoryEntry entry;
entry.id = query.value(0).toInt();
entry.count = query.value(1).toInt();
entry.date = QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong());
entry.url = query.value(3).toUrl();
entry.title = query.value(4).toString();
query.prepare("DELETE FROM history WHERE id=?");
query.bindValue(0, index);
query.exec();
query.prepare("DELETE FROM icons WHERE url=?");
query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment));
query.exec();
emit historyEntryDeleted(entry);
}
HistoryEntry entry;
entry.id = query.value(0).toInt();
entry.count = query.value(1).toInt();
entry.date = QDateTime::fromMSecsSinceEpoch(query.value(2).toLongLong());
entry.url = query.value(3).toUrl();
entry.title = query.value(4).toString();
query.prepare("DELETE FROM history WHERE id=?");
query.bindValue(0, index);
query.exec();
query.prepare("DELETE FROM icons WHERE url=?");
query.bindValue(0, entry.url.toEncoded(QUrl::RemoveFragment));
query.exec();
emit historyEntryDeleted(entry);
db.commit();
}
bool HistoryModel::urlIsStored(const QString &url)

View File

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

View File

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

View File

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

View File

@ -213,3 +213,10 @@ void TreeWidget::deleteItem(QTreeWidgetItem* 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 deleteItem(QTreeWidgetItem* item);
void deleteItems(const QList<QTreeWidgetItem*> &items);
signals:
void itemControlClicked(QTreeWidgetItem* item);