Skip to content

Commit

Permalink
Implemented preliminary ability to edit the starting bit for signals.
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Jun 11, 2015
1 parent c855a09 commit 993a026
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
26 changes: 25 additions & 1 deletion candatagrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QPainter>
#include <QDebug>
#include <QMouseEvent>

CANDataGrid::CANDataGrid(QWidget *parent) :
QWidget(parent),
Expand All @@ -19,6 +20,25 @@ CANDataGrid::~CANDataGrid()
delete ui;
}

void CANDataGrid::mousePressEvent(QMouseEvent *event)
{
QPoint clickedPoint = event->pos();
if (event->button() == Qt::LeftButton)
{
//qDebug() << "Mouse Loc " << clickedPoint;
clickedPoint -= upperLeft;
if (clickedPoint.x() < 0 || clickedPoint.y() < 0)
{
//qDebug() << "Clicked outside the grid you wanker";
return;
}
int x = clickedPoint.x() / gridSize.x();
int y = clickedPoint.y() / gridSize.y();
//qDebug() << "Grid square clicked " << x << " " << y;
emit gridClicked(x,y);
}
}

void CANDataGrid::paintEvent(QPaintEvent *event)
{
int x, y;
Expand Down Expand Up @@ -111,7 +131,11 @@ void CANDataGrid::paintEvent(QPaintEvent *event)
//painter.fillRect(viewport.left() + (x+2) * xSector, viewport.top() + (y+2) * ySector, xSector, ySector, redBrush);
painter.drawRect(viewport.left() + (x+2) * xSector, viewport.top() + (y+2) * ySector, xSector, ySector);
}
}
}
upperLeft.setX(viewport.left() + 2 * xSector);
upperLeft.setY(viewport.top() + 2 * ySector);
gridSize.setX(xSector);
gridSize.setY(ySector);
}

void CANDataGrid::setReference(unsigned char *newRef, bool bUpdate = true)
Expand Down
7 changes: 7 additions & 0 deletions candatagrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ class CANDataGrid : public QWidget
void setReference(unsigned char *, bool);
void updateData(unsigned char *, bool);

protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;

signals:
void gridClicked(int x,int y);

private:
Ui::CANDataGrid *ui;
unsigned char refData[8];
unsigned char data[8];
QPoint upperLeft, gridSize;
};

#endif // CANDATAGRID_H
14 changes: 14 additions & 0 deletions dbcsignaleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) :
}

connect(ui->signalsList, SIGNAL(currentRowChanged(int)), this, SLOT(clickSignalList(int)));
connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int)));
}

DBCSignalEditor::~DBCSignalEditor()
Expand Down Expand Up @@ -89,6 +90,10 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig)
}

endBit = startBit + sig->signalSize - 1;
if (endBit > 63)
{
endBit = 63;
}

bitpattern[startBit / 8] |= 1 << (startBit % 8);
ui->bitfield->setReference(bitpattern, false);
Expand Down Expand Up @@ -155,3 +160,12 @@ void DBCSignalEditor::clickSignalList(int row)
fillValueTable(thisSig);

}

void DBCSignalEditor::bitfieldClicked(int x, int y)
{
int bit = (x) + (y * 8);
DBC_SIGNAL *thisSig = dbcHandler->findSignalByIdx(dbcMessage, ui->signalsList->currentRow());
if (thisSig == NULL) return;
thisSig->startBit = bit;
fillSignalForm(thisSig);
}
1 change: 1 addition & 0 deletions dbcsignaleditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DBCSignalEditor : public QDialog

private slots:
void clickSignalList(int);
void bitfieldClicked(int x, int y);

private:
Ui::DBCSignalEditor *ui;
Expand Down

0 comments on commit 993a026

Please sign in to comment.