From d5b969d1e79e4edfeb9c11440e81ad65c957719d Mon Sep 17 00:00:00 2001 From: moerp Date: Fri, 28 May 2021 18:20:00 +0200 Subject: [PATCH] now drawing model --- sources/mainwindow.cpp | 8 +++++--- sources/mainwindow.h | 2 +- sources/mainwindow.ui | 3 +++ sources/sqmtablemodel.cpp | 34 +++++++++++++++++++++++++--------- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 2e62a5f..30ff54f 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -13,6 +13,9 @@ MainWindow::MainWindow(QWidget *parent) resultTable = ui->resultTable; + resultTableModel = new SQMTableModel; +// resultTable->setModel(resultTableModel); +// resultTable->show(); connect(spinBase, SIGNAL(valueChanged(int)), this, SLOT(SetModel())); connect(spinExp, SIGNAL(valueChanged(int)), this, SLOT(SetModel())); @@ -31,9 +34,8 @@ void MainWindow::SetModel() { int exp = spinExp->value(); int mod = spinMod->value(); - SQMTableModel resultTableModel; - resultTableModel.SetStartValues(base, exp, mod); - resultTable->setModel(&resultTableModel); + resultTableModel->SetStartValues(base, exp, mod); + resultTable->setModel(resultTableModel); //resultTable->show(); } diff --git a/sources/mainwindow.h b/sources/mainwindow.h index f8a6f65..92f2e67 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -27,7 +27,7 @@ private: Ui::MainWindow *ui; QSpinBox *spinBase, *spinExp, *spinMod; QTableView *resultTable; - //SQMTableModel *resultTableModel; + SQMTableModel *resultTableModel; }; #endif // MAINWINDOW_H diff --git a/sources/mainwindow.ui b/sources/mainwindow.ui index 969ba6f..e44f1a5 100644 --- a/sources/mainwindow.ui +++ b/sources/mainwindow.ui @@ -65,6 +65,9 @@ 421 + + false + diff --git a/sources/sqmtablemodel.cpp b/sources/sqmtablemodel.cpp index c69625d..09b1942 100644 --- a/sources/sqmtablemodel.cpp +++ b/sources/sqmtablemodel.cpp @@ -16,15 +16,17 @@ int SQMTableModel::columnCount(const QModelIndex & /*parent*/) const { QVariant SQMTableModel::data(const QModelIndex &index, int role) const { + try { + if (role == Qt::DisplayRole) { + int row = index.row(); + int col = index.column(); - if (role == Qt::DisplayRole) { -// int row = index.row(); -// int col = index.column(); - -// return sqmMatrix.at(col).at(row); - return "test"; + return sqmMatrix.at(col).at(row); + } + } + catch (...) { + return QVariant(); } - return QVariant(); } QVariant SQMTableModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -70,6 +72,8 @@ void SQMTableModel::SetStartValues(int pBase, int pExp, int pMod) { base = pBase; exp = pExp; mod = pMod; + + CalculateSqmMatrix(0); } @@ -89,12 +93,24 @@ void SQMTableModel::CalculateSqmMatrix(int startRow) { string bin = IntToBinary(exp); binLen = bin.length(); + // Fill vector with 0 + vector colSqn, colMul; + for (int i = 0; i <= binLen; i++) { + colSqn.push_back(0); + colMul.push_back(0); + } + + + // Initialize bin column vector colBin; - for (int i = 0; i < binLen; i++) { + for (int i = 0; i <= binLen; i++) { colBin.push_back(bin[i] - '0'); } - sqmMatrix.at(0) = colBin; + sqmMatrix.push_back(colBin); + sqmMatrix.push_back(colSqn); + sqmMatrix.push_back(colMul); + for (int i = startRow; i < binLen; i++) { if (i == 0) {