Commit f204eced authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

reimplementing filter

parent df46fff3
...@@ -14,8 +14,8 @@ AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent) ...@@ -14,8 +14,8 @@ AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent)
db = QSqlDatabase::addDatabase("QMYSQL"); db = QSqlDatabase::addDatabase("QMYSQL");
QStringList args = qApp->arguments(); QStringList args = qApp->arguments();
QString dbHost = "fcslog-replica-01"; QString dbHost = "fcslog-replica-01";
if(args.contains("--log-database-host") && args.size() > args.indexOf("--log-database-host")) { if(args.contains("--dbh") && args.size() > args.indexOf("--dbh")) {
dbHost = args.at(args.indexOf("--log-database-host") + 1); dbHost = args.at(args.indexOf("--dbh") + 1);
} }
db.setHostName(dbHost); db.setHostName(dbHost);
db.setDatabaseName("hdbpp"); db.setDatabaseName("hdbpp");
......
...@@ -151,6 +151,8 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent) ...@@ -151,6 +151,8 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(ui->leFilterName, SIGNAL(textChanged(QString)), this, SLOT(onFilterNameChanged(QString))); connect(ui->leFilterName, SIGNAL(textChanged(QString)), this, SLOT(onFilterNameChanged(QString)));
connect(ui->comboStatus, SIGNAL(currentTextChanged(QString)), this, SLOT(onFilterStatusChanged(QString))); connect(ui->comboStatus, SIGNAL(currentTextChanged(QString)), this, SLOT(onFilterStatusChanged(QString)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), this, SLOT(onFilterStatusEnabled(bool))); connect(ui->cBStatus, SIGNAL(toggled(bool)), this, SLOT(onFilterStatusEnabled(bool)));
m_filter = new AlarmFilter(ui->twHistory);
} }
Alarm::~Alarm() { Alarm::~Alarm() {
...@@ -269,6 +271,7 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) { ...@@ -269,6 +271,7 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
} }
void Alarm::onFilterNameChanged(const QString &n) { void Alarm::onFilterNameChanged(const QString &n) {
m_filter->addFilter("Alarm", n);
AlarmFilter f; AlarmFilter f;
f.filter(ui->twHistory, "Alarm", n); f.filter(ui->twHistory, "Alarm", n);
} }
......
...@@ -92,6 +92,7 @@ private: ...@@ -92,6 +92,7 @@ private:
Ui::Alarm *ui; Ui::Alarm *ui;
Sound *sound; Sound *sound;
bool filtering; bool filtering;
AlarmFilter *m_filter;
// cumbia // cumbia
CumbiaPool *cu_pool; CumbiaPool *cu_pool;
......
...@@ -13,24 +13,46 @@ class QAbstractItemModel; ...@@ -13,24 +13,46 @@ class QAbstractItemModel;
class AlarmFilter class AlarmFilter
{ {
public: public:
AlarmFilter() { ack_enable = ack = lev = stat = grp = false; } AlarmFilter(QTreeView *m) { m_view = m; ack_enable = ack = lev = stat = grp = false; }
bool ack_enable, ack, lev, stat, grp; bool ack_enable, ack, lev, stat, grp;
QString level, status; QString level, status;
QStringList groups; QStringList groups;
void filter(QTreeView *m, const QString &column, const QString& f); void addFilter(const QString& column, const QString& f) {
int c;
for(c = 0; c < m_view->model()->columnCount(); c++)
if(m_view->model()->headerData(c, Qt::Horizontal).toString() == column)
break;
fmap[c] = f;
}
void removeFilter(const QString& column) {
int c;
for(c = 0; c < m_view->model()->columnCount(); c++)
if(m_view->model()->headerData(c, Qt::Horizontal).toString() == column)
break;
fmap.remove(c);
}
void filter();
QMap<int, QString > fmap;
QTreeView *m_view;
}; };
inline void AlarmFilter::filter(QTreeView *v, const QString& column, const QString& f)
inline void AlarmFilter::filter()
{ {
QAbstractItemModel *m = v->model(); QAbstractItemModel *m = m_view->model();
int c; bool hide;
for(c = 0; c < m->columnCount(); c++)
if(m->headerData(c, Qt::Horizontal).toString() == column)
break;
for(int i = 0; i < m->rowCount(); i++) { for(int i = 0; i < m->rowCount(); i++) {
v->setRowHidden(i, QModelIndex(), !f.isEmpty() && !m->data(m->index(i, c), Qt::DisplayRole).toString().contains(f)); hide = false;
foreach(int c, fmap.keys()) {
const QString& f = fmap[c];
hide |= !f.isEmpty() && !m->data(m->index(i, c), Qt::DisplayRole).toString().contains(f);
}
m_view->setRowHidden(i, QModelIndex(), hide);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment