2 #include "ui_curvelist_panel.h" 10 #include <QHeaderView> 11 #include <QFontDatabase> 12 #include <QMessageBox> 13 #include <QApplication> 16 #include <QStandardItem> 17 #include <QWheelEvent> 18 #include <QItemSelectionModel> 28 return doj::alphanum_impl(this->
str.c_str(),
29 other.
str.c_str()) < 0;
43 _custom_plots(mapped_math_plots),
47 ui->tableView->viewport()->installEventFilter(
this );
49 _model =
new QStandardItemModel(0, 2,
this);
51 for(
auto table_view: {
ui->tableView,
ui->tableViewCustom})
53 table_view->viewport()->installEventFilter(
this );
54 table_view->setModel(
_model );
55 table_view->horizontalHeader()->setStretchLastSection (
true);
56 table_view->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
59 ui->widgetOptions->setVisible(
false);
61 ui->radioRegExp->setAutoExclusive(
true);
62 ui->radioContains->setAutoExclusive(
true);
63 ui->radioPrefix->setAutoExclusive(
true);
65 _completer->setCompletionMode( QCompleter::PopupCompletion );
69 QString active_filter = settings.value(
"FilterableListWidget.searchFilter").toString();
70 if( active_filter ==
"radioRegExp"){
72 ui->radioRegExp->setChecked(
true);
74 else if( active_filter ==
"radioPrefix"){
76 ui->radioPrefix->setChecked(
true);
78 else if( active_filter ==
"radioContains"){
80 ui->radioContains->setChecked(
true);
83 _point_size = settings.value(
"FilterableListWidget/table_point_size", 9).toInt();
88 ui->splitter->setStretchFactor(0,5);
89 ui->splitter->setStretchFactor(1,1);
91 connect(
ui->tableViewCustom->selectionModel(), &QItemSelectionModel::selectionChanged,
102 return _model->rowCount();
109 ui->labelNumberDisplayed->setText(
"0 of 0");
114 if(
_model->findItems(item_name).size() > 0)
120 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
124 _model->setRowCount(row+1);
125 _model->setItem(row, 0, item);
127 auto val_cell =
new QStandardItem(
"-");
128 val_cell->setTextAlignment(Qt::AlignRight);
129 val_cell->setFlags( Qt::NoItemFlags | Qt::ItemIsEnabled );
130 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
132 val_cell->setFont( font );
133 val_cell->setFlags(Qt::NoItemFlags);
135 _model->setItem(row, 1, val_cell );
145 ui->tableView->sortByColumn(0,Qt::AscendingOrder);
146 ui->tableViewCustom->sortByColumn(0,Qt::AscendingOrder);
148 ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
149 ui->tableViewCustom->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
157 auto item_list =
_model->findItems( QString::fromStdString( text ), Qt::MatchExactly);
158 if( item_list.isEmpty())
162 if( item_list.count()>1)
164 qDebug() <<
"FilterableListWidget constins multiple rows with the same name";
167 return item_list.front()->row();
178 if( event->key() == Qt::Key_Delete){
186 while ( obj && obj !=
ui->tableView && obj !=
ui->tableViewCustom )
194 return QWidget::eventFilter(
object,event);
197 bool shift_modifier_pressed = (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier);
198 bool ctrl_modifier_pressed = (QGuiApplication::keyboardModifiers() == Qt::ControlModifier);
200 if(event->type() == QEvent::MouseButtonPress)
202 QMouseEvent *mouse_event =
static_cast<QMouseEvent*
>(event);
207 if( !shift_modifier_pressed && !ctrl_modifier_pressed )
209 if( obj ==
ui->tableView)
211 ui->tableViewCustom->clearSelection() ;
213 if( obj ==
ui->tableViewCustom)
215 ui->tableView->clearSelection() ;
219 if(mouse_event->button() == Qt::LeftButton )
223 else if(mouse_event->button() == Qt::RightButton )
230 return QWidget::eventFilter(
object,event);
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 ||
238 mouse_event->buttons() == Qt::RightButton) &&
239 distance_from_click >= QApplication::startDragDistance() &&
243 QDrag *drag =
new QDrag(
this);
244 QMimeData *mimeData =
new QMimeData;
247 QDataStream stream(&mdata, QIODevice::WriteOnly);
251 stream << QString::fromStdString(curve_name);
256 mimeData->setData(
"curveslist/add_curve", mdata);
264 mimeData->setData(
"curveslist/new_X_axis", mdata);
266 QPixmap cursor( QSize(160,30) );
267 cursor.fill(Qt::transparent);
270 painter.begin( &cursor);
271 painter.setPen(QColor(22, 22, 22));
273 QString text(
"set as new X axis");
274 painter.setFont( QFont(
"Arial", 14 ) );
276 painter.setBackground(Qt::transparent);
277 painter.drawText( QRect(0, 0, 160, 30), Qt::AlignHCenter | Qt::AlignVCenter, text );
280 drag->setDragCursor(cursor, Qt::MoveAction);
283 drag->setMimeData(mimeData);
284 drag->exec(Qt::CopyAction | Qt::MoveAction);
288 else if(event->type() == QEvent::Wheel)
290 QWheelEvent *wheel_event =
dynamic_cast<QWheelEvent*
>(event);
292 if( ctrl_modifier_pressed )
298 else if( _point_size < 14 && wheel_event->delta() > 0 )
304 auto horizontal =
ui->tableView->horizontalHeader();
305 horizontal->setSectionResizeMode(0, QHeaderView::Fixed);
306 horizontal->setSectionResizeMode(1, QHeaderView::Fixed);
308 auto vertical =
ui->tableView->verticalHeader();
309 vertical->setSectionResizeMode(0, QHeaderView::Fixed);
310 vertical->setSectionResizeMode(1, QHeaderView::Fixed);
312 for (
int row=0; row<
rowCount(); row++)
314 for (
int col=0; col< 2; col++)
316 auto item =
_model->item( row, col );
317 auto font = item->font();
319 item->setFont( font );
323 horizontal->setSectionResizeMode(0, QHeaderView::ResizeToContents);
324 horizontal->setSectionResizeMode(1, QHeaderView::Stretch);
325 vertical->setSectionResizeMode(0, QHeaderView::ResizeToContents);
326 vertical->setSectionResizeMode(1, QHeaderView::ResizeToContents);
329 settings.setValue(
"FilterableListWidget/table_point_size",
_point_size);
335 return QWidget::eventFilter(
object,event);
340 std::vector<std::string> non_hidden_list;
342 for(
auto table_view: {
ui->tableView,
ui->tableViewCustom})
344 for (
const auto &selected_index : table_view->selectionModel()->selectedRows(0))
346 if (!table_view->isRowHidden(selected_index.row()))
348 auto item =
_model->item( selected_index.row(), 0 );
349 non_hidden_list.push_back(item->text().toStdString());
353 return non_hidden_list;
358 return ui->tableView;
363 return ui->tableViewCustom;
370 ui->lineEdit->setCompleter(
nullptr );
372 settings.setValue(
"FilterableListWidget.searchFilter",
"radioContains");
380 ui->lineEdit->setCompleter(
nullptr );
382 settings.setValue(
"FilterableListWidget.searchFilter",
"radioRegExp");
393 for (
int row=0; row<
rowCount(); row++)
395 auto item =
_model->item(row,0);
402 settings.setValue(
"FilterableListWidget.searchFilter",
"radioPrefix");
414 int visible_count = 0;
415 bool updated =
false;
417 Qt::CaseSensitivity cs = Qt::CaseInsensitive;
418 if(
ui->checkBoxCaseSensitive->isChecked())
420 cs = Qt::CaseSensitive;
422 QRegExp regexp( search_string, cs, QRegExp::Wildcard );
423 QRegExpValidator
v(regexp,
nullptr);
425 QStringList spaced_items = search_string.split(
' ');
427 for (
int row=0; row <
rowCount(); row++)
429 auto item =
_model->item(row,0);
430 QString
name = item->text();
434 if( search_string.isEmpty() == false )
436 if(
ui->radioRegExp->isChecked())
438 toHide = v.validate( name, pos ) != QValidator::Acceptable;
440 else if(
ui->radioPrefix->isChecked())
442 toHide = !name.startsWith( search_string, cs ) ;
444 else if(
ui->radioContains->isChecked())
446 for (
const auto& item: spaced_items)
448 if( name.contains(item, cs) == false )
456 if( !toHide ) visible_count++;
458 if( toHide !=
ui->tableView->isRowHidden(row) ) updated =
true;
460 const auto name_std = name.toStdString();
461 const bool is_custom_plot =
_custom_plots.count(name_std) > 0;
464 ui->tableView->setRowHidden(row, toHide || is_custom_plot );
465 ui->tableViewCustom->setRowHidden(row, toHide || !is_custom_plot );
467 ui->labelNumberDisplayed->setText( QString::number( visible_count ) + QString(
" of ") +
468 QString::number( item_count ) );
477 ui->widgetOptions->setVisible(checked);
482 for(
auto table_view: {
ui->tableView,
ui->tableViewCustom})
485 table_view->hideColumn(1);
488 table_view->showColumn(1);
496 QMessageBox::StandardButton reply;
497 reply = QMessageBox::question(
nullptr, tr(
"Warning"),
498 tr(
"Do you really want to remove these data?\n"),
499 QMessageBox::Yes | QMessageBox::No,
502 if (reply == QMessageBox::Yes)
511 for (
int row=0; row<
rowCount(); row++)
513 auto item =
_model->item(row);
529 if( curve_names.empty() )
550 int selected_items = 0;
552 for (
const auto &index :
ui->tableViewCustom->selectionModel()->selectedRows(0))
554 if (!
ui->tableViewCustom->isRowHidden(index.row()) )
560 bool enabled = selected_items == 1;
561 ui->buttonEditCustom->setEnabled( enabled );
562 ui->buttonEditCustom->setToolTip( enabled ?
"Edit the selected custom timeserie" :
563 "Select a single custom Timeserie to Edit it");
568 int selected_count = 0;
569 QModelIndex selected_index;
570 auto table_view =
ui->tableViewCustom;
572 for (QModelIndex index : table_view->selectionModel()->selectedRows(0))
574 if (!table_view->isRowHidden( index.row()) )
577 selected_index = index;
580 if( selected_count != 1)
585 auto item =
_model->item( selected_index.row(), 0 );
591 ui->tableViewCustom->clearSelection();
592 ui->tableView->clearSelection();
void addItem(const QString &item_name)
int findRowByName(const std::string &text) const
void on_radioRegExp_toggled(bool checked)
void onCustomSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
void editMathPlot(const std::string &plot_name)
void on_radioContains_toggled(bool checked)
void addToCompletionTree(const QString &name)
TreeModelCompleter * _completer
bool eventFilter(QObject *object, QEvent *event) override
std::vector< std::string > getNonHiddenSelectedRows()
QTableView * getTableView() const
void createMathPlot(const std::string &linked_plot)
SortedTableItem(const QString &name)
void deleteCurves(const std::vector< std::string > &curve_names)
virtual void keyPressEvent(QKeyEvent *event) override
CurveListPanel(const CustomPlotMap &mapped_math_plots, QWidget *parent)
std::unordered_map< std::string, CustomPlotPtr > CustomPlotMap
~CurveListPanel() override
bool _completer_need_update
void on_pushButtonSettings_toggled(bool checked)
void on_radioPrefix_toggled(bool checked)
void on_buttonEditCustom_clicked()
const CustomPlotMap & _custom_plots
void removeSelectedCurves()
void hiddenItemsChanged()
QStandardItemModel * _model
QTableView * getCustomView() const
void on_checkBoxHideSecondColumn_toggled(bool checked)
void on_lineEdit_textChanged(const QString &search_string)
bool operator<(const SortedTableItem &other) const
void on_checkBoxCaseSensitive_toggled(bool checked)
void on_buttonAddCustom_clicked()