File indexing completed on 2024-05-12 04:58:24

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include <QAbstractProxyModel>
0021 
0022 #include "qzcommon.h"
0023 
0024 class WebTab;
0025 class BrowserWindow;
0026 
0027 class TabMruModelItem;
0028 
0029 class FALKON_EXPORT TabMruModel : public QAbstractProxyModel
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     explicit TabMruModel(BrowserWindow *window, QObject *parent = nullptr);
0035     ~TabMruModel() override;
0036 
0037     QModelIndex tabIndex(WebTab *tab) const;
0038     WebTab *tab(const QModelIndex &index) const;
0039 
0040     Qt::ItemFlags flags(const QModelIndex &index) const override;
0041     int rowCount(const QModelIndex &parent) const override;
0042     int columnCount(const QModelIndex &parent) const override;
0043     QModelIndex parent(const QModelIndex &index) const override;
0044     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0045 
0046     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
0047     QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
0048 
0049 private:
0050     void init();
0051     QModelIndex index(TabMruModelItem *item) const;
0052     TabMruModelItem *item(const QModelIndex &index) const;
0053 
0054     void currentTabChanged(int index);
0055     void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
0056     void sourceRowsInserted(const QModelIndex &parent, int start, int end);
0057     void sourceRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
0058     void sourceReset();
0059 
0060     BrowserWindow *m_window;
0061     TabMruModelItem *m_root = nullptr;
0062     QHash<WebTab*, TabMruModelItem*> m_items;
0063 };