forked from qt-creator/qt-creator
Timeline: Centralize the selection in zoom control.
This is where it logically belongs, given that trace, window, and range are already there. Also, it fixes the types to qint64, making it easier to reason about type conversions and numerical overflows. Change-Id: I2f88b2646b9a649d34bdf4fe87c37e7afdeee078 Task-number: QTCREATORBUG-14170 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
@@ -47,8 +47,6 @@ Rectangle {
|
|||||||
|
|
||||||
property bool selectionRangeMode: false
|
property bool selectionRangeMode: false
|
||||||
property bool selectionRangeReady: selectionRange.ready
|
property bool selectionRangeReady: selectionRange.ready
|
||||||
property real selectionRangeStart: selectionRange.startTime
|
|
||||||
property real selectionRangeEnd: selectionRange.startTime + selectionRange.duration
|
|
||||||
property int typeId: content.typeId
|
property int typeId: content.typeId
|
||||||
|
|
||||||
onTypeIdChanged: updateCursorPosition()
|
onTypeIdChanged: updateCursorPosition()
|
||||||
@@ -317,7 +315,12 @@ Rectangle {
|
|||||||
visible: parent.visible
|
visible: parent.visible
|
||||||
|
|
||||||
onRangeDoubleClicked: {
|
onRangeDoubleClicked: {
|
||||||
zoomControl.setRange(startTime, endTime);
|
var diff = 500 - zoomer.selectionDuration;
|
||||||
|
if (diff > 0)
|
||||||
|
zoomControl.setRange(zoomer.selectionStart - diff / 2,
|
||||||
|
zoomer.selectionEnd + diff / 2);
|
||||||
|
else
|
||||||
|
zoomControl.setRange(zoomer.selectionStart, zoomer.selectionEnd);
|
||||||
root.selectionRangeMode = false;
|
root.selectionRangeMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,16 +334,17 @@ Rectangle {
|
|||||||
|
|
||||||
id: selectionRangeDetails
|
id: selectionRangeDetails
|
||||||
visible: selectionRange.visible
|
visible: selectionRange.visible
|
||||||
startTime: selectionRange.startTime
|
startTime: zoomControl.selectionStart
|
||||||
duration: selectionRange.duration
|
duration: zoomControl.selectionDuration
|
||||||
endTime: selectionRange.endTime
|
endTime: zoomControl.selectionEnd
|
||||||
showDuration: selectionRange.rangeWidth > 1
|
showDuration: selectionRange.rangeWidth > 1
|
||||||
|
|
||||||
onRecenter: {
|
onRecenter: {
|
||||||
if ((selectionRange.startTime < zoomControl.rangeStart) ^
|
if ((zoomControl.selectionStart < zoomControl.rangeStart) ^
|
||||||
(selectionRange.endTime > zoomControl.rangeEnd)) {
|
(zoomControl.selectionEnd > zoomControl.rangeEnd)) {
|
||||||
var center = selectionRange.startTime + selectionRange.duration / 2;
|
var center = (zoomControl.selectionStart + zoomControl.selectionEnd) / 2;
|
||||||
var halfDuration = Math.max(selectionRange.duration, zoomControl.rangeDuration / 2);
|
var halfDuration = Math.max(zoomControl.selectionDuration,
|
||||||
|
zoomControl.rangeDuration) / 2;
|
||||||
zoomControl.setRange(center - halfDuration, center + halfDuration);
|
zoomControl.setRange(center - halfDuration, center + halfDuration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,10 +41,6 @@ RangeMover {
|
|||||||
|
|
||||||
property bool ready: visible && creationState === creationFinished
|
property bool ready: visible && creationState === creationFinished
|
||||||
|
|
||||||
property double startTime: rangeLeft * viewTimePerPixel + zoomer.windowStart
|
|
||||||
property double duration: Math.max(rangeWidth * viewTimePerPixel, 500)
|
|
||||||
property double endTime: startTime + duration
|
|
||||||
|
|
||||||
property double viewTimePerPixel: 1
|
property double viewTimePerPixel: 1
|
||||||
property double creationReference : 0
|
property double creationReference : 0
|
||||||
property int creationState : creationInactive
|
property int creationState : creationInactive
|
||||||
@@ -55,6 +51,14 @@ RangeMover {
|
|||||||
creationReference = 0;
|
creationReference = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateZoomer() {
|
||||||
|
zoomer.setSelection(rangeLeft * viewTimePerPixel + zoomer.windowStart,
|
||||||
|
rangeRight * viewTimePerPixel + zoomer.windowStart)
|
||||||
|
}
|
||||||
|
|
||||||
|
onRangeWidthChanged: updateZoomer()
|
||||||
|
onRangeLeftChanged: updateZoomer()
|
||||||
|
|
||||||
function setPos(pos) {
|
function setPos(pos) {
|
||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
|
|||||||
@@ -31,8 +31,10 @@
|
|||||||
|
|
||||||
namespace Timeline {
|
namespace Timeline {
|
||||||
|
|
||||||
TimelineZoomControl::TimelineZoomControl(QObject *parent) : QObject(parent), m_traceStart(-1), m_traceEnd(-1),
|
TimelineZoomControl::TimelineZoomControl(QObject *parent) : QObject(parent),
|
||||||
m_windowStart(-1), m_windowEnd(-1), m_rangeStart(-1), m_rangeEnd(-1), m_windowLocked(false)
|
m_traceStart(-1), m_traceEnd(-1), m_windowStart(-1), m_windowEnd(-1),
|
||||||
|
m_rangeStart(-1), m_rangeEnd(-1), m_selectionStart(-1), m_selectionEnd(-1),
|
||||||
|
m_windowLocked(false)
|
||||||
{
|
{
|
||||||
connect(&m_timer, &QTimer::timeout, this, &TimelineZoomControl::moveWindow);
|
connect(&m_timer, &QTimer::timeout, this, &TimelineZoomControl::moveWindow);
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,15 @@ void TimelineZoomControl::setRange(qint64 start, qint64 end)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimelineZoomControl::setSelection(qint64 start, qint64 end)
|
||||||
|
{
|
||||||
|
if (m_selectionStart != start || m_selectionEnd != end) {
|
||||||
|
m_selectionStart = start;
|
||||||
|
m_selectionEnd = end;
|
||||||
|
emit selectionChanged(start, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineZoomControl::setWindowLocked(bool windowLocked)
|
void TimelineZoomControl::setWindowLocked(bool windowLocked)
|
||||||
{
|
{
|
||||||
if (windowLocked != m_windowLocked) {
|
if (windowLocked != m_windowLocked) {
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ class TIMELINE_EXPORT TimelineZoomControl : public QObject {
|
|||||||
Q_PROPERTY(qint64 rangeEnd READ rangeEnd NOTIFY rangeChanged)
|
Q_PROPERTY(qint64 rangeEnd READ rangeEnd NOTIFY rangeChanged)
|
||||||
Q_PROPERTY(qint64 rangeDuration READ rangeDuration NOTIFY rangeChanged)
|
Q_PROPERTY(qint64 rangeDuration READ rangeDuration NOTIFY rangeChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(qint64 selectionStart READ selectionStart NOTIFY selectionChanged)
|
||||||
|
Q_PROPERTY(qint64 selectionEnd READ selectionEnd NOTIFY selectionChanged)
|
||||||
|
Q_PROPERTY(qint64 selectionDuration READ selectionDuration NOTIFY selectionChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool windowLocked READ windowLocked WRITE setWindowLocked NOTIFY windowLockedChanged)
|
Q_PROPERTY(bool windowLocked READ windowLocked WRITE setWindowLocked NOTIFY windowLockedChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -69,6 +73,10 @@ public:
|
|||||||
qint64 rangeEnd() const { return m_rangeEnd; }
|
qint64 rangeEnd() const { return m_rangeEnd; }
|
||||||
qint64 rangeDuration() const { return m_rangeEnd - m_rangeStart; }
|
qint64 rangeDuration() const { return m_rangeEnd - m_rangeStart; }
|
||||||
|
|
||||||
|
qint64 selectionStart() const { return m_selectionStart; }
|
||||||
|
qint64 selectionEnd() const { return m_selectionEnd; }
|
||||||
|
qint64 selectionDuration() const { return m_selectionEnd - m_selectionStart; }
|
||||||
|
|
||||||
bool windowLocked() const { return m_windowLocked; }
|
bool windowLocked() const { return m_windowLocked; }
|
||||||
virtual void clear();
|
virtual void clear();
|
||||||
|
|
||||||
@@ -76,11 +84,13 @@ signals:
|
|||||||
void traceChanged(qint64 start, qint64 end);
|
void traceChanged(qint64 start, qint64 end);
|
||||||
void windowChanged(qint64 start, qint64 end);
|
void windowChanged(qint64 start, qint64 end);
|
||||||
void rangeChanged(qint64 start, qint64 end);
|
void rangeChanged(qint64 start, qint64 end);
|
||||||
|
void selectionChanged(qint64 start, qint64 end);
|
||||||
void windowLockedChanged(bool windowLocked);
|
void windowLockedChanged(bool windowLocked);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTrace(qint64 start, qint64 end);
|
void setTrace(qint64 start, qint64 end);
|
||||||
void setRange(qint64 start, qint64 end);
|
void setRange(qint64 start, qint64 end);
|
||||||
|
void setSelection(qint64 start, qint64 end);
|
||||||
void setWindowLocked(bool windowLocked);
|
void setWindowLocked(bool windowLocked);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
@@ -93,6 +103,8 @@ protected:
|
|||||||
qint64 m_windowEnd;
|
qint64 m_windowEnd;
|
||||||
qint64 m_rangeStart;
|
qint64 m_rangeStart;
|
||||||
qint64 m_rangeEnd;
|
qint64 m_rangeEnd;
|
||||||
|
qint64 m_selectionStart;
|
||||||
|
qint64 m_selectionEnd;
|
||||||
|
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
bool m_windowLocked;
|
bool m_windowLocked;
|
||||||
|
|||||||
@@ -171,18 +171,12 @@ bool QmlProfilerTraceView::hasValidSelection() const
|
|||||||
|
|
||||||
qint64 QmlProfilerTraceView::selectionStart() const
|
qint64 QmlProfilerTraceView::selectionStart() const
|
||||||
{
|
{
|
||||||
QQuickItem *rootObject = d->m_mainView->rootObject();
|
return d->m_zoomControl->selectionStart();
|
||||||
if (rootObject)
|
|
||||||
return rootObject->property("selectionRangeStart").toLongLong();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 QmlProfilerTraceView::selectionEnd() const
|
qint64 QmlProfilerTraceView::selectionEnd() const
|
||||||
{
|
{
|
||||||
QQuickItem *rootObject = d->m_mainView->rootObject();
|
return d->m_zoomControl->selectionEnd();
|
||||||
if (rootObject)
|
|
||||||
return rootObject->property("selectionRangeEnd").toLongLong();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerTraceView::clear()
|
void QmlProfilerTraceView::clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user