Skip to content
Snippets Groups Projects
Commit c6d1ad8e authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

uses elettra.eu.qutreemodel

parent 37bd73dc
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,9 @@
#include <quapps.h>
// cumbia
// tree model plugin
#include <qutreemodelplugininterface.h>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QLabel>
......@@ -16,6 +19,11 @@
#include <qulabel.h>
#include <qubutton.h>
#include <QGridLayout>
#include <QAbstractItemModel>
#include <QTreeView>
#include <QLineEdit>
#include <cupluginloader.h>
Alarmmanager::Alarmmanager(CumbiaPool *cumbia_pool, QWidget *parent) :
......@@ -24,101 +32,74 @@ Alarmmanager::Alarmmanager(CumbiaPool *cumbia_pool, QWidget *parent) :
// cumbia
CuModuleLoader mloader(cumbia_pool, &m_ctrl_factory_pool, &m_log_impl);
cu_pool = cumbia_pool;
// ui = new Ui::Alarmmanager;
// ui->setupUi(this, cu_pool, m_ctrl_factory_pool);
// mloader.modules() to get the list of loaded modules
// cumbia
for(int i = 1; i < qApp->arguments().size(); i++) {
const QString s = qApp->arguments().at(i);
if(s.count('/') >= 2) { // probably a device
Qu1TWatcher *w = new Qu1TWatcher(this, cumbia_pool, m_ctrl_factory_pool);
w->attach(this, SLOT(m_load(const QStringList &)));
w->setSource(s + "/alarmList");
pretty_pri(" source %s", qstoc( w->source()));
CuPluginLoader loader;
QObject **qo = nullptr;
tree_i = loader.get<QuTreeModelPluginInterface>(QuTreeModelPluginInterface::file_name, qo);
if(!tree_i)
perr("%s: plugin \"%s\" not found", __FUNCTION__, QuTreeModelPluginInterface::file_name);
else {
QuTreeModelI *mi = tree_i->instantiate({"Alarm"}, this);
m_model = mi->qmodel();
m_model_i = mi;
// ui = new Ui::Alarmmanager;
// ui->setupUi(this, cu_pool, m_ctrl_factory_pool);
// mloader.modules() to get the list of loaded modules
// cumbia
for(int i = 1; i < qApp->arguments().size(); i++) {
const QString s = qApp->arguments().at(i);
if(s.count('/') >= 2) { // probably a device
Qu1TWatcher *w = new Qu1TWatcher(this, cumbia_pool, m_ctrl_factory_pool);
w->attach(this, SLOT(m_load(const QStringList &)));
w->setSource(s + "/alarmList");
pretty_pri(" source %s", qstoc( w->source()));
}
}
}
QGridLayout *lo = new QGridLayout(this);
lo->setObjectName("lo0");
QGridLayout *lo = new QGridLayout(this);
lo->setObjectName("lo0");
resize(1024, 768);
}
// tree view
QTreeView *t = new QTreeView(this);
lo->addWidget(t, 0, 0, 10, 4);
t->setModel(this->m_model_i->qmodel());
Alarmmanager::~Alarmmanager()
{
// delete ui;
}
QLabel *search_l = new QLabel("Search", this);
QLineEdit *search_le = new QLineEdit(this);
search_le->setPlaceholderText("Type text to search...");
connect(search_le, SIGNAL(textChanged(QString)), this, SLOT(m_filter(QString)));
lo->addWidget(search_l, 10, 0, 1, 1);
lo->addWidget(search_le, 10, 1, 1, 3);
QTreeWidgetItem * Alarmmanager::findItem(const QString& s, QTreeWidgetItem *par) {
// printf(" searching for %s under %p (%s) with %d children", qstoc(s), par,
// par ? qstoc(par->text(0)) : "-", par ? par->childCount() : -1);
// if(par)
// printf(" (%s)\n", qstoc(par->text(0)));
// else printf("\n");
QTreeWidget *t = findChild<QTreeWidget *>();
const QStringList& p = s.split('/', Qt::SkipEmptyParts);
assert(p.size() > 0 && t != nullptr);
if(par && par->text(0) == p[0])
return par;
if(!par) {
for(int i = 0; i < t->topLevelItemCount(); i++) {
// printf(" \e[1,33m searching %s under top level items %d text %s\e[0m\n",
// qstoc( p[0]),
// t->topLevelItemCount(),
// qstoc(t->topLevelItem(i)->text(0)));
if(t->topLevelItem(i)->text(0) == p[0])
return t->topLevelItem(i);
}
resize(1024, 768);
}
else {
for(int i = 0; i < par->childCount(); i++) {
// printf(" \e[1,36m searching %s under item with %d children text %s\e[0m\n",
// qstoc( p[0]),
// par->childCount(),
// qstoc(par->child(i)->text(0)));
if(par->child(i)->text(0) == p[0])
return s.count('/') > 0 ? findItem(s.section('/', 1), par->child(i)) : par->child(i);
}
}
// printf(" \e[1;31m no item found under parent %p (%s) while searching %s\e[0m\n", par,
// par ? qstoc(par->text(0)) : "-", qstoc(s));
return nullptr;
}
void Alarmmanager::m_add_item(QTreeWidgetItem *par, const QString &s)
{
// printf("\e[0;32m+ %s under %s\e[0m\n", qstoc(s), par != nullptr ? qstoc(par->text(0)) : "-");
QStringList p = s.split('/', Qt::SkipEmptyParts);
QTreeWidgetItem *t = nullptr;
if(p.size() > 0) {
t = findItem(p[0], par);
if(!t) {
if(!par)
t = new QTreeWidgetItem(findChild<QTreeWidget *>(), QStringList {p[0]} );
else
t = new QTreeWidgetItem(par, QStringList {p[0]} );
// printf(" \e[1;32m++++ adding %s (%p) under %s\e[0m\n", qstoc(p[0]), t, !par ? "main tree"
// : qstoc(par->text(0)));
Alarmmanager::~Alarmmanager() {
// delete ui;
}
void Alarmmanager::m_filter(const QString &s) {
QList<QModelIndex > il = m_model_i->findItems(s);
foreach(const QModelIndex& i, il) {
printf("%d,%d, %s\n", i.row(), i.column(), qstoc(m_model_i->printItem(i)));
findChild<QTreeView *>()->expand(i);
QModelIndex p(i.parent());
while(p.isValid()) {
findChild<QTreeView *>()->expand(p);
p = p.parent();
}
if(p.size() > 1)
m_add_item(t, s.section('/', 1));
}
findChild<QTreeView *>()->keyboardSearch(s);
}
void Alarmmanager::m_load(const QStringList& args) {
QTreeWidget *t = findChild<QTreeWidget *>();
if(!t) {
t = new QTreeWidget(this);
findChild<QGridLayout *>()->addWidget(t, 0, 0, 10, 4);
}
foreach(QString s, args) {
s.remove(QRegularExpression("tango://[A-Za-z0-9\\.\\-:]+/"));
// pretty_pri("processing %s", qstoc(s));
m_add_item(nullptr, s);
m_model_i->addItem(s);
}
foreach(const QModelIndex& i, m_model_i->itemsWithChildren(QModelIndex()))
findChild<QTreeView *>()->expand(i);
}
......@@ -15,6 +15,9 @@ class Alarmmanager;
class QTreeWidget;
class QTreeWidgetItem;
class QuTreeModelPluginInterface;
class QAbstractItemModel;
class QuTreeModelI;
class Alarmmanager : public QWidget
{
......@@ -37,9 +40,13 @@ private:
void m_add_item(QTreeWidgetItem *t, const QString& s);
private slots:
QuTreeModelPluginInterface *tree_i;
QAbstractItemModel *m_model;
QuTreeModelI *m_model_i;
private slots:
void m_filter(const QString& s);
void m_load(const QStringList &args);
};
......
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