diff --git a/sources/SQM-GUI-ng.pro.user b/sources/SQM-GUI-ng.pro.user index dfc8e03..96473c8 100644 --- a/sources/SQM-GUI-ng.pro.user +++ b/sources/SQM-GUI-ng.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 41a26bd..1df6570 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -11,5 +11,23 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { delete ui; + spinBase = ui->spinBase; + spinExp = ui->spinExp; + spinMod = ui->spinMod; + + connect(spinBase, SIGNAL(valueChanged(int)), this, SLOT(SetModel())); + connect(spinExp, SIGNAL(valueChanged(int)), this, SLOT(SetModel())); + connect(spinMod, SIGNAL(valueChanged(int)), this, SLOT(SetModel())); + + resultTable = ui->resultTable; + } +void MainWindow::SetModel() { + int base = spinBase->value(); + int exp = spinExp->value(); + int mod = spinMod->value(); + + resultTableModel->SetStartValues(base, exp, mod); + resultTable->setModel(resultTableModel); +} diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 4643e32..92f2e67 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -2,6 +2,11 @@ #define MAINWINDOW_H #include +#include "sqmtablemodel.h" + +class SQMTableModel; +class QSpinBox; +class QTableView; QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -15,7 +20,14 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); +private slots: + void SetModel(); + private: Ui::MainWindow *ui; + QSpinBox *spinBase, *spinExp, *spinMod; + QTableView *resultTable; + SQMTableModel *resultTableModel; + }; #endif // MAINWINDOW_H diff --git a/sources/mainwindow.ui b/sources/mainwindow.ui index b232854..969ba6f 100644 --- a/sources/mainwindow.ui +++ b/sources/mainwindow.ui @@ -6,15 +6,77 @@ 0 0 - 800 - 600 + 390 + 562 MainWindow - - + + + + + 10 + 10 + 371 + 71 + + + + + + + Base: + + + + + + + + + + Exponent: + + + + + + + + + + Modulus: + + + + + + + + + + + + 10 + 90 + 371 + 421 + + + + + + + + 0 + 0 + 390 + 20 + + + diff --git a/sources/sqmtablemodel.cpp b/sources/sqmtablemodel.cpp index f05ad01..6a0ca9e 100644 --- a/sources/sqmtablemodel.cpp +++ b/sources/sqmtablemodel.cpp @@ -5,6 +5,16 @@ SQMTableModel::SQMTableModel(QObject *parent) : QAbstractTableModel(parent) { } + +int SQMTableModel::rowCount(const QModelIndex & parent) const { + return binLen; +} + +int SQMTableModel::columnCount(const QModelIndex & parent) const { + return 3; +} + + QVariant SQMTableModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { @@ -16,6 +26,7 @@ QVariant SQMTableModel::data(const QModelIndex &index, int role) const { return QVariant(); } + void SQMTableModel::SetStartValues(int pBase, int pExp, int pMod) { base = pBase; exp = pExp; @@ -37,7 +48,7 @@ std::string SQMTableModel::IntToBinary(int n) { void SQMTableModel::CalculateSqmMatrix(int startRow) { string bin = IntToBinary(exp); - int binLen = bin.length(); + binLen = bin.length(); // Initialize bin column vector colBin; diff --git a/sources/sqmtablemodel.h b/sources/sqmtablemodel.h index 57e8b3d..65354c2 100644 --- a/sources/sqmtablemodel.h +++ b/sources/sqmtablemodel.h @@ -9,6 +9,8 @@ class SQMTableModel : public QAbstractTableModel { Q_OBJECT public: SQMTableModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; void SetStartValues(int pBase, int pExp, int pMod); @@ -20,6 +22,7 @@ private: int base; int exp; int mod; + int binLen; vector> sqmMatrix; };