#include "PSetConfigurationTable.h"
#include <QKeyEvent>
//! PSetConfigurationTable - Constructor
/*!
* Set up the tablewidget; arguments are the size of row & columns
*/
PSetConfigurationTable
::PSetConfigurationTable(QWidget *parent,
int xPos,
int yPos,
int width,
int height)
mXPos(xPos),
mYPos(yPos),
mWidth(width),
mHeight(height)
{
setTable();
}
//! keyPressEvent
/*!
* Receives the keypress event when
* the table widget is in focus.
*/
void PSetConfigurationTable
::keyPressEvent(QKeyEvent *e
) {
if(e->key() == ButtonKeyDefines::QKEY_OK || e->key() == ButtonKeyDefines::QKEY_SOFTBUTTON_RIGHT)
{
if ((currentRow() == 0 && currentColumn() == 1) || (currentRow() == 2 && currentColumn() == 1))
{
}
}
/*!
* Forward the event to the parent widget
*/
}
Qt::KeyboardModifiers /*modifiers*/)
{
switch (cursorAction)
{
case MoveUp:
if (current.row() > 0)
{
current = model()->index(current.row() - 1, current.column(), rootIndex());
}
else
{
current = model()->index(0, current.column(), rootIndex());
}
break;
case MoveDown:
if (current.row() < rows(current) - 1)
{
current = model()->index(current.row() + 1, current.column(), rootIndex());
}
else
{
current = model()->index(rows(current) - 1, current.column(), rootIndex());
}
break;
default:
break;
}
viewport()->update();
return current;
}
int PSetConfigurationTable
::rows(const QModelIndex &index
) const {
return model()->rowCount(model()->parent(index));
}
void PSetConfigurationTable::moveUp()
{
setCell(current.row(), current.column());
}
void PSetConfigurationTable::moveDown()
{
setCell(current.row(), current.column());
}
//! showEvent
/*!
* If a parameter in a cell table is updated
* the cell size is adjusted to the new value.
*/
void PSetConfigurationTable
::showEvent(QShowEvent*) {
adjustSize();
}
//! setTable
/*!
* Set the table size, add delegate,
* initiate header items & set properties.
*/
void PSetConfigurationTable::setTable()
{
setRowCount(4);
setColumnCount(3);
// #FFE600
setStyleSheet("QTableWidget {selection-background-color : black } ");
pItemDelegate = new PSetItemDelegate;
setItemDelegate(pItemDelegate);
setHorizontalHeaderItem(0, pItemHeaderA);
setHorizontalHeaderItem(1, pItemHeaderB);
setHorizontalHeaderItem(2, pItemHeaderC);
horizontalHeader
()->setResizeMode
(QHeaderView::ResizeToContents);
verticalHeader
()->setResizeMode
(QHeaderView::ResizeToContents);
setGeometry( mXPos, mYPos, mWidth, mHeight);
setFrameShape
(QFrame::NoFrame);
horizontalHeader()->hide();
verticalHeader()->hide();
setShowGrid(false);
}
//! populateTable
/*!
* Add items & pset parameter data to the tablewidget.
* If the cell is editable setData is used. It sets the
* item's data for the given role to the specified value.
*/
void PSetConfigurationTable
::populateTable(QString torque,
QString batchSize
) {
/*!
* Column Torque
*/
pItemTextTorque->setText("Torque");
setItem(ROW_TORQUE, FIRST_COLUMN, pItemTextTorque);
pItemTorque
->setData
(Qt
::EditRole,
QVariant(torque
));
pItemTorque->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_TORQUE, SECOND_COLUMN, pItemTorque);
pItemTextNm->setText("Nm");
pItemTextNm->setTextAlignment(Qt::AlignLeft);
setItem(ROW_TORQUE, THIRD_COLUMN, pItemTextNm);
/*!
* Column Batch
*/
pItemTextBatch->setText("Batch");
setItem(ROW_BATCH, FIRST_COLUMN, pItemTextBatch);
pItemBatch->setText("ON");
pItemBatch->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_BATCH, SECOND_COLUMN, pItemBatch);
/*!
* Column Batch size
*/
pItemTextBatchSize->setText("Batch Size");
setItem(ROW_BATCHSIZE, FIRST_COLUMN, pItemTextBatchSize);
pItemBatchSize
->setData
(Qt
::EditRole,
QVariant(batchSize
));
pItemBatchSize->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_BATCHSIZE, SECOND_COLUMN, pItemBatchSize);
/*!
* Column Rehit
*/
pItemTextRehit->setText("Rehit");
setItem(ROW_REHIT, FIRST_COLUMN, pItemTextRehit);
pItemRehit->setText("OFF");
pItemRehit->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_REHIT, SECOND_COLUMN, pItemRehit);
setCell(0, 1);
}
//! setCell
/*!
* Sets the current cell to be the cell at position (row, column).
*/
void PSetConfigurationTable::setCell(int row, int column)
{
setCurrentCell(row, column);
}
void PSetConfigurationTable
::setTorqueValue(QString torqueValue
) {
torqueItem->setText(torqueValue);
}
void PSetConfigurationTable
::setBatchSizeValue(QString batchSizeValue
) {
batchSizeItem->setText(batchSizeValue);
}
//! getTorqueValue
/*!
* item(row, column) returns the item for the given row and column.
* The items torque value is returned.
*/
QString PSetConfigurationTable
::getTorqueValue() {
return torqueItem->text();
}
//! getBatchSizeValue
/*!
* item(row, column) returns the item for the given row and column.
* The items batch size value is returned.
*/
QString PSetConfigurationTable
::getBatchSizeValue() {
return batchSizeItem->text();
}
#include "PSetConfigurationTable.h"
#include <QKeyEvent>
//! PSetConfigurationTable - Constructor
/*!
* Set up the tablewidget; arguments are the size of row & columns
*/
PSetConfigurationTable::PSetConfigurationTable(QWidget *parent,
int xPos,
int yPos,
int width,
int height)
: QTableWidget(parent),
mXPos(xPos),
mYPos(yPos),
mWidth(width),
mHeight(height)
{
setTable();
}
//! keyPressEvent
/*!
* Receives the keypress event when
* the table widget is in focus.
*/
void PSetConfigurationTable::keyPressEvent(QKeyEvent *e)
{
if(e->key() == ButtonKeyDefines::QKEY_OK || e->key() == ButtonKeyDefines::QKEY_SOFTBUTTON_RIGHT)
{
if ((currentRow() == 0 && currentColumn() == 1) || (currentRow() == 2 && currentColumn() == 1))
{
QAbstractItemView::edit(currentIndex(), QAbstractItemView::EditKeyPressed, e);
}
}
/*!
* Forward the event to the parent widget
*/
QTableWidget::keyPressEvent(e);
}
QModelIndex PSetConfigurationTable::moveCursor(QAbstractItemView::CursorAction cursorAction,
Qt::KeyboardModifiers /*modifiers*/)
{
QModelIndex current = currentIndex();
switch (cursorAction)
{
case MoveUp:
if (current.row() > 0)
{
current = model()->index(current.row() - 1, current.column(), rootIndex());
}
else
{
current = model()->index(0, current.column(), rootIndex());
}
break;
case MoveDown:
if (current.row() < rows(current) - 1)
{
current = model()->index(current.row() + 1, current.column(), rootIndex());
}
else
{
current = model()->index(rows(current) - 1, current.column(), rootIndex());
}
break;
default:
break;
}
viewport()->update();
return current;
}
int PSetConfigurationTable::rows(const QModelIndex &index) const
{
return model()->rowCount(model()->parent(index));
}
void PSetConfigurationTable::moveUp()
{
QModelIndex current = moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier);
setCell(current.row(), current.column());
}
void PSetConfigurationTable::moveDown()
{
QModelIndex current = moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier);
setCell(current.row(), current.column());
}
//! showEvent
/*!
* If a parameter in a cell table is updated
* the cell size is adjusted to the new value.
*/
void PSetConfigurationTable::showEvent(QShowEvent*)
{
adjustSize();
}
//! setTable
/*!
* Set the table size, add delegate,
* initiate header items & set properties.
*/
void PSetConfigurationTable::setTable()
{
setRowCount(4);
setColumnCount(3);
// #FFE600
setStyleSheet("QTableWidget {selection-background-color : black } ");
pItemDelegate = new PSetItemDelegate;
setItemDelegate(pItemDelegate);
setEditTriggers(QAbstractItemView::EditKeyPressed);
pItemHeaderA = new QTableWidgetItem();
setHorizontalHeaderItem(0, pItemHeaderA);
pItemHeaderB = new QTableWidgetItem();
setHorizontalHeaderItem(1, pItemHeaderB);
pItemHeaderC = new QTableWidgetItem();
setHorizontalHeaderItem(2, pItemHeaderC);
horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
setGeometry( mXPos, mYPos, mWidth, mHeight);
setFrameShape(QFrame::NoFrame);
horizontalHeader()->hide();
verticalHeader()->hide();
setShowGrid(false);
}
//! populateTable
/*!
* Add items & pset parameter data to the tablewidget.
* If the cell is editable setData is used. It sets the
* item's data for the given role to the specified value.
*/
void PSetConfigurationTable::populateTable(QString torque, QString batchSize)
{
/*!
* Column Torque
*/
pItemTextTorque = new QTableWidgetItem();
pItemTextTorque->setText("Torque");
setItem(ROW_TORQUE, FIRST_COLUMN, pItemTextTorque);
pItemTorque = new QTableWidgetItem();
pItemTorque->setData(Qt::EditRole, QVariant(torque));
pItemTorque->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_TORQUE, SECOND_COLUMN, pItemTorque);
pItemTextNm = new QTableWidgetItem();
pItemTextNm->setText("Nm");
pItemTextNm->setTextAlignment(Qt::AlignLeft);
setItem(ROW_TORQUE, THIRD_COLUMN, pItemTextNm);
/*!
* Column Batch
*/
pItemTextBatch = new QTableWidgetItem();
pItemTextBatch->setText("Batch");
setItem(ROW_BATCH, FIRST_COLUMN, pItemTextBatch);
pItemBatch = new QTableWidgetItem();
pItemBatch->setText("ON");
pItemBatch->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_BATCH, SECOND_COLUMN, pItemBatch);
/*!
* Column Batch size
*/
pItemTextBatchSize = new QTableWidgetItem();
pItemTextBatchSize->setText("Batch Size");
setItem(ROW_BATCHSIZE, FIRST_COLUMN, pItemTextBatchSize);
pItemBatchSize = new QTableWidgetItem(batchSize);
pItemBatchSize->setData(Qt::EditRole, QVariant(batchSize));
pItemBatchSize->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_BATCHSIZE, SECOND_COLUMN, pItemBatchSize);
/*!
* Column Rehit
*/
pItemTextRehit = new QTableWidgetItem();
pItemTextRehit->setText("Rehit");
setItem(ROW_REHIT, FIRST_COLUMN, pItemTextRehit);
pItemRehit = new QTableWidgetItem();
pItemRehit->setText("OFF");
pItemRehit->setTextAlignment(Qt::AlignHCenter);
setItem(ROW_REHIT, SECOND_COLUMN, pItemRehit);
setCell(0, 1);
}
//! setCell
/*!
* Sets the current cell to be the cell at position (row, column).
*/
void PSetConfigurationTable::setCell(int row, int column)
{
setCurrentCell(row, column);
}
void PSetConfigurationTable::setTorqueValue(QString torqueValue)
{
QTableWidgetItem *torqueItem = item( 0, 1 );
torqueItem->setText(torqueValue);
}
void PSetConfigurationTable::setBatchSizeValue(QString batchSizeValue)
{
QTableWidgetItem *batchSizeItem = item( 2, 1 );
batchSizeItem->setText(batchSizeValue);
}
//! getTorqueValue
/*!
* item(row, column) returns the item for the given row and column.
* The items torque value is returned.
*/
QString PSetConfigurationTable::getTorqueValue()
{
QTableWidgetItem *torqueItem = item( 0, 1 );
return torqueItem->text();
}
//! getBatchSizeValue
/*!
* item(row, column) returns the item for the given row and column.
* The items batch size value is returned.
*/
QString PSetConfigurationTable::getBatchSizeValue()
{
QTableWidgetItem *batchSizeItem = item( 2, 1 );
return batchSizeItem->text();
}
To copy to clipboard, switch view to plain text mode
Bookmarks