52 return QSL(
"application/falkon.tabmodel.tab");
57 : QAbstractListModel(parent)
65 const int idx = m_tabs.indexOf(
tab);
74 return m_tabs.value(index.row());
79 if (parent.isValid()) {
82 return m_tabs.count();
87 if (!index.isValid()) {
88 return Qt::ItemIsDropEnabled;
90 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
95 if (index.row() < 0 || index.row() > m_tabs.count()) {
106 return QVariant::fromValue(
t);
109 case Qt::DisplayRole:
113 case Qt::DecorationRole:
117 return t->isPinned();
120 return t->isRestored();
123 return t->isCurrentTab();
126 return t->isLoading();
129 return t->isPlaying();
135 return t->backgroundActivity();
144 return Qt::MoveAction;
154 if (indexes.isEmpty()) {
169 if (action != Qt::MoveAction || parent.isValid() || column > 0 || !m_window) {
172 const auto *
mimeData = qobject_cast<const TabModelMimeData*>(
data);
200 tab->
setPinned(row < m_window->tabWidget()->pinnedTabsCount());
217 connect(m_window, &QObject::destroyed,
this, [
this]() {
225void TabModel::tabInserted(
int index)
229 beginInsertRows(QModelIndex(), index, index);
230 m_tabs.insert(index,
tab);
233 auto emitDataChanged = [
this](
WebTab *
tab,
int role) {
235 Q_EMIT dataChanged(idx, idx, {role});
251void TabModel::tabRemoved(
int index)
253 beginRemoveRows(QModelIndex(), index, index);
254 m_tabs.remove(index);
258void TabModel::tabMoved(
int from,
int to)
260 if (!beginMoveRows(QModelIndex(), from, from, QModelIndex(), to > from ? to + 1 : to)) {
261 qWarning() <<
"Invalid beginMoveRows" << from << (to > from ? to + 1 : to);
264 m_tabs.insert(to, m_tabs.takeAt(from));
TabWidget * tabWidget() const
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
QStringList mimeTypes() const override
Qt::DropActions supportedDropActions() const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
WebTab * tab(const QModelIndex &index) const
Qt::ItemFlags flags(const QModelIndex &index) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
QMimeData * mimeData(const QModelIndexList &indexes) const override
TabModel(BrowserWindow *window, QObject *parent=nullptr)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex tabIndex(WebTab *tab) const
QStringList formats() const override
static QString mimeType()
bool hasFormat(const QString &format) const override
void setPinned(bool state)
void mutedChanged(bool muted)
void titleChanged(const QString &title)
void currentTabChanged(bool current)
void restoredChanged(bool restored)
void iconChanged(const QIcon &icon)
void pinnedChanged(bool pinned)
BrowserWindow * browserWindow() const
void backgroundActivityChanged(bool activity)
void loadingChanged(bool loading)
void playingChanged(bool playing)