Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/*
CMakeLists.txt.user
.vscode/
82 changes: 65 additions & 17 deletions src/table_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
#include "graph_page.h"
#include "qos_dictionary.h"

#include <QInputDialog>
#include <QMessageBox>
#include <QDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QLabel>
#include <QPushButton>

#include <iostream>
#include <exception>
Expand Down Expand Up @@ -88,7 +95,7 @@ void TablePage::on_filterButton_clicked()
const std::string topicName = m_topicName.toStdString();
QItemSelectionModel* selectionModel = topicTableView->selectionModel();
QModelIndexList indexList = selectionModel->selectedIndexes();
QString initialText = "";
QString initialText = m_topicMonitor->getFilter();

// Create a default filter based on the table selection
for (int i = 0; i < indexList.size(); ++i)
Expand Down Expand Up @@ -143,28 +150,69 @@ void TablePage::on_filterButton_clicked()

}

bool ok = false;
QString usageString;
usageString += "Install a topic filter using SQL syntax.\n";
usageString += "A blank string will remove any existing filter.\n";
usageString += "Example usage: color = 'BLUE' AND id = 1\n";
QDialog filterDialog(this);
filterDialog.setWindowTitle("Topic Filter");
filterDialog.setModal(true);
filterDialog.resize(500, 300);

// Prompt the user for the topic filter string
QString filter = QInputDialog::getText(
this,
"Topic Filter",
usageString,
QLineEdit::Normal,
initialText,
&ok);
QVBoxLayout *layout = new QVBoxLayout(&filterDialog);

QLabel *instructionLabel = new QLabel(&filterDialog);
instructionLabel->setText("Install a topic filter using SQL syntax.\n"
"A blank string will remove any existing filter.\n"
"Example usage: color = 'BLUE' AND id = 1");
instructionLabel->setWordWrap(true);
layout->addWidget(instructionLabel);

// Text edit for filter input
QTextEdit *filterTextEdit = new QTextEdit(&filterDialog);
filterTextEdit->setPlainText(initialText);
layout->addWidget(filterTextEdit);

// Button layout
QHBoxLayout *buttonLayout = new QHBoxLayout();

QPushButton *clearButton = new QPushButton("Clear", &filterDialog);
QPushButton *okButton = new QPushButton("OK", &filterDialog);
QPushButton *cancelButton = new QPushButton("Cancel", &filterDialog);

buttonLayout->addWidget(clearButton);
buttonLayout->addStretch();
buttonLayout->addWidget(okButton);
buttonLayout->addWidget(cancelButton);

layout->addLayout(buttonLayout);

bool clearClicked = false;

// Only abort if the user didn't click 'ok'.
// An empty string will remove the filter.
if (!ok)
connect(clearButton, &QPushButton::clicked, [&filterDialog, &clearClicked, this]() {
clearClicked = true;
m_refreshTimer.stop();
CommonData::flushSamples(m_topicName);
m_topicMonitor->setFilter("");
m_refreshTimer.start(REFRESH_TIMEOUT);

freezeButton->show();
unfreezeButton->hide();

filterDialog.accept();
});

connect(okButton, &QPushButton::clicked, &filterDialog, &QDialog::accept);
connect(cancelButton, &QPushButton::clicked, &filterDialog, &QDialog::reject);

if (filterDialog.exec() != QDialog::Accepted)
{
return;
}

if (clearClicked)
{
return;
}

QString filter = filterTextEdit->toPlainText();

// Make sure we have an information object for this topic
std::shared_ptr<TopicInfo> topicInfo = CommonData::getTopicInfo(m_topicName);
if (!topicInfo)
Expand Down
Loading