task done
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
#include "sqmtablemodel.h"
|
#include "sqmtablemodel.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
|
||||||
SQMTableModel::SQMTableModel(QObject *parent)
|
SQMTableModel::SQMTableModel(QObject *parent)
|
||||||
@ -17,19 +18,43 @@ int SQMTableModel::columnCount(const QModelIndex & /*parent*/) const {
|
|||||||
|
|
||||||
|
|
||||||
QVariant SQMTableModel::data(const QModelIndex &index, int role) const {
|
QVariant SQMTableModel::data(const QModelIndex &index, int role) const {
|
||||||
if (role == Qt::DisplayRole) {
|
int row = index.row();
|
||||||
int row = index.row();
|
int col = index.column();
|
||||||
int col = index.column();
|
QVariant result;
|
||||||
QString result;
|
switch (role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = QString::number(sqmMatrix.at(col).at(row));
|
result = QString::number(sqmMatrix.at(col).at(row));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
result = "x";
|
result = "x";
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
break;
|
||||||
|
case Qt::ForegroundRole:
|
||||||
|
if (changedHere.isValid()) {
|
||||||
|
if (row >= changedHere.row() && col >= changedHere.column()) {
|
||||||
|
result = QColor(Qt::red);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return QVariant();
|
|
||||||
|
// if (role == Qt::DisplayRole) {
|
||||||
|
// int row = index.row();
|
||||||
|
// int col = index.column();
|
||||||
|
// QString result;
|
||||||
|
// try {
|
||||||
|
// result = QString::number(sqmMatrix.at(col).at(row));
|
||||||
|
// } catch (...) {
|
||||||
|
// result = "x";
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SQMTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
QVariant SQMTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
@ -58,7 +83,7 @@ bool SQMTableModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||||||
|
|
||||||
// call calculateSqmMatrix
|
// call calculateSqmMatrix
|
||||||
sqmMatrix.at(col).at(row) = value.toInt();
|
sqmMatrix.at(col).at(row) = value.toInt();
|
||||||
|
changedHere = index;
|
||||||
|
|
||||||
UpdateSqmMatrix(index);
|
UpdateSqmMatrix(index);
|
||||||
return true;
|
return true;
|
||||||
@ -78,6 +103,7 @@ void SQMTableModel::SetStartValues(int pBase, int pExp, int pMod) {
|
|||||||
exp = pExp;
|
exp = pExp;
|
||||||
mod = pMod;
|
mod = pMod;
|
||||||
|
|
||||||
|
//changedHere.model()->index(-1, -1, QModelIndex());
|
||||||
CalculateSqmMatrix();
|
CalculateSqmMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,9 +175,9 @@ void SQMTableModel::UpdateSqmMatrix(QModelIndex startIndex) {
|
|||||||
for (int i = start_row; i < binLen; i++) {
|
for (int i = start_row; i < binLen; i++) {
|
||||||
if (start_col != 1) {
|
if (start_col != 1) {
|
||||||
sqmMatrix.at(1).at(i) = (sqmMatrix.at(2).at(i - 1) * sqmMatrix.at(2).at(i - 1)) % mod;
|
sqmMatrix.at(1).at(i) = (sqmMatrix.at(2).at(i - 1) * sqmMatrix.at(2).at(i - 1)) % mod;
|
||||||
start_col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
start_col = 0;
|
||||||
if (sqmMatrix.at(0).at(i) == 0) {
|
if (sqmMatrix.at(0).at(i) == 0) {
|
||||||
sqmMatrix.at(2).at(i) = sqmMatrix.at(1).at(i);
|
sqmMatrix.at(2).at(i) = sqmMatrix.at(1).at(i);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ private:
|
|||||||
int exp;
|
int exp;
|
||||||
int mod;
|
int mod;
|
||||||
int binLen = 0;
|
int binLen = 0;
|
||||||
|
QModelIndex changedHere;
|
||||||
|
|
||||||
vector<vector <int>> sqmMatrix;
|
vector<vector <int>> sqmMatrix;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user