changed the way connections are organized and retrieved by connection window
This commit is contained in:
+72
-48
@@ -1,5 +1,4 @@
|
|||||||
#include "canconnection.h"
|
#include "connections/canconnection.h"
|
||||||
#include "canconnectioncontainer.h"
|
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
|
|
||||||
CANConnectionModel::CANConnectionModel(QObject *parent)
|
CANConnectionModel::CANConnectionModel(QObject *parent)
|
||||||
@@ -7,11 +6,6 @@ CANConnectionModel::CANConnectionModel(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANConnectionModel::refreshView()
|
|
||||||
{
|
|
||||||
beginResetModel();
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
@@ -41,6 +35,9 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
|
|||||||
return QString(tr("Single Wire"));
|
return QString(tr("Single Wire"));
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
|
return QString(tr("Status"));
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
return QString(tr("Active"));
|
return QString(tr("Active"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -52,97 +49,124 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CANConnectionModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return buses.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
int CANConnectionModel::columnCount(const QModelIndex &parent) const
|
int CANConnectionModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CANConnectionModel::rowCount(const QModelIndex &parent) const {
|
||||||
|
int rows=0;
|
||||||
|
QList<CANConnection*>::const_iterator iter;
|
||||||
|
|
||||||
|
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
||||||
|
rows+=(*iter)->getNumBuses();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (index.row() >= (buses.count()))
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
CANBus bus = buses[index.row()];
|
int busId;
|
||||||
CANConnection *conn = bus.getContainer()->getRef();
|
CANConnection *conn_p = getAtIdx(index.row(), busId);
|
||||||
|
if(!conn_p)
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
CANBus bus;
|
||||||
|
bool ret;
|
||||||
|
ret = conn_p->getBusSettings(busId, bus);
|
||||||
|
if(!ret) return QVariant();
|
||||||
|
|
||||||
switch (index.column())
|
switch (index.column())
|
||||||
{
|
{
|
||||||
case 0: //bus
|
case 0: //bus
|
||||||
return QString::number(bus.busNum);
|
return QString::number(busId);
|
||||||
break;
|
break;
|
||||||
case 1: //type
|
case 1: //type
|
||||||
if (conn) return conn->getConnTypeName();
|
if (conn_p)
|
||||||
|
switch (conn_p->getType()) {
|
||||||
|
case CANCon::KVASER: return "KVASER";
|
||||||
|
case CANCon::SOCKETCAN: return "SocketCAN";
|
||||||
|
case CANCon::GVRET_SERIAL: return "GVRET";
|
||||||
|
default: {}
|
||||||
|
}
|
||||||
else qDebug() << "Tried to show connection type but connection was NULL";
|
else qDebug() << "Tried to show connection type but connection was NULL";
|
||||||
break;
|
break;
|
||||||
case 2: //port
|
case 2: //port
|
||||||
if (conn) return conn->getConnPortName();
|
if (conn_p) return conn_p->getPort();
|
||||||
else qDebug() << "Tried to show connection port but connection was NULL";
|
else qDebug() << "Tried to show connection port but connection was NULL";
|
||||||
break;
|
break;
|
||||||
case 3: //speed
|
case 3: //speed
|
||||||
return QString::number(bus.speed);
|
return QString::number(bus.speed);
|
||||||
break;
|
|
||||||
case 4: //Listen Only
|
case 4: //Listen Only
|
||||||
if (bus.listenOnly) return QString("True");
|
return (bus.listenOnly) ? "True" : "False";
|
||||||
else return QString("False");
|
|
||||||
break;
|
|
||||||
case 5: //Single Wire
|
case 5: //Single Wire
|
||||||
if (bus.singleWire) return QString("True");
|
return (bus.singleWire) ? "True" : "False";
|
||||||
else return QString("False");
|
case 6: //Status
|
||||||
break;
|
return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected";
|
||||||
case 6: //Active
|
case 7: //Active
|
||||||
if (bus.active) return QString("True");
|
return (bus.active) ? "True" : "False";
|
||||||
else return QString("False");
|
default: {}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CANConnectionModel::addBus(CANBus &bus)
|
void CANConnectionModel::add(CANConnection* pConn_p)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
buses.append(bus);
|
mConns.append(pConn_p);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CANConnectionModel::removeBus(int busIdx)
|
|
||||||
|
void CANConnectionModel::remove(CANConnection* pConn_p)
|
||||||
{
|
{
|
||||||
if (busIdx>=0 && busIdx < buses.count()) {
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
buses.removeAt(busIdx);
|
mConns.removeOne(pConn_p);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CANBus* CANConnectionModel::getBus(int bus)
|
|
||||||
|
QList<CANConnection*>& CANConnectionModel::getConnections()
|
||||||
{
|
{
|
||||||
if (bus < 0) return NULL;
|
return mConns;
|
||||||
if (bus >= buses.count()) return NULL;
|
|
||||||
return &buses[bus];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CANBus* CANConnectionModel::findBusByNum(int bus)
|
CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buses.count(); i++)
|
if (pIdx < 0)
|
||||||
{
|
return NULL;
|
||||||
if (buses[i].busNum == bus)
|
|
||||||
{
|
int i=0;
|
||||||
return &buses[i];
|
QList<CANConnection*>::const_iterator iter = mConns.begin();
|
||||||
|
|
||||||
|
for (iter = mConns.begin() ; iter != mConns.end() ; ++iter) {
|
||||||
|
if( i <= pIdx && pIdx < i+(*iter)->getNumBuses() ) {
|
||||||
|
pBusId = pIdx - i;
|
||||||
|
return (*iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i+= (*iter)->getNumBuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CANConnectionModel::refreshView()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|||||||
+12
-15
@@ -1,13 +1,13 @@
|
|||||||
#ifndef CANCONNECTIONMODEL_H
|
#ifndef CANCONNECTIONMODEL_H
|
||||||
#define CANCONNECTIONMODEL_H
|
#define CANCONNECTIONMODEL_H
|
||||||
|
|
||||||
#include "canconnection.h"
|
|
||||||
#include "canbus.h"
|
|
||||||
#include "canconnectioncontainer.h"
|
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
class CANConnectionContainer;
|
#include "canbus.h"
|
||||||
|
#include "connections/canconnection.h"
|
||||||
|
#include "connectionwindow.h"
|
||||||
|
|
||||||
|
|
||||||
class CANConnectionModel : public QAbstractTableModel
|
class CANConnectionModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
@@ -19,24 +19,21 @@ public:
|
|||||||
// Header:
|
// Header:
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
void addConnection(CANConnectionContainer *conn);
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
void removeConnection(CANConnection*);
|
|
||||||
void addBus(CANBus &bus);
|
void add(CANConnection* pConn_p);
|
||||||
void removeBus(int busIdx);
|
void remove(CANConnection* pConn_p);
|
||||||
CANBus* getBus(int bus);
|
|
||||||
CANConnection* getConnection(int conn);
|
QList<CANConnection*>& getConnections();
|
||||||
|
CANConnection* getAtIdx(int, int&) const;
|
||||||
void refreshView();
|
void refreshView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CANConnectionContainer *> connections;
|
QList<CANConnection*> mConns;
|
||||||
QList<CANBus> buses;
|
|
||||||
|
|
||||||
CANBus *findBusByNum(int bus);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CANCONNECTIONMODEL_H
|
#endif // CANCONNECTIONMODEL_H
|
||||||
|
|||||||
Reference in New Issue
Block a user