forked from qt-creator/qt-creator
QmlDesigner: Use single function trackWidgetFocusTime to track view usage
This is simpler and not all widgets get focus events. Change-Id: I91769abee7ee73017ba57811c124ddc509cac3fe Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -110,19 +110,6 @@ bool AssetsLibraryWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
return QObject::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::focusOutEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
QmlDesignerPlugin::emitUsageStatisticsTime(Constants::EVENT_ASSETSLIBRARY_TIME,
|
||||
m_usageTimer.elapsed());
|
||||
QFrame::focusOutEvent(focusEvent);
|
||||
}
|
||||
|
||||
void AssetsLibraryWidget::focusInEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
m_usageTimer.restart();
|
||||
QFrame::focusInEvent(focusEvent);
|
||||
}
|
||||
|
||||
AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFontImageCache,
|
||||
SynchronousImageCache &synchronousFontImageCache)
|
||||
: m_itemIconSize(24, 24)
|
||||
@@ -201,6 +188,8 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFon
|
||||
}
|
||||
});
|
||||
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_ASSETSLIBRARY_TIME);
|
||||
|
||||
// init the first load of the QML UI elements
|
||||
reloadQmlSource();
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include <previewtooltip/previewtooltipbackend.h>
|
||||
#include "assetslibrarymodel.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QFileIconProvider>
|
||||
#include <QFrame>
|
||||
#include <QPointF>
|
||||
@@ -90,8 +89,6 @@ signals:
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void focusOutEvent(QFocusEvent *focusEvent) override;
|
||||
void focusInEvent(QFocusEvent *focusEvent) override;
|
||||
|
||||
private:
|
||||
void reloadQmlSource();
|
||||
@@ -117,7 +114,6 @@ private:
|
||||
bool m_updateRetry = false;
|
||||
QString m_filterText;
|
||||
QPoint m_dragStartPoint;
|
||||
QElapsedTimer m_usageTimer;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -140,19 +140,6 @@ void ItemLibraryWidget::resizeEvent(QResizeEvent *event)
|
||||
isHorizontalLayout = event->size().width() >= HORIZONTAL_LAYOUT_WIDTH_LIMIT;
|
||||
}
|
||||
|
||||
void ItemLibraryWidget::focusOutEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
QmlDesignerPlugin::emitUsageStatisticsTime(Constants::EVENT_ITEMLIBRARY_TIME,
|
||||
m_usageTimer.elapsed());
|
||||
QFrame::focusOutEvent(focusEvent);
|
||||
}
|
||||
|
||||
void ItemLibraryWidget::focusInEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
m_usageTimer.restart();
|
||||
QFrame::focusInEvent(focusEvent);
|
||||
}
|
||||
|
||||
ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
|
||||
AsynchronousImageCache &asynchronousFontImageCache,
|
||||
SynchronousImageCache &synchronousFontImageCache)
|
||||
@@ -213,6 +200,8 @@ ItemLibraryWidget::ItemLibraryWidget(AsynchronousImageCache &imageCache,
|
||||
m_itemsWidget->engine()->addImageProvider("itemlibrary_preview",
|
||||
new ItemLibraryIconImageProvider{m_imageCache});
|
||||
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_ITEMLIBRARY_TIME);
|
||||
|
||||
// init the first load of the QML UI elements
|
||||
reloadQmlSource();
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@
|
||||
#include <utils/dropsupport.h>
|
||||
#include <previewtooltip/previewtooltipbackend.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QFileIconProvider>
|
||||
#include <QFrame>
|
||||
#include <QPointF>
|
||||
@@ -105,8 +104,6 @@ signals:
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void focusOutEvent(QFocusEvent *focusEvent) override;
|
||||
void focusInEvent(QFocusEvent *focusEvent) override;
|
||||
|
||||
private:
|
||||
void reloadQmlSource();
|
||||
@@ -135,7 +132,6 @@ private:
|
||||
QString m_filterText;
|
||||
QPoint m_dragStartPoint;
|
||||
bool m_subCompEditMode = false;
|
||||
QElapsedTimer m_usageTimer;
|
||||
|
||||
inline static int HORIZONTAL_LAYOUT_WIDTH_LIMIT = 600;
|
||||
};
|
||||
|
@@ -83,6 +83,8 @@ NavigatorWidget::NavigatorWidget(NavigatorView *view)
|
||||
sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
|
||||
setStyleSheet(Theme::replaceCssColors(QString::fromUtf8(sheet)));
|
||||
#endif
|
||||
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_NAVIGATORVIEW_TIME);
|
||||
}
|
||||
|
||||
void NavigatorWidget::setTreeModel(QAbstractItemModel *model)
|
||||
|
@@ -32,19 +32,7 @@ namespace QmlDesigner {
|
||||
|
||||
PropertyEditorWidget::PropertyEditorWidget(QWidget *parent) : QStackedWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void PropertyEditorWidget::focusOutEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
QmlDesignerPlugin::emitUsageStatisticsTime(Constants::EVENT_PROPERTYEDITOR_TIME,
|
||||
m_usageTimer.elapsed());
|
||||
QStackedWidget::focusOutEvent(focusEvent);
|
||||
}
|
||||
|
||||
void PropertyEditorWidget::focusInEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
m_usageTimer.restart();
|
||||
QStackedWidget::focusInEvent(focusEvent);
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_PROPERTYEDITOR_TIME);
|
||||
}
|
||||
|
||||
void PropertyEditorWidget::resizeEvent(QResizeEvent * event)
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QStackedWidget>
|
||||
|
||||
namespace QmlDesigner {
|
||||
@@ -42,12 +41,7 @@ signals:
|
||||
void resized();
|
||||
|
||||
protected:
|
||||
void focusOutEvent(QFocusEvent *focusEvent) override;
|
||||
void focusInEvent(QFocusEvent *focusEvent) override;
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
||||
private:
|
||||
QElapsedTimer m_usageTimer;
|
||||
};
|
||||
|
||||
} //QmlDesigner
|
||||
|
@@ -69,6 +69,7 @@ TextEditorWidget::TextEditorWidget(TextEditorView *textEditorView)
|
||||
m_updateSelectionTimer.setInterval(200);
|
||||
|
||||
connect(&m_updateSelectionTimer, &QTimer::timeout, this, &TextEditorWidget::updateSelectionByCursorPosition);
|
||||
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_TEXTEDITOR_TIME);
|
||||
}
|
||||
|
||||
void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor)
|
||||
@@ -241,17 +242,4 @@ void TextEditorWidget::dropEvent(QDropEvent *dropEvent)
|
||||
actionManager.handleExternalAssetsDrop(dropEvent->mimeData());
|
||||
}
|
||||
|
||||
void TextEditorWidget::focusOutEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
QmlDesignerPlugin::emitUsageStatisticsTime(Constants::EVENT_TEXTEDITOR_TIME,
|
||||
m_usageTimer.elapsed());
|
||||
QWidget::focusOutEvent(focusEvent);
|
||||
}
|
||||
|
||||
void TextEditorWidget::focusInEvent(QFocusEvent *focusEvent)
|
||||
{
|
||||
m_usageTimer.restart();
|
||||
QWidget::focusInEvent(focusEvent);
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
@@ -70,8 +69,6 @@ protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
void dragEnterEvent(QDragEnterEvent *dragEnterEvent) override;
|
||||
void dropEvent(QDropEvent *dropEvent) override;
|
||||
void focusOutEvent(QFocusEvent *focusEvent) override;
|
||||
void focusInEvent(QFocusEvent *focusEvent) override;
|
||||
|
||||
private:
|
||||
void updateSelectionByCursorPosition();
|
||||
@@ -84,7 +81,6 @@ private:
|
||||
QVBoxLayout *m_layout = nullptr;
|
||||
bool m_blockCursorSelectionSynchronisation = false;
|
||||
bool m_blockRoundTrip = false;
|
||||
QElapsedTimer m_usageTimer;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -123,8 +123,10 @@ const char EVENT_PROPERTYEDITOR_TIME[] = "propertyEditor";
|
||||
const char EVENT_ASSETSLIBRARY_TIME[] = "assetsLibrary";
|
||||
const char EVENT_ITEMLIBRARY_TIME[] = "itemLibrary";
|
||||
const char EVENT_TRANSLATIONVIEW_TIME[] = "translationView";
|
||||
const char EVENT_NAVIGATORVIEW_TIME[] = "navigatorView";
|
||||
const char EVENT_DESIGNMODE_TIME[] = "designMode";
|
||||
|
||||
|
||||
const char PROPERTY_EDITOR_CLASSNAME_PROPERTY[] = "__classNamePrivateInternal";
|
||||
|
||||
namespace Internal {
|
||||
|
@@ -678,6 +678,38 @@ void QmlDesignerPlugin::registerPreviewImageProvider(QQmlEngine *engine)
|
||||
m_instance->d->projectManager.registerPreviewImageProvider(engine);
|
||||
}
|
||||
|
||||
|
||||
bool isParent(QWidget *parent, QWidget *widget)
|
||||
{
|
||||
if (!widget)
|
||||
return false;
|
||||
|
||||
if (widget == parent)
|
||||
return true;
|
||||
|
||||
return isParent(parent, widget->parentWidget());
|
||||
}
|
||||
|
||||
void QmlDesignerPlugin::trackWidgetFocusTime(QWidget *widget, const QString &identifier)
|
||||
{
|
||||
connect(qApp,
|
||||
&QApplication::focusChanged,
|
||||
widget,
|
||||
[widget, identifier](QWidget *from, QWidget *to) {
|
||||
static QElapsedTimer widgetUsageTimer;
|
||||
static QString lastIdentifier;
|
||||
if (isParent(widget, to)) {
|
||||
if (!lastIdentifier.isEmpty())
|
||||
emitUsageStatisticsTime(lastIdentifier, widgetUsageTimer.elapsed());
|
||||
widgetUsageTimer.restart();
|
||||
lastIdentifier = identifier;
|
||||
} else if (isParent(widget, from) && lastIdentifier == identifier) {
|
||||
emitUsageStatisticsTime(identifier, widgetUsageTimer.elapsed());
|
||||
lastIdentifier.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void QmlDesignerPlugin::emitUsageStatisticsTime(const QString &identifier, int elapsed)
|
||||
{
|
||||
QTC_ASSERT(instance(), return);
|
||||
|
@@ -97,6 +97,8 @@ public:
|
||||
|
||||
static void registerPreviewImageProvider(QQmlEngine *engine);
|
||||
|
||||
static void trackWidgetFocusTime(QWidget *widget, const QString &identifier);
|
||||
|
||||
signals:
|
||||
void usageStatisticsNotifier(const QString &identifier);
|
||||
void usageStatisticsUsageTimer(const QString &identifier, int elapsed);
|
||||
|
Reference in New Issue
Block a user