fullfilled requirements
This commit is contained in:
parent
a76a04f15c
commit
1484cfa7b6
@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle("Square Multiply Calculator");
|
||||
|
||||
spinBase = ui->spinBase;
|
||||
spinExp = ui->spinExp;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>333</width>
|
||||
<height>564</height>
|
||||
<height>416</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -20,34 +20,42 @@
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>311</width>
|
||||
<height>71</height>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labBase">
|
||||
<property name="text">
|
||||
<string>Base:</string>
|
||||
<string>base:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBase"/>
|
||||
<widget class="QSpinBox" name="spinBase">
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labExp">
|
||||
<property name="text">
|
||||
<string>Exponent:</string>
|
||||
<string>exponent:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinExp"/>
|
||||
<widget class="QSpinBox" name="spinExp">
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labMod">
|
||||
<property name="text">
|
||||
<string>Modulus:</string>
|
||||
<string>modulos:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -56,6 +64,9 @@
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>9999</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -64,11 +75,14 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>90</y>
|
||||
<y>50</y>
|
||||
<width>311</width>
|
||||
<height>421</height>
|
||||
<height>321</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "sqmtablemodel.h"
|
||||
#include <algorithm>
|
||||
#include <QColor>
|
||||
#include <QRegularExpression>
|
||||
|
||||
|
||||
SQMTableModel::SQMTableModel(QObject *parent)
|
||||
@ -32,28 +33,16 @@ QVariant SQMTableModel::data(const QModelIndex &index, int role) const {
|
||||
|
||||
break;
|
||||
case Qt::ForegroundRole:
|
||||
if (changedHere.isValid()) {
|
||||
|
||||
|
||||
if (changedHere.isValid() && highlightChanged) {
|
||||
if ((row > changedHere.row() || (col >= changedHere.column() && row == changedHere.row())) && (col != 0 || changedHere.column() == 0)) {
|
||||
result = QColor(Qt::red);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Qt::TextAlignmentRole:
|
||||
result = Qt::AlignRight;
|
||||
break;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
}
|
||||
@ -81,14 +70,14 @@ bool SQMTableModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
if (col == 0 && value.toInt() != 0 && value.toInt() != 1) {
|
||||
if (col == 0 && value.toInt() != 0 && value.toInt() != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// call calculateSqmMatrix
|
||||
sqmMatrix.at(col).at(row) = value.toInt();
|
||||
changedHere = index;
|
||||
|
||||
highlightChanged = true;
|
||||
UpdateSqmMatrix(index);
|
||||
return true;
|
||||
}
|
||||
@ -106,7 +95,7 @@ void SQMTableModel::SetStartValues(int pBase, int pExp, int pMod) {
|
||||
base = pBase;
|
||||
exp = pExp;
|
||||
mod = pMod;
|
||||
|
||||
highlightChanged = false;
|
||||
//changedHere.model()->index(-1, -1, QModelIndex());
|
||||
CalculateSqmMatrix();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ private:
|
||||
int exp;
|
||||
int mod;
|
||||
int binLen = 0;
|
||||
bool highlightChanged;
|
||||
QModelIndex changedHere;
|
||||
|
||||
vector<vector <int>> sqmMatrix;
|
||||
|
Loading…
x
Reference in New Issue
Block a user