Big changes to connection window to make it more intuitive. Also

brings window closer to supporting M2RET devices better.
This commit is contained in:
Collin Kidder
2017-10-18 21:48:13 -04:00
parent bb3fee1a12
commit 383ee8fe19
4 changed files with 131 additions and 149 deletions
+94 -15
View File
@@ -40,10 +40,10 @@ 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")); return QString(tr("Active"));
break; break;
case 7: case 7:
return QString(tr("Active")); return QString(tr("Status"));
break; break;
} }
} }
@@ -54,11 +54,10 @@ QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation
return QVariant(); return QVariant();
} }
int CANConnectionModel::columnCount(const QModelIndex &parent) const int CANConnectionModel::columnCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
return 7; return 8;
} }
@@ -75,22 +74,87 @@ int CANConnectionModel::rowCount(const QModelIndex &parent) const
return rows; 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 QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid())
return QVariant(); 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) { if (role == Qt::DisplayRole) {
int busId;
CANConnection *conn_p = getAtIdx(index.row(), busId);
if(!conn_p) if(!conn_p)
return QVariant(); return QVariant();
CANBus bus;
bool ret;
ret = conn_p->getBusSettings(busId, bus);
if(!ret) return QVariant(); if(!ret) return QVariant();
switch (index.column()) 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"; else qDebug() << "Tried to show connection port but connection was NULL";
break; break;
case 3: //speed case 3: //speed
return QString::number(bus.speed); if (!isSocketCAN) return QString::number(bus.speed);
else return QString("N/A");
case 4: //Listen Only case 4: //Listen Only
return (bus.listenOnly) ? "True" : "False"; return QVariant();
case 5: //Single Wire case 5: //Single Wire
return (bus.singleWire) ? "True" : "False"; return QVariant();
case 6: //Status case 6: //Status
return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected"; return QVariant();
case 7: //Active case 7: //Active
return (bus.active) ? "True" : "False"; return (conn_p->getStatus()==CANCon::CONNECTED) ? "Connected" : "Not Connected";
default: {} 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(); return QVariant();
} }
@@ -172,7 +252,6 @@ CANConnection* CANConnectionModel::getAtIdx(int pIdx, int& pBusId) const
return NULL; return NULL;
} }
void CANConnectionModel::refresh(int pIndex) void CANConnectionModel::refresh(int pIndex)
{ {
QModelIndex begin; QModelIndex begin;
+4
View File
@@ -21,6 +21,10 @@ public:
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 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;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
void add(CANConnection* pConn_p); void add(CANConnection* pConn_p);
+17 -64
View File
@@ -24,25 +24,17 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
connModel = new CANConnectionModel(this); connModel = new CANConnectionModel(this);
ui->tableConnections->setModel(connModel); ui->tableConnections->setModel(connModel);
ui->tableConnections->setColumnWidth(0, 50); ui->tableConnections->setColumnWidth(0, 40);
ui->tableConnections->setColumnWidth(1, 110); ui->tableConnections->setColumnWidth(1, 70);
ui->tableConnections->setColumnWidth(2, 110); ui->tableConnections->setColumnWidth(2, 70);
ui->tableConnections->setColumnWidth(3, 110); ui->tableConnections->setColumnWidth(3, 70);
ui->tableConnections->setColumnWidth(4, 75); ui->tableConnections->setColumnWidth(4, 70);
ui->tableConnections->setColumnWidth(5, 75); ui->tableConnections->setColumnWidth(5, 70);
ui->tableConnections->setColumnWidth(6, 75); ui->tableConnections->setColumnWidth(6, 70);
ui->tableConnections->setColumnWidth(7, 75); ui->tableConnections->setColumnWidth(7, 90);
QHeaderView *HorzHdr = ui->tableConnections->horizontalHeader(); QHeaderView *HorzHdr = ui->tableConnections->horizontalHeader();
HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview HorzHdr->setStretchLastSection(true); //causes the data column to automatically fill the tableview
ui->ckSingleWire->setChecked(settings.value("Main/SingleWireMode", false).toBool());
ui->cbSpeed->addItem(tr("125000"));
ui->cbSpeed->addItem(tr("250000"));
ui->cbSpeed->addItem(tr("500000"));
ui->cbSpeed->addItem(tr("1000000"));
ui->cbSpeed->addItem(tr("33333"));
ui->textConsole->setEnabled(false); ui->textConsole->setEnabled(false);
ui->btnClearDebug->setEnabled(false); ui->btnClearDebug->setEnabled(false);
ui->btnSendHex->setEnabled(false); ui->btnSendHex->setEnabled(false);
@@ -61,9 +53,7 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
connect(ui->rbGVRET, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged); connect(ui->rbGVRET, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbKvaser, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged); connect(ui->rbKvaser, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged); connect(ui->rbSocketCAN, &QAbstractButton::clicked, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged); connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &ConnectionWindow::currentRowChanged);
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll); connect(ui->btnActivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleEnableAll);
connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll); connect(ui->btnDeactivateAll, &QPushButton::clicked, this, &ConnectionWindow::handleDisableAll);
connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn); connect(ui->btnRemoveBus, &QPushButton::clicked, this, &ConnectionWindow::handleRemoveConn);
@@ -236,10 +226,10 @@ void ConnectionWindow::handleOKButton()
if(!ret) return; if(!ret) return;
bus.setListenOnly(ui->ckListenOnly->isChecked()); //bus.setListenOnly(ui->ckListenOnly->isChecked());
bus.setSingleWire(ui->ckSingleWire->isChecked()); //bus.setSingleWire(ui->ckSingleWire->isChecked());
bus.setEnabled(ui->ckEnabled->isChecked()); //bus.setEnabled(ui->ckEnabled->isChecked());
bus.setSpeed(ui->cbSpeed->currentText().toInt()); //bus.setSpeed(ui->cbSpeed->currentText().toInt());
/* update bus settings */ /* update bus settings */
conn_p->setBusSettings(busId, bus); conn_p->setBusSettings(busId, bus);
@@ -255,11 +245,11 @@ void ConnectionWindow::handleOKButton()
for (int i=0 ; i<conn_p->getNumBuses() ; i++) { for (int i=0 ; i<conn_p->getNumBuses() ; i++) {
/* set bus configuration */ /* set bus configuration */
CANBus bus; CANBus bus;
bus.active = ui->ckEnabled->isChecked(); //bus.active = ui->ckEnabled->isChecked();
bus.listenOnly = ui->ckListenOnly->isChecked(); //bus.listenOnly = ui->ckListenOnly->isChecked();
bus.singleWire = ui->ckSingleWire->isChecked(); //bus.singleWire = ui->ckSingleWire->isChecked();
bus.speed = ui->cbSpeed->currentText().toInt(); //bus.speed = ui->cbSpeed->currentText().toInt();
/* update bus settings */ /* update bus settings */
conn_p->setBusSettings(i, bus); conn_p->setBusSettings(i, bus);
@@ -280,6 +270,7 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
disconnect(connModel->getAtIdx(previous.row(), busId), SIGNAL(debugOutput(QString)), 0, 0); disconnect(connModel->getAtIdx(previous.row(), busId), SIGNAL(debugOutput(QString)), 0, 0);
disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row(), busId), SLOT(debugInput(QByteArray))); disconnect(this, SIGNAL(sendDebugData(QByteArray)), connModel->getAtIdx(previous.row(), busId), SLOT(debugInput(QByteArray)));
return;
/* enable / diable connection type */ /* enable / diable connection type */
ui->stPort->setEnabled(selIdx==-1); ui->stPort->setEnabled(selIdx==-1);
@@ -291,9 +282,6 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
{ {
ui->btnOK->setText(tr("Create New Connection")); ui->btnOK->setText(tr("Create New Connection"));
ui->rbGVRET->setChecked(true); ui->rbGVRET->setChecked(true);
ui->ckListenOnly->setChecked(false);
ui->ckSingleWire->setChecked(false);
ui->ckEnabled->setChecked(false);
setSpeed(0); setSpeed(0);
setPortName(CANCon::GVRET_SERIAL, ""); setPortName(CANCon::GVRET_SERIAL, "");
} }
@@ -313,9 +301,6 @@ void ConnectionWindow::currentRowChanged(const QModelIndex &current, const QMode
if(!ret) return; if(!ret) return;
ui->btnOK->setText(tr("Update Connection Settings")); ui->btnOK->setText(tr("Update Connection Settings"));
ui->ckListenOnly->setChecked(bus.isListenOnly());
ui->ckSingleWire->setChecked(bus.isSingleWire());
ui->ckEnabled->setChecked(bus.isActive());
setSpeed(bus.getSpeed()); setSpeed(bus.getSpeed());
setPortName(conn_p->getType(), conn_p->getPort()); setPortName(conn_p->getType(), conn_p->getPort());
} }
@@ -349,7 +334,6 @@ void ConnectionWindow::selectSerial()
{ {
/* set combobox page visible */ /* set combobox page visible */
ui->stPort->setCurrentWidget(ui->cbPage); ui->stPort->setCurrentWidget(ui->cbPage);
ui->cbSpeed->setEnabled(true);
ui->cbPort->clear(); ui->cbPort->clear();
ports = QSerialPortInfo::availablePorts(); ports = QSerialPortInfo::availablePorts();
@@ -362,7 +346,6 @@ void ConnectionWindow::selectKvaser()
{ {
/* set combobox page visible */ /* set combobox page visible */
ui->stPort->setCurrentWidget(ui->cbPage); ui->stPort->setCurrentWidget(ui->cbPage);
ui->cbSpeed->setEnabled(false);
} }
void ConnectionWindow::selectSocketCan() void ConnectionWindow::selectSocketCan()
@@ -373,18 +356,6 @@ void ConnectionWindow::selectSocketCan()
void ConnectionWindow::setSpeed(int speed0) void ConnectionWindow::setSpeed(int speed0)
{ {
for (int i = 0; i < ui->cbSpeed->count(); i++)
{
if (ui->cbSpeed->itemText(i).toInt() == speed0)
{
ui->cbSpeed->setCurrentIndex(i);
return;
}
}
/* add custom speed */
ui->cbSpeed->addItem(QString::number(speed0));
ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
} }
void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName) void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
@@ -393,9 +364,6 @@ void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
{ {
case CANCon::GVRET_SERIAL: case CANCon::GVRET_SERIAL:
ui->rbGVRET->setChecked(true); ui->rbGVRET->setChecked(true);
ui->cbSpeed->setEnabled(true);
ui->ckListenOnly->setEnabled(true);
ui->ckSingleWire->setEnabled(true);
break; break;
case CANCon::KVASER: case CANCon::KVASER:
ui->rbKvaser->setChecked(true); ui->rbKvaser->setChecked(true);
@@ -403,9 +371,6 @@ void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
case CANCon::SOCKETCAN: case CANCon::SOCKETCAN:
ui->rbSocketCAN->setChecked(true); ui->rbSocketCAN->setChecked(true);
//you can't configure any of the below three with socketcan so dim them out //you can't configure any of the below three with socketcan so dim them out
ui->cbSpeed->setEnabled(false);
ui->ckListenOnly->setEnabled(false);
ui->ckSingleWire->setEnabled(false);
break; break;
default: {} default: {}
} }
@@ -435,16 +400,6 @@ void ConnectionWindow::setPortName(CANCon::type pType, QString pPortName)
//-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want. //-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want.
int ConnectionWindow::getSpeed() int ConnectionWindow::getSpeed()
{ {
switch (ui->cbSpeed->currentIndex())
{
case -1:
case 0:
return -1;
case 1:
return 0;
default:
return (ui->cbSpeed->currentText().toInt());
}
} }
QString ConnectionWindow::getPortName() QString ConnectionWindow::getPortName()
@@ -475,12 +430,10 @@ CANCon::type ConnectionWindow::getConnectionType()
void ConnectionWindow::setSWMode(bool mode) void ConnectionWindow::setSWMode(bool mode)
{ {
ui->ckSingleWire->setChecked(mode);
} }
bool ConnectionWindow::getSWMode() bool ConnectionWindow::getSWMode()
{ {
if (ui->ckSingleWire->checkState() == Qt::Checked) return true;
return false; return false;
} }
+16 -70
View File
@@ -25,6 +25,9 @@
</item> </item>
<item> <item>
<widget class="QTableView" name="tableConnections"> <widget class="QTableView" name="tableConnections">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
@@ -35,13 +38,6 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="btnNewConn">
<property name="text">
<string>New Connection</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="btnRemoveBus"> <widget class="QPushButton" name="btnRemoveBus">
<property name="text"> <property name="text">
@@ -49,10 +45,6 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item> <item>
<widget class="QPushButton" name="btnActivateAll"> <widget class="QPushButton" name="btnActivateAll">
<property name="text"> <property name="text">
@@ -193,45 +185,6 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="ckSingleWire">
<property name="text">
<string>Single Wire Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckListenOnly">
<property name="text">
<string>Listen Only Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckEnabled">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>CAN Speed</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbSpeed">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
@@ -241,15 +194,21 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="btnRevert">
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter"> <item alignment="Qt::AlignHCenter">
<widget class="QCheckBox" name="ckEnableConsole"> <widget class="QCheckBox" name="ckEnableConsole">
<property name="text"> <property name="text">
@@ -319,19 +278,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>