##// END OF EJS Templates
temp commit
Alexandre Leroux -
r970:63eae7d6c90b
parent child
Show More
@@ -1,100 +1,101
1 #include <DataSource/DataSourceWidget.h>
1 #include <DataSource/DataSourceWidget.h>
2
2
3 #include <ui_DataSourceWidget.h>
3 #include <ui_DataSourceWidget.h>
4
4
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetHelper.h>
6 #include <DataSource/DataSourceTreeWidgetHelper.h>
7 #include <DataSource/DataSourceTreeWidgetItem.h>
7 #include <DataSource/DataSourceTreeWidgetItem.h>
8
8
9 #include <QMenu>
9 #include <QMenu>
10
10
11 namespace {
11 namespace {
12
12
13 /// Number of columns displayed in the tree
13 /// Number of columns displayed in the tree
14 const auto TREE_NB_COLUMNS = 1;
14 const auto TREE_NB_COLUMNS = 1;
15
15
16 /// Header labels for the tree
16 /// Header labels for the tree
17 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
17 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
18
18
19 /**
19 /**
20 * Creates the item associated to a data source
20 * Creates the item associated to a data source
21 * @param dataSource the data source for which to create the item
21 * @param dataSource the data source for which to create the item
22 * @return the new item
22 * @return the new item
23 */
23 */
24 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
24 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
25 {
25 {
26 // Creates item for the data source
26 // Creates item for the data source
27 auto item = new DataSourceTreeWidgetItem{dataSource};
27 auto item = new DataSourceTreeWidgetItem{dataSource};
28
28
29 // Generates items for the children of the data source
29 // Generates items for the children of the data source
30 for (auto i = 0; i < dataSource->childCount(); ++i) {
30 for (auto i = 0; i < dataSource->childCount(); ++i) {
31 item->addChild(createTreeWidgetItem(dataSource->child(i)));
31 item->addChild(createTreeWidgetItem(dataSource->child(i)));
32 }
32 }
33
33
34 return item;
34 return item;
35 }
35 }
36
36
37 } // namespace
37 } // namespace
38
38
39 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
39 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
40 {
40 {
41 ui->setupUi(this);
41 ui->setupUi(this);
42
42
43 // Set tree properties
43 // Set tree properties
44 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
44 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
45 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
46 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
47
47
48 // Connection to show a menu when right clicking on the tree
48 // Connection to show a menu when right clicking on the tree
49 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
50 &DataSourceWidget::onTreeMenuRequested);
50 &DataSourceWidget::onTreeMenuRequested);
51
51
52 // Connection to filter tree
52 // Connection to filter tree
53 connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
53 connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
54 ui->filterLineEdit->setText("tha_ion_s");
54 }
55 }
55
56
56 DataSourceWidget::~DataSourceWidget() noexcept
57 DataSourceWidget::~DataSourceWidget() noexcept
57 {
58 {
58 delete ui;
59 delete ui;
59 }
60 }
60
61
61 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
62 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
62 {
63 {
63 // Creates the item associated to the source and adds it to the tree widget. The tree widget
64 // Creates the item associated to the source and adds it to the tree widget. The tree widget
64 // takes the ownership of the item
65 // takes the ownership of the item
65 if (dataSource) {
66 if (dataSource) {
66 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
67 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
67 }
68 }
68 }
69 }
69
70
70 void DataSourceWidget::filterChanged(const QString &text) noexcept
71 void DataSourceWidget::filterChanged(const QString &text) noexcept
71 {
72 {
72 auto validateItem = [&text](const DataSourceTreeWidgetItem &item) {
73 auto validateItem = [&text](const DataSourceTreeWidgetItem &item) {
73 auto regExp = QRegExp{text, Qt::CaseInsensitive, QRegExp::Wildcard};
74 auto regExp = QRegExp{text, Qt::CaseInsensitive, QRegExp::Wildcard};
74
75
75 // An item is valid if any of its metadata validates the text filter
76 // An item is valid if any of its metadata validates the text filter
76 auto itemMetadata = item.data()->data();
77 auto itemMetadata = item.data()->data();
77 auto itemMetadataEnd = itemMetadata.cend();
78 auto itemMetadataEnd = itemMetadata.cend();
78 auto acceptFilter
79 auto acceptFilter
79 = [&regExp](const auto &variant) { return variant.toString().contains(regExp); };
80 = [&regExp](const auto &variant) { return variant.toString().contains(regExp); };
80
81
81 return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter)
82 return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter)
82 != itemMetadataEnd;
83 != itemMetadataEnd;
83 };
84 };
84
85
85 // Applies filter on tree widget
86 // Applies filter on tree widget
86 DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem);
87 DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem);
87 }
88 }
88
89
89 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
90 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
90 {
91 {
91 // Retrieves the selected item in the tree, and build the menu from its actions
92 // Retrieves the selected item in the tree, and build the menu from its actions
92 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
93 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
93 QMenu treeMenu{};
94 QMenu treeMenu{};
94 treeMenu.addActions(selectedItem->actions());
95 treeMenu.addActions(selectedItem->actions());
95
96
96 if (!treeMenu.isEmpty()) {
97 if (!treeMenu.isEmpty()) {
97 treeMenu.exec(QCursor::pos());
98 treeMenu.exec(QCursor::pos());
98 }
99 }
99 }
100 }
100 }
101 }
@@ -1,156 +1,156
1 #include "TimeWidget/TimeWidget.h"
1 #include "TimeWidget/TimeWidget.h"
2 #include "ui_TimeWidget.h"
2 #include "ui_TimeWidget.h"
3
3
4 #include <Common/DateUtils.h>
4 #include <Common/DateUtils.h>
5 #include <Common/MimeTypesDef.h>
5 #include <Common/MimeTypesDef.h>
6
6
7 #include <DragAndDrop/DragDropHelper.h>
7 #include <DragAndDrop/DragDropHelper.h>
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDrag>
11 #include <QDrag>
12 #include <QDragEnterEvent>
12 #include <QDragEnterEvent>
13 #include <QDropEvent>
13 #include <QDropEvent>
14 #include <QMimeData>
14 #include <QMimeData>
15
15
16
16
17 struct TimeWidget::TimeWidgetPrivate {
17 struct TimeWidget::TimeWidgetPrivate {
18
18
19 explicit TimeWidgetPrivate() {}
19 explicit TimeWidgetPrivate() {}
20
20
21 QPoint m_DragStartPosition;
21 QPoint m_DragStartPosition;
22 };
22 };
23
23
24 TimeWidget::TimeWidget(QWidget *parent)
24 TimeWidget::TimeWidget(QWidget *parent)
25 : QWidget{parent},
25 : QWidget{parent},
26 ui{new Ui::TimeWidget},
26 ui{new Ui::TimeWidget},
27 impl{spimpl::make_unique_impl<TimeWidgetPrivate>()}
27 impl{spimpl::make_unique_impl<TimeWidgetPrivate>()}
28 {
28 {
29 ui->setupUi(this);
29 ui->setupUi(this);
30
30
31 ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton));
31 ui->applyToolButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_DialogApplyButton));
32
32
33 // Connection
33 // Connection
34 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
34 connect(ui->startDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
35 &TimeWidget::onTimeUpdateRequested);
35 &TimeWidget::onTimeUpdateRequested);
36
36
37 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
37 connect(ui->endDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this,
38 &TimeWidget::onTimeUpdateRequested);
38 &TimeWidget::onTimeUpdateRequested);
39
39
40
40
41 connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(),
41 connect(ui->applyToolButton, &QToolButton::clicked, &sqpApp->timeController(),
42 &TimeController::onTimeNotify);
42 &TimeController::onTimeNotify);
43
43
44 // Initialisation
44 // Initialisation
45 auto endDateTime = QDateTime::currentDateTimeUtc();
45 auto endDateTime = QDateTime{QDate{2012, 12, 11}, QTime{0, 0}, Qt::UTC};
46 auto startDateTime = endDateTime.addSecs(-3600); // one hour before
46 auto startDateTime = QDateTime{QDate{2012, 12, 10}, QTime{0, 0}, Qt::UTC}; // one hour before
47
47
48 ui->startDateTimeEdit->setDateTime(startDateTime);
48 ui->startDateTimeEdit->setDateTime(startDateTime);
49 ui->endDateTimeEdit->setDateTime(endDateTime);
49 ui->endDateTimeEdit->setDateTime(endDateTime);
50
50
51 auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime),
51 auto dateTime = SqpRange{DateUtils::secondsSinceEpoch(startDateTime),
52 DateUtils::secondsSinceEpoch(endDateTime)};
52 DateUtils::secondsSinceEpoch(endDateTime)};
53
53
54 sqpApp->timeController().onTimeToUpdate(dateTime);
54 sqpApp->timeController().onTimeToUpdate(dateTime);
55 }
55 }
56
56
57
57
58 TimeWidget::~TimeWidget()
58 TimeWidget::~TimeWidget()
59 {
59 {
60 delete ui;
60 delete ui;
61 }
61 }
62
62
63 void TimeWidget::setTimeRange(SqpRange time)
63 void TimeWidget::setTimeRange(SqpRange time)
64 {
64 {
65 auto startDateTime = DateUtils::dateTime(time.m_TStart);
65 auto startDateTime = DateUtils::dateTime(time.m_TStart);
66 auto endDateTime = DateUtils::dateTime(time.m_TEnd);
66 auto endDateTime = DateUtils::dateTime(time.m_TEnd);
67
67
68 ui->startDateTimeEdit->setDateTime(startDateTime);
68 ui->startDateTimeEdit->setDateTime(startDateTime);
69 ui->endDateTimeEdit->setDateTime(endDateTime);
69 ui->endDateTimeEdit->setDateTime(endDateTime);
70 }
70 }
71
71
72 SqpRange TimeWidget::timeRange() const
72 SqpRange TimeWidget::timeRange() const
73 {
73 {
74 return SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
74 return SqpRange{DateUtils::secondsSinceEpoch(ui->startDateTimeEdit->dateTime()),
75 DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())};
75 DateUtils::secondsSinceEpoch(ui->endDateTimeEdit->dateTime())};
76 }
76 }
77
77
78 void TimeWidget::onTimeUpdateRequested()
78 void TimeWidget::onTimeUpdateRequested()
79 {
79 {
80 auto dateTime = timeRange();
80 auto dateTime = timeRange();
81 emit timeUpdated(std::move(dateTime));
81 emit timeUpdated(std::move(dateTime));
82 }
82 }
83
83
84 void TimeWidget::dragEnterEvent(QDragEnterEvent *event)
84 void TimeWidget::dragEnterEvent(QDragEnterEvent *event)
85 {
85 {
86 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
86 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
87 event->acceptProposedAction();
87 event->acceptProposedAction();
88 setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
88 setStyleSheet("QDateTimeEdit{background-color: #BBD5EE; border:2px solid #2A7FD4}");
89 }
89 }
90 else {
90 else {
91 event->ignore();
91 event->ignore();
92 }
92 }
93 }
93 }
94
94
95 void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event)
95 void TimeWidget::dragLeaveEvent(QDragLeaveEvent *event)
96 {
96 {
97 setStyleSheet(QString());
97 setStyleSheet(QString());
98 }
98 }
99
99
100 void TimeWidget::dropEvent(QDropEvent *event)
100 void TimeWidget::dropEvent(QDropEvent *event)
101 {
101 {
102 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
102 if (event->mimeData()->hasFormat(MIME_TYPE_TIME_RANGE)) {
103 auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
103 auto mimeData = event->mimeData()->data(MIME_TYPE_TIME_RANGE);
104 auto timeRange = TimeController::timeRangeForMimeData(mimeData);
104 auto timeRange = TimeController::timeRangeForMimeData(mimeData);
105
105
106 setTimeRange(timeRange);
106 setTimeRange(timeRange);
107 }
107 }
108 else {
108 else {
109 event->ignore();
109 event->ignore();
110 }
110 }
111
111
112 setStyleSheet(QString());
112 setStyleSheet(QString());
113 }
113 }
114
114
115
115
116 void TimeWidget::mousePressEvent(QMouseEvent *event)
116 void TimeWidget::mousePressEvent(QMouseEvent *event)
117 {
117 {
118 if (event->button() == Qt::LeftButton) {
118 if (event->button() == Qt::LeftButton) {
119 impl->m_DragStartPosition = event->pos();
119 impl->m_DragStartPosition = event->pos();
120 }
120 }
121
121
122 QWidget::mousePressEvent(event);
122 QWidget::mousePressEvent(event);
123 }
123 }
124
124
125 void TimeWidget::mouseMoveEvent(QMouseEvent *event)
125 void TimeWidget::mouseMoveEvent(QMouseEvent *event)
126 {
126 {
127 if (!(event->buttons() & Qt::LeftButton)) {
127 if (!(event->buttons() & Qt::LeftButton)) {
128 return;
128 return;
129 }
129 }
130
130
131 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
131 if ((event->pos() - impl->m_DragStartPosition).manhattanLength()
132 < QApplication::startDragDistance()) {
132 < QApplication::startDragDistance()) {
133 return;
133 return;
134 }
134 }
135
135
136 // Note: The management of the drag object is done by Qt
136 // Note: The management of the drag object is done by Qt
137 auto drag = new QDrag{this};
137 auto drag = new QDrag{this};
138
138
139 auto mimeData = new QMimeData;
139 auto mimeData = new QMimeData;
140 auto timeData = TimeController::mimeDataForTimeRange(timeRange());
140 auto timeData = TimeController::mimeDataForTimeRange(timeRange());
141 mimeData->setData(MIME_TYPE_TIME_RANGE, timeData);
141 mimeData->setData(MIME_TYPE_TIME_RANGE, timeData);
142
142
143 drag->setMimeData(mimeData);
143 drag->setMimeData(mimeData);
144
144
145 auto pixmap = QPixmap(size());
145 auto pixmap = QPixmap(size());
146 render(&pixmap);
146 render(&pixmap);
147 drag->setPixmap(pixmap);
147 drag->setPixmap(pixmap);
148 drag->setHotSpot(impl->m_DragStartPosition);
148 drag->setHotSpot(impl->m_DragStartPosition);
149
149
150 sqpApp->dragDropHelper().resetDragAndDrop();
150 sqpApp->dragDropHelper().resetDragAndDrop();
151
151
152 // Note: The exec() is blocking on windows but not on linux and macOS
152 // Note: The exec() is blocking on windows but not on linux and macOS
153 drag->exec(Qt::MoveAction | Qt::CopyAction);
153 drag->exec(Qt::MoveAction | Qt::CopyAction);
154
154
155 QWidget::mouseMoveEvent(event);
155 QWidget::mouseMoveEvent(event);
156 }
156 }
General Comments 0
You need to be logged in to leave comments. Login now