8 #include <QApplication>
10 #include <QMessageBox>
20 setEditTriggers(NoEditTriggers);
21 setDragEnabled(
false);
22 setDefaultDropAction(Qt::IgnoreAction);
23 setDragDropOverwriteMode(
false);
24 setDragDropMode(NoDragDrop);
25 viewport()->installEventFilter(
this);
27 setSelectionBehavior(QAbstractItemView::SelectRows);
28 setSelectionMode(ExtendedSelection);
29 setFocusPolicy(Qt::ClickFocus);
31 verticalHeader()->setVisible(
false);
32 horizontalHeader()->setVisible(
false);
34 horizontalHeader()->setStretchLastSection(
true);
36 setColumnWidth(1, 100);
38 setHorizontalHeaderItem(0,
new QTableWidgetItem(
"Time series"));
39 setHorizontalHeaderItem(1,
new QTableWidgetItem(
"Current value"));
41 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
46 const QString& plot_ID)
53 QString row_name = prefix;
54 if (!prefix.isEmpty() && !prefix.endsWith(
'/'))
58 row_name += plot_name;
61 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
64 item->setData(Qt::UserRole, plot_ID);
65 const int row = rowCount();
66 QTableWidget::setRowCount(row + 1);
67 QTableWidget::setItem(row, 0, item);
69 auto val_cell =
new QTableWidgetItem(
"-");
70 val_cell->setTextAlignment(Qt::AlignRight);
71 val_cell->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
72 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
74 val_cell->setFont(font);
76 QTableWidget::setItem(row, 1, val_cell);
83 sortByColumn(0, Qt::AscendingOrder);
89 std::vector<std::string> non_hidden_list;
91 for (
const QTableWidgetItem* cell : selectedItems())
93 non_hidden_list.push_back(cell->text().toStdString());
95 return non_hidden_list;
106 for (
int row = 0; row < rowCount(); row++)
108 auto cell = item(row, 0);
109 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
114 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
123 for (
int row = 0; row < model()->rowCount(); row++)
125 if (item(row, 0)->text() == name)
138 bool updated =
false;
141 QStringList spaced_items = search_string.split(
' ');
143 for (
int row = 0; row < model()->rowCount(); row++)
145 auto cell = item(row, 0);
146 QString name = cell->text();
149 if (search_string.isEmpty() ==
false)
151 for (
const auto& item : spaced_items)
153 if (name.contains(item, Qt::CaseInsensitive) ==
false)
165 if (toHide != isRowHidden(row))
170 setRowHidden(row, toHide);
179 verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
182 horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
183 horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
187 horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
188 horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
211 QAbstractItemView* table_widget = qobject_cast<QAbstractItemView*>(
object);
213 if (qobject_cast<QScrollBar*>(
object))
219 while (obj && !table_widget)
222 table_widget = qobject_cast<QAbstractItemView*>(obj);
225 bool ctrl_modifier_pressed =
226 (QGuiApplication::keyboardModifiers() == Qt::ControlModifier);
228 if (event->type() == QEvent::MouseButtonPress)
230 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
235 if (mouse_event->button() == Qt::LeftButton)
239 else if (mouse_event->button() == Qt::RightButton)
249 else if (event->type() == QEvent::MouseMove)
251 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
252 double distance_from_click = (mouse_event->pos() -
_drag_start_pos).manhattanLength();
254 if ((mouse_event->buttons() == Qt::LeftButton ||
255 mouse_event->buttons() == Qt::RightButton) &&
256 distance_from_click >= QApplication::startDragDistance() && !
_dragging)
259 QDrag* drag =
new QDrag(table_widget);
260 QMimeData* mimeData =
new QMimeData;
263 QDataStream stream(&mdata, QIODevice::WriteOnly);
267 std::sort(selected_names.begin(), selected_names.end());
269 for (
const auto& curve_name : selected_names)
271 stream << QString::fromStdString(curve_name);
276 mimeData->setData(
"curveslist/add_curve", mdata);
280 if (selected_names.size() != 2)
282 if (selected_names.size() >= 1)
284 QMessageBox::warning(table_widget,
"New in version 2.3+",
285 "To create a new XY curve, you must select two "
287 "drag&drop them using the RIGHT mouse button.",
292 mimeData->setData(
"curveslist/new_XY_axis", mdata);
294 QPixmap cursor(QSize(80, 30));
295 cursor.fill(Qt::transparent);
298 painter.begin(&cursor);
301 painter.setFont(QFont(
"Arial", 14));
303 painter.setBackground(Qt::transparent);
304 painter.setPen(table_widget->palette().foreground().color());
305 painter.drawText(QRect(0, 0, 80, 30), Qt::AlignCenter, text);
308 drag->setDragCursor(cursor, Qt::MoveAction);
311 drag->setMimeData(mimeData);
312 drag->exec(Qt::CopyAction | Qt::MoveAction);
316 else if (event->type() == QEvent::Wheel)
318 QWheelEvent* wheel_event =
dynamic_cast<QWheelEvent*
>(event);
320 if (ctrl_modifier_pressed)
323 if (wheel_event->delta() < 0)
327 else if (wheel_event->delta() > 0)