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)
db = QSqlDatabase::addDatabase("QMYSQL");
QStringList args = qApp->arguments();
QString dbHost = "fcslog-replica-01";
if(args.contains("--log-database-host") && args.size() > args.indexOf("--log-database-host")) {
dbHost = args.at(args.indexOf("--log-database-host") + 1);
if(args.contains("--dbh") && args.size() > args.indexOf("--dbh")) {
dbHost = args.at(args.indexOf("--dbh") + 1);
}
db.setHostName(dbHost);
db.setDatabaseName("hdbpp");
......
......@@ -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->comboStatus, SIGNAL(currentTextChanged(QString)), this, SLOT(onFilterStatusChanged(QString)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), this, SLOT(onFilterStatusEnabled(bool)));
m_filter = new AlarmFilter(ui->twHistory);
}
Alarm::~Alarm() {
......@@ -269,6 +271,7 @@ void Alarm::onItemDoubleClicked(const QModelIndex &mi) {
}
void Alarm::onFilterNameChanged(const QString &n) {
m_filter->addFilter("Alarm", n);
AlarmFilter f;
f.filter(ui->twHistory, "Alarm", n);
}
......
......@@ -92,6 +92,7 @@ private:
Ui::Alarm *ui;
Sound *sound;
bool filtering;
AlarmFilter *m_filter;
// cumbia
CumbiaPool *cu_pool;
......
......@@ -13,24 +13,46 @@ class QAbstractItemModel;
class AlarmFilter
{
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;
QString level, status;
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();
int c;
for(c = 0; c < m->columnCount(); c++)
if(m->headerData(c, Qt::Horizontal).toString() == column)
break;
QAbstractItemModel *m = m_view->model();
bool hide;
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