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