2 #include <QApplication> 13 setEditTriggers(NoEditTriggers);
14 setDragEnabled(
false);
15 setDefaultDropAction(Qt::IgnoreAction);
16 setDragDropOverwriteMode(
false);
17 setDragDropMode(NoDragDrop);
18 viewport()->installEventFilter(
this);
20 setSelectionBehavior(QAbstractItemView::SelectRows);
21 setSelectionMode(ExtendedSelection);
22 setFocusPolicy(Qt::ClickFocus);
24 verticalHeader()->setVisible(
false);
25 horizontalHeader()->setVisible(
false);
27 horizontalHeader()->setStretchLastSection(
true);
29 setColumnWidth(1, 100);
31 setHorizontalHeaderItem(0,
new QTableWidgetItem(
"Time series"));
32 setHorizontalHeaderItem(1,
new QTableWidgetItem(
"Current value"));
34 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
46 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
49 const int row = rowCount();
50 QTableWidget::setRowCount(row + 1);
51 QTableWidget::setItem(row, 0, item);
53 auto val_cell =
new QTableWidgetItem(
"-");
54 val_cell->setTextAlignment(Qt::AlignRight);
55 val_cell->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
56 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
58 val_cell->setFont(font);
60 QTableWidget::setItem(row, 1, val_cell);
67 sortByColumn(0, Qt::AscendingOrder);
73 std::vector<std::string> non_hidden_list;
75 for (
const QTableWidgetItem* cell : selectedItems())
77 non_hidden_list.push_back(cell->text().toStdString());
79 return non_hidden_list;
90 for (
int row = 0; row < rowCount(); row++)
92 auto cell = item(row, 0);
93 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
98 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
107 for (
int row = 0; row < model()->rowCount(); row++)
109 if (item(row, 0)->text() ==
name)
122 bool updated =
false;
125 QStringList spaced_items = search_string.split(
' ');
127 for (
int row = 0; row < model()->rowCount(); row++)
129 auto cell = item(row, 0);
130 QString
name = cell->text();
133 if (search_string.isEmpty() ==
false)
135 for (
const auto& item : spaced_items)
137 if (name.contains(item, Qt::CaseInsensitive) ==
false)
149 if (toHide != isRowHidden(row))
154 setRowHidden(row, toHide);
163 verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
166 horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
167 horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
171 horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
172 horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
195 QAbstractItemView* table_widget = qobject_cast<QAbstractItemView*>(
object);
197 if (qobject_cast<QScrollBar*>(
object))
203 while (obj && !table_widget)
206 table_widget = qobject_cast<QAbstractItemView*>(obj);
209 bool ctrl_modifier_pressed = (QGuiApplication::keyboardModifiers() == Qt::ControlModifier);
211 if (event->type() == QEvent::MouseButtonPress)
213 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
218 if (mouse_event->button() == Qt::LeftButton)
222 else if (mouse_event->button() == Qt::RightButton)
232 else if (event->type() == QEvent::MouseMove)
234 QMouseEvent* mouse_event =
static_cast<QMouseEvent*
>(event);
235 double distance_from_click = (mouse_event->pos() -
_drag_start_pos).manhattanLength();
237 if ((mouse_event->buttons() == Qt::LeftButton || mouse_event->buttons() == Qt::RightButton) &&
238 distance_from_click >= QApplication::startDragDistance() && !
_dragging)
241 QDrag* drag =
new QDrag(table_widget);
242 QMimeData* mimeData =
new QMimeData;
245 QDataStream stream(&mdata, QIODevice::WriteOnly);
248 std::sort(selected_names.begin(), selected_names.end());
250 for (
const auto& curve_name : selected_names)
252 stream << QString::fromStdString(curve_name);
257 mimeData->setData(
"curveslist/add_curve", mdata);
261 if (selected_names.size() != 2)
263 if (selected_names.size() >= 1)
265 QMessageBox::warning(table_widget,
"New in version 2.3+",
266 "To create a new XY curve, you must select two " 268 "drag&drop them using the RIGHT mouse button.",
273 mimeData->setData(
"curveslist/new_XY_axis", mdata);
275 QPixmap cursor(QSize(80, 30));
276 cursor.fill(Qt::transparent);
279 painter.begin(&cursor);
282 painter.setFont(QFont(
"Arial", 14));
284 painter.setBackground(Qt::transparent);
285 painter.setPen(table_widget->palette().foreground().color());
286 painter.drawText(QRect(0, 0, 80, 30), Qt::AlignCenter, text);
289 drag->setDragCursor(cursor, Qt::MoveAction);
292 drag->setMimeData(mimeData);
293 drag->exec(Qt::CopyAction | Qt::MoveAction);
297 else if (event->type() == QEvent::Wheel)
299 QWheelEvent* wheel_event =
dynamic_cast<QWheelEvent*
>(event);
301 if (ctrl_modifier_pressed)
304 if (wheel_event->delta() < 0)
308 else if (wheel_event->delta() > 0)
void addItem(const QString &item_name) override
basic_object< reference > object
virtual std::vector< std::string > getSelectedNames()=0
void changeFontSize(int point_size)
CurvesView(CurveListPanel *parent)
virtual void hideValuesColumn(bool hide) override
QSet< QString > _inserted_curves
std::vector< std::string > getSelectedNames() override
CurveListPanel * _parent_panel
void setViewResizeEnabled(bool enable) override
static int sort(lua_State *L)
CurveTableView(CurveListPanel *parent)
void refreshFontSize() override
void refreshColumns() override
bool applyVisibilityFilter(const QString &filter_string) override
bool eventFilterBase(QObject *object, QEvent *event)
void removeCurve(const QString &name) override