12 #include "TabWidgetQuick_p.h"
16 #include "../Frame_p.h"
19 #include <QScopedValueRollback>
23 TabWidgetQuick::TabWidgetQuick(Frame *parent)
24 : QWidgetAdapter(parent)
25 , TabWidget(this, parent)
26 , m_dockWidgetModel(new DockWidgetModel(this))
27 , m_tabBar(
Config::self().frameworkWidgetFactory()->createTabBar(this))
29 connect(m_dockWidgetModel, &DockWidgetModel::countChanged,
this,
31 if (m_currentDockWidget && indexOfDockWidget(m_currentDockWidget) == -1) {
33 if (numDockWidgets() > 0)
34 setCurrentDockWidget(0);
37 Q_EMIT countChanged(); });
40 TabBar *TabWidgetQuick::tabBar()
const
45 int TabWidgetQuick::numDockWidgets()
const
47 return m_dockWidgetModel->count();
52 m_dockWidgetModel->remove(dw);
55 int TabWidgetQuick::indexOfDockWidget(
const DockWidgetBase *dw)
const
57 return m_dockWidgetModel->indexOf(dw);
60 bool TabWidgetQuick::isPositionDraggable(
QPoint p)
const
66 void TabWidgetQuick::setCurrentDockWidget(
int index)
70 if (m_currentDockWidget != dw) {
71 m_currentDockWidget = dw;
72 Q_EMIT currentDockWidgetChanged(dw);
73 Q_EMIT currentTabChanged(index);
77 QObject *TabWidgetQuick::tabBarObj()
const
79 return m_tabBar->asWidget();
85 return m_dockWidgetModel->insert(dw, index);
88 void TabWidgetQuick::setTabBarAutoHide(
bool)
90 qWarning() << Q_FUNC_INFO <<
"Not implemented";
93 void TabWidgetQuick::renameTab(
int index,
const QString &)
96 qWarning() << Q_FUNC_INFO <<
"Not implemented";
99 void TabWidgetQuick::changeTabIcon(
int index,
const QIcon &)
102 qWarning() << Q_FUNC_INFO <<
"Not implemented";
107 return m_dockWidgetModel->dockWidgetAt(index);
110 int TabWidgetQuick::currentIndex()
const
112 if (!m_currentDockWidget)
115 const int index = indexOfDockWidget(m_currentDockWidget);
118 qWarning() << Q_FUNC_INFO <<
"Unexpected null index for" << m_currentDockWidget <<
this
119 <<
"; count=" << m_dockWidgetModel->count();
124 DockWidgetModel *TabWidgetQuick::dockWidgetModel()
const
126 return m_dockWidgetModel;
129 DockWidgetModel::DockWidgetModel(
QObject *parent)
134 int DockWidgetModel::count()
const
136 return m_dockWidgets.size();
139 int DockWidgetModel::rowCount(
const QModelIndex &parent)
const
141 return parent.
isValid() ? 0 : m_dockWidgets.size();
146 const int row = index.
row();
147 if (row < 0 || row >= m_dockWidgets.size())
162 if (index < 0 || index >= m_dockWidgets.size()) {
167 return m_dockWidgets[index];
172 return m_dockWidgets.contains(dw);
177 return { { Role_Title,
"title" } };
182 const int row = indexOf(dw);
184 qWarning() << Q_FUNC_INFO <<
"Couldn't find" << dw;
187 Q_EMIT dataChanged(index, index);
194 const int row = indexOf(dw);
196 if (!m_removeGuard) {
199 qWarning() << Q_FUNC_INFO <<
"Nothing to remove"
200 <<
static_cast<void *
>(dw);
203 const auto connections = m_connections.take(dw);
208 m_dockWidgets.removeOne(dw);
211 Q_EMIT countChanged();
222 if (m_dockWidgets.contains(dw)) {
223 qWarning() << Q_FUNC_INFO <<
"Shouldn't happen";
228 emitDataChangedFor(dw);
235 m_connections[dw] = { conn, conn2 };
238 m_dockWidgets.insert(index, dw);
241 Q_EMIT countChanged();