QtHPConnect/treemodel.cpp

85 lines
1.8 KiB
C++
Raw Normal View History

2019-02-10 14:32:15 +01:00
#include "treemodel.h"
2019-02-10 14:43:00 +01:00
#include "hptreeitem.h"
2019-02-10 14:32:15 +01:00
2019-02-10 14:43:00 +01:00
treeModel::treeModel(QObject *parent)
:QStandardItemModel(parent)
2019-02-10 14:32:15 +01:00
{
2019-02-10 14:43:00 +01:00
setItemPrototype(new hpTreeItem());
createRoot();
}
int treeModel::createRoot()
{
rootNode = invisibleRootItem();
return 0;
}
//Rework - name should be calc name
int treeModel::addCalculator(QString name, hpusb * handle){
hpDataLink hplink;
hpCalcData * hpData = new hpCalcData(handle);
hpTreeItem * hpCalc = new hpTreeItem(name,hpData,0);
QObject::connect(hpData, SIGNAL(dataChanged(hp_Change)),hpCalc, SLOT(dataChange(hp_Change)));
setHpCalcData(name,hpData,hpCalc);
rootNode->appendRow(hpCalc);
hpData->readInfo();
}
hpCalcData * treeModel::getCalculator(QString name){
hpDataLink hplink;
hpCalcData * hpdata = nullptr;
QMap<QString, hpDataLink>::const_iterator i = hpCalcList.find(name);
if (i!=hpCalcList.end()) {
hplink = i.value();
hpdata= hplink.dataItem;
}
return hpdata;
}
2019-02-10 14:32:15 +01:00
2019-02-10 14:43:00 +01:00
QString treeModel::getLastDataKey() {
return hpCalcList.lastKey();
2019-02-10 14:32:15 +01:00
}
2019-02-10 14:43:00 +01:00
//manage link between tree and data
//A map stores the treeItem, dataItem and in future perhaps the handle in a list
// retrievable by a string key
hpCalcData * treeModel::getHpCalcData(QString name) {
hpDataLink hplink;
hpCalcData * hpdata;
QMap<QString, hpDataLink>::const_iterator i = hpCalcList.find(name);
if (i!=hpCalcList.end()) {
hplink = i.value();
hpdata= hplink.dataItem;
}
return hpdata;
}
//manage link between tree and data
void treeModel::setHpCalcData(QString name, hpCalcData * data, hpTreeItem * tree ){
hpDataLink hplink;
hplink.dataItem=data;
hplink.treeItem=tree;
hpCalcList.insert(name,hplink);
return;
}
treeModel::~treeModel() {
delete rootNode;
}