Falkon Develop
Cross-platform Qt-based web browser
tabtreemodel.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#pragma once
19
20#include <QAbstractProxyModel>
21
22#include "qzcommon.h"
23
24class QTimer;
25
26class WebTab;
27class BrowserWindow;
29
30class FALKON_EXPORT TabTreeModel : public QAbstractProxyModel
31{
32 Q_OBJECT
33
34public:
35 explicit TabTreeModel(BrowserWindow *window, QObject *parent = nullptr);
36 ~TabTreeModel() override;
37
38 QModelIndex tabIndex(WebTab *tab) const;
39 WebTab *tab(const QModelIndex &index) const;
40
41 Qt::ItemFlags flags(const QModelIndex &index) const override;
42 QVariant data(const QModelIndex &index, int role) const override;
43 int rowCount(const QModelIndex &parent) const override;
44 int columnCount(const QModelIndex &parent) const override;
45 bool hasChildren(const QModelIndex &parent) const override;
46 QModelIndex parent(const QModelIndex &child) const override;
47 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
48
49 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
50 QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
51
52 bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
53 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
54
55private:
56 void init();
57 QModelIndex index(TabTreeModelItem *item) const;
58 TabTreeModelItem *item(const QModelIndex &index) const;
59 TabTreeModelItem *createItems(TabTreeModelItem *root);
60
61 void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
62 void sourceRowsInserted(const QModelIndex &parent, int start, int end);
63 void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
64 void sourceReset();
65
66 void insertIndex(const QModelIndex &sourceIndex);
67 void removeIndex(const QModelIndex &sourceIndex);
68 void connectTab(WebTab *tab);
69 void syncTopLevelTabs();
70
71 BrowserWindow *m_window;
72 TabTreeModelItem *m_root = nullptr;
73 QHash<WebTab*, TabTreeModelItem*> m_items;
74};
Definition: webtab.h:40
#define FALKON_EXPORT
Definition: qzcommon.h:28