Big changes to connection window to make it more intuitive. Also
brings window closer to supporting M2RET devices better.
This commit is contained in:
@@ -40,10 +40,10 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
|
||||
return QString(tr("Single Wire"));
|
||||
break;
|
||||
case 6:
|
||||
return QString(tr("Status"));
|
||||
return QString(tr("Active"));
|
||||
break;
|
||||
case 7:
|
||||
return QString(tr("Active"));
|
||||
return QString(tr("Status"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -54,11 +54,10 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
int CANConnectionModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 7;
|
||||
return 8;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,22 +74,87 @@ int CANConnectionModel::rowCount(const QModelIndex &parent) const
|
||||
return rows;
|
||||
}
|
||||
|
||||
Qt::ItemFlags CANConnectionModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::ItemFlag::NoItemFlags;
|
||||
|
||||
int busId;
|
||||
CANConnection *conn_p = getAtIdx(index.row(), busId);
|
||||
if (!conn_p) return Qt::ItemFlag::NoItemFlags;
|
||||
|
||||
//you can't set speed, single wire, or listen only on socketcan devices so
|
||||
//detect if we're using GVRET where you can and turn that functionality on
|
||||
bool editParams = false;
|
||||
if (conn_p->getType() == CANCon::GVRET_SERIAL) editParams = true;
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 3: //speed
|
||||
if (editParams) return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled;
|
||||
else return Qt::ItemFlag::NoItemFlags;
|
||||
break;
|
||||
case 4: //listen only
|
||||
case 5: //single wire
|
||||
if (editParams) return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
|
||||
else return Qt::ItemFlag::NoItemFlags;
|
||||
break;
|
||||
case 6: //enabled
|
||||
return Qt::ItemFlag::ItemIsEditable | Qt::ItemFlag::ItemIsEnabled | Qt::ItemFlag::ItemIsUserCheckable;
|
||||
break;
|
||||
default:
|
||||
return Qt::ItemFlag::ItemIsEnabled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CANConnectionModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
qDebug() << "setData: " << index.row() << ":" << index.column() << " role: " << role << " Val: " << value;
|
||||
|
||||
int busId;
|
||||
CANConnection *conn_p = getAtIdx(index.row(), busId);
|
||||
if (!conn_p) return false;
|
||||
CANBus bus;
|
||||
bool ret;
|
||||
ret = conn_p->getBusSettings(busId, bus);
|
||||
if (!ret) return false;
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case 3: //speed
|
||||
bus.speed = value.toInt();
|
||||
break;
|
||||
case 4: //listen only
|
||||
bus.listenOnly = value.toBool();
|
||||
break;
|
||||
case 5: //single wire
|
||||
bus.singleWire = value.toBool();
|
||||
break;
|
||||
case 6: //active
|
||||
bus.active = value.toBool();
|
||||
break;
|
||||
}
|
||||
conn_p->setBusSettings(busId, bus);
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
int busId;
|
||||
CANConnection *conn_p = getAtIdx(index.row(), busId);
|
||||
CANBus bus;
|
||||
bool ret;
|
||||
ret = conn_p->getBusSettings(busId, bus);
|
||||
bool isSocketCAN = (conn_p->getType() == CANCon::SOCKETCAN) ? true: false;
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
int busId;
|
||||
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())
|
||||
@@ -114,18 +178,34 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||
else qDebug() << "Tried to show connection port but connection was NULL";
|
||||
break;
|
||||
case 3: //speed
|
||||
return QString::number(bus.speed);
|
||||
if (!isSocketCAN) return QString::number(bus.speed);
|
||||
else return QString("N/A");
|
||||
case 4: //Listen Only
|
||||
return (bus.listenOnly) ? "True" : "False";
|
||||
return QVariant();
|
||||
case 5: //Single Wire
|
||||
return (bus.singleWire) ? "True" : "False";
|
||||
return QVariant();
|
||||
case 6: //Status
|
||||
return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected";
|
||||
return QVariant();
|
||||
case 7: //Active
|
||||
return (bus.active) ? "True" : "False";
|
||||
return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected";
|
||||
default: {}
|
||||
}
|
||||
}
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
switch (index.column())
|
||||
{
|
||||
case 4:
|
||||
return (bus.listenOnly) ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
case 5:
|
||||
return (bus.singleWire) ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
case 6:
|
||||
return (bus.active) ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
@@ -172,7 +252,6 @@ CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void CANConnectionModel::refresh(int pIndex)
|
||||
{
|
||||
QModelIndex begin;
|
||||
|
||||
Reference in New Issue
Block a user