mainWindows spinBox decleration

This commit is contained in:
moerp 2021-05-24 23:25:17 +02:00
parent ddf2f0b513
commit fc4875dd27
6 changed files with 112 additions and 6 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.0, 2021-05-22T22:51:04. -->
<!-- Written by QtCreator 4.15.0, 2021-05-24T12:12:52. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -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);
}

View File

@ -2,6 +2,11 @@
#define MAINWINDOW_H
#include <QMainWindow>
#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

View File

@ -6,15 +6,77 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>390</width>
<height>562</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>371</width>
<height>71</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labBase">
<property name="text">
<string>Base:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBase"/>
</item>
<item>
<widget class="QLabel" name="labExp">
<property name="text">
<string>Exponent:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinExp"/>
</item>
<item>
<widget class="QLabel" name="labMod">
<property name="text">
<string>Modulus:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMod"/>
</item>
</layout>
</widget>
<widget class="QTableView" name="resultTable">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>371</width>
<height>421</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>

View File

@ -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<int> colBin;

View File

@ -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<vector <int>> sqmMatrix;
};