Traing mode changed from parallel port to usb solution
This commit is contained in:
125
timemodel.cpp
Normal file
125
timemodel.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "timemodel.h"
|
||||
#include<qvector.h>
|
||||
#include <iostream>
|
||||
#include <qcolor.h>
|
||||
|
||||
|
||||
TimeModel::TimeModel(QVector<QVector<int>> timeData, QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
this->timeData = timeData;
|
||||
}
|
||||
|
||||
QVariant TimeModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (section) {
|
||||
case 0:
|
||||
return QString("Sektor 1");
|
||||
|
||||
case 1:
|
||||
return QString("Sektor 2");
|
||||
|
||||
case 2:
|
||||
return QString("Sektor 3");
|
||||
|
||||
case 3:
|
||||
return QString("Runde");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int TimeModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
|
||||
return this->timeData.size();
|
||||
}
|
||||
|
||||
int TimeModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
if (parent.isValid())
|
||||
return 0;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QColor TimeModel::getColor(const QVector<QVector<int>> data, const int col, const int row) const{
|
||||
if(row == 0){
|
||||
return QColor(Qt::gray);
|
||||
}
|
||||
else if(data.size() > row){ // check for enough rows
|
||||
if(data.at(row).size() > col){ // check for enough cols
|
||||
QVector<int> compare;
|
||||
for(int i = 0; i <= row; i++){
|
||||
compare.append(data.at(i).at(col));
|
||||
}
|
||||
if(data.at(row).at(col) == getMin(compare)){
|
||||
return QColor(Qt::green);
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::gray);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return QColor(Qt::white);
|
||||
}
|
||||
}
|
||||
|
||||
int TimeModel::getMin(const QVector<int> x) const{
|
||||
int min;
|
||||
if(x.size() > 0){
|
||||
min = x.at(0);
|
||||
}
|
||||
for(int i = 1; i < x.size(); i++){
|
||||
if(x.at(i) < min){
|
||||
min = x.at(i);
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
QVariant TimeModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
//std::cout << "data called" << std::endl;
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if(role == Qt::DisplayRole){
|
||||
if(timeData.at(index.row()).size() > index.column()){
|
||||
return QString::number((double)timeData.at(index.row()).at(index.column())/1000);
|
||||
}
|
||||
else{
|
||||
return QString("∞");
|
||||
}
|
||||
}
|
||||
else if(role == Qt::BackgroundColorRole){
|
||||
return getColor(timeData, index.column(), index.row());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool TimeModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
std::cout << "insert triggert" << std::endl;
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
bool TimeModel::insertColumns(int column, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertColumns(parent, column, column + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertColumns();
|
||||
}
|
||||
Reference in New Issue
Block a user