##// END OF EJS Templates
Fix bug when canceling acquisition
Fix bug when canceling acquisition

File last commit:

r1110:029fbf916457
r1399:5f9a7b80e8f3
Show More
TimeWidget.cpp
154 lines | 4.0 KiB | text/x-c | CppLexer
Add the TimeWidget
r134 #include "TimeWidget/TimeWidget.h"
#include "ui_TimeWidget.h"
Alexandre Leroux
Passes TimeWidget in UTC...
r489 #include <Common/DateUtils.h>
Drop of variable, graph and zones on the time widget
r884 #include <Common/MimeTypesDef.h>
Rename "DragDropHelper" in "DragDropGuiController"
r1110 #include <DragAndDrop/DragDropGuiController.h>
Add apply button and its connection for timewidget
r302 #include <SqpApplication.h>
#include <Time/TimeController.h>
add TimeWidget connection
r192
Drag of the time widget on a graph
r885 #include <QDrag>
Drop of variable, graph and zones on the time widget
r884 #include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
Drag of the time widget on a graph
r885
struct TimeWidget::TimeWidgetPrivate {
explicit TimeWidgetPrivate() {}
QPoint m_DragStartPosition;
};
TimeWidget::TimeWidget(QWidget *parent)
: QWidget{parent},
ui{new Ui::TimeWidget},
impl{spimpl::make_unique_impl<TimeWidgetPrivate>()}
Add the TimeWidget
r134 {
ui->setupUi(this);
add TimeWidget connection
r192
Add apply button and its connection for timewidget
r302 ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton));
add TimeWidget connection
r192 // Connection
connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
&TimeWidget::onTimeUpdateRequested);
connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
&TimeWidget::onTimeUpdateRequested);
Add apply button and its connection for timewidget
r302
connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(),
&TimeController::onTimeNotify);
Temporal parameters of the selected variables can be updated using the...
r304
// Initialisation
Alexandre Leroux
Passes TimeWidget in UTC...
r489 auto endDateTime = QDateTime::currentDateTimeUtc();
auto startDateTime = endDateTime.addSecs(-3600); // one hour before
ui->startDateTimeEdit->setDateTime(startDateTime);
ui->endDateTimeEdit->setDateTime(endDateTime);
Change SqpRange for SqpDateTime
r512 auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime),
DateUtils::secondsSinceEpoch(endDateTime)};
Temporal parameters of the selected variables can be updated using the...
r304
sqpApp->timeController().onTimeToUpdate(dateTime);
Add the TimeWidget
r134 }
Add apply button and its connection for timewidget
r302
Add the TimeWidget
r134 TimeWidget::~TimeWidget()
{
delete ui;
}
add TimeWidget connection
r192
Drop of variable, graph and zones on the time widget
r884 void TimeWidget::setTimeRange(SqpRange time)
{
auto startDateTime = DateUtils::dateTime(time.m_TStart);
auto endDateTime = DateUtils::dateTime(time.m_TEnd);
ui->startDateTimeEdit->setDateTime(startDateTime);
ui->endDateTimeEdit->setDateTime(endDateTime);
}
Drag of the time widget on a graph
r885 SqpRange TimeWidget::timeRange() const
add TimeWidget connection
r192 {
Drag of the time widget on a graph
r885 return SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())};
}
add TimeWidget connection
r192
Drag of the time widget on a graph
r885 void TimeWidget::onTimeUpdateRequested()
{
auto dateTime = timeRange();
add TimeWidget connection
r192 emit timeUpdated(std::move(dateTime));
}
Drop of variable, graph and zones on the time widget
r884
void TimeWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
event->acceptProposedAction();
setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
}
else {
event->ignore();
}
}
void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
code improvements
r980 setStyleSheet(QString{});
Drop of variable, graph and zones on the time widget
r884 }
void TimeWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
auto timeRange = TimeController::timeRangeForMimeData(mimeData);
setTimeRange(timeRange);
}
else {
event->ignore();
}
code improvements
r980 setStyleSheet(QString{});
Drop of variable, graph and zones on the time widget
r884 }
Drag of the time widget on a graph
r885
void TimeWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
impl->m_DragStartPosition = event->pos();
}
QWidget::mousePressEvent(event);
}
void TimeWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton)) {
return;
}
if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
< QApplication::startDragDistance()) {
return;
}
// Note: The management of the drag object is done by Qt
auto drag = new QDrag{this};
auto mimeData = new QMimeData;
auto timeData = TimeController::mimeDataForTimeRange(timeRange());
mimeData->setData(MIME_TYPE_TIME_RANGE, timeData);
drag->setMimeData(mimeData);
show a clock icon during the drag of the TimeWidget
r976 auto pixmap = QPixmap{":/icones/time.png"};
drag->setPixmap(pixmap.scaledToWidth(22));
Drag of the time widget on a graph
r885
Rename "DragDropHelper" in "DragDropGuiController"
r1110 sqpApp->dragDropGuiController().resetDragAndDrop();
Drag of the time widget on a graph
r885
// Note: The exec() is blocking on windows but not on linux and macOS
drag->exec(Qt::MoveAction | Qt::CopyAction);
QWidget::mouseMoveEvent(event);
}