2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#ifndef HISTORYMODEL_H
|
|
|
|
#define HISTORYMODEL_H
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
class QTimer;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
class History;
|
|
|
|
class HistoryItem;
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_EXPORT HistoryModel : public QAbstractItemModel
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-04-30 16:33:14 +02:00
|
|
|
enum Roles {
|
|
|
|
IdRole = Qt::UserRole + 1,
|
|
|
|
TitleRole = Qt::UserRole + 2,
|
|
|
|
UrlRole = Qt::UserRole + 3,
|
|
|
|
UrlStringRole = Qt::UserRole + 4,
|
|
|
|
IconRole = Qt::UserRole + 5,
|
|
|
|
IconLoadedRole = Qt::UserRole + 6,
|
|
|
|
IsTopLevelRole = Qt::UserRole + 7,
|
|
|
|
TimestampStartRole = Qt::UserRole + 8,
|
|
|
|
TimestampEndRole = Qt::UserRole + 9,
|
|
|
|
MaxRole = TimestampEndRole
|
2011-04-25 20:56:45 +02:00
|
|
|
};
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
explicit HistoryModel(History* history);
|
2011-07-30 17:57:14 +02:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
2011-12-17 14:30:54 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QModelIndex parent(const QModelIndex &child) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
2011-12-17 14:30:54 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
bool canFetchMore(const QModelIndex &parent) const;
|
|
|
|
void fetchMore(const QModelIndex &parent);
|
2011-05-06 20:05:49 +02:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
bool hasChildren(const QModelIndex &parent) const;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
HistoryItem* itemFromIndex(const QModelIndex &index) const;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-07-04 00:21:08 +02:00
|
|
|
void removeTopLevelIndexes(const QList<QPersistentModelIndex> &indexes);
|
|
|
|
|
2011-04-25 20:56:45 +02:00
|
|
|
signals:
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
private slots:
|
|
|
|
void resetHistory();
|
|
|
|
|
|
|
|
void historyEntryAdded(const HistoryEntry &entry);
|
|
|
|
void historyEntryDeleted(const HistoryEntry &entry);
|
|
|
|
void historyEntryEdited(const HistoryEntry &before, const HistoryEntry &after);
|
2011-12-17 14:30:54 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
private:
|
2012-04-30 16:33:14 +02:00
|
|
|
HistoryItem* findHistoryItem(const HistoryEntry &entry);
|
|
|
|
void checkEmptyParentItem(HistoryItem* item);
|
|
|
|
void init();
|
|
|
|
|
|
|
|
HistoryItem* m_rootItem;
|
|
|
|
HistoryItem* m_todayItem;
|
|
|
|
History* m_history;
|
2011-03-02 16:57:41 +01:00
|
|
|
};
|
|
|
|
|
2014-02-19 22:12:32 +01:00
|
|
|
class QUPZILLA_EXPORT HistoryFilterModel : public QSortFilterProxyModel
|
2012-04-30 16:33:14 +02:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit HistoryFilterModel(QAbstractItemModel* parent);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setFilterFixedString(const QString &pattern);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void expandAllItems();
|
|
|
|
void collapseAllItems();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void startFiltering();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_pattern;
|
|
|
|
QTimer* m_filterTimer;
|
|
|
|
};
|
2012-01-23 17:30:34 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
#endif // HISTORYMODEL_H
|