| 271 | }; |
| 272 | |
| 273 | std::pair<QWidget*, bool> ToolViewWidgetCache::prepareViewWidget(View& view, QWidget* parent) |
| 274 | { |
| 275 | const auto* const document = view.document(); |
| 276 | Q_ASSERT(document); |
| 277 | |
| 278 | if (auto* const widget = view.widget()) { |
| 279 | Q_ASSERT(m_widgets.value(document).widget() == widget); |
| 280 | qCDebug(SUBLIME) << "the view already has a tool view widget" << document->documentSpecifier(); |
| 281 | return {widget, false}; |
| 282 | } |
| 283 | |
| 284 | auto& cachedWidget = m_widgets[document]; |
| 285 | |
| 286 | if (auto* const widget = cachedWidget.widget()) { |
| 287 | cachedWidget.addUse(); |
| 288 | view.setSharedWidget(widget); |
| 289 | qCDebug(SUBLIME).nospace() << "reusing an existing tool view widget " << document->documentSpecifier() |
| 290 | << ", use count: " << cachedWidget.useCount(); |
| 291 | return {widget, false}; |
| 292 | } |
| 293 | |
| 294 | auto* const widget = view.initializeWidget(parent); |
| 295 | Q_ASSERT(widget); |
| 296 | cachedWidget.initializeWidget(widget); |
| 297 | qCDebug(SUBLIME) << "created a new tool view widget" << document->documentSpecifier(); |
| 298 | return {widget, true}; |
| 299 | } |
| 300 | |
| 301 | bool ToolViewWidgetCache::disuse(const View& view) |
| 302 | { |
no test coverage detected