now drawing model
This commit is contained in:
@ -13,6 +13,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
|
|
||||||
resultTable = ui->resultTable;
|
resultTable = ui->resultTable;
|
||||||
|
resultTableModel = new SQMTableModel;
|
||||||
|
// resultTable->setModel(resultTableModel);
|
||||||
|
// resultTable->show();
|
||||||
|
|
||||||
connect(spinBase, SIGNAL(valueChanged(int)), this, SLOT(SetModel()));
|
connect(spinBase, SIGNAL(valueChanged(int)), this, SLOT(SetModel()));
|
||||||
connect(spinExp, 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 exp = spinExp->value();
|
||||||
int mod = spinMod->value();
|
int mod = spinMod->value();
|
||||||
|
|
||||||
SQMTableModel resultTableModel;
|
|
||||||
|
|
||||||
resultTableModel.SetStartValues(base, exp, mod);
|
resultTableModel->SetStartValues(base, exp, mod);
|
||||||
resultTable->setModel(&resultTableModel);
|
resultTable->setModel(resultTableModel);
|
||||||
//resultTable->show();
|
//resultTable->show();
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ private:
|
|||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
QSpinBox *spinBase, *spinExp, *spinMod;
|
QSpinBox *spinBase, *spinExp, *spinMod;
|
||||||
QTableView *resultTable;
|
QTableView *resultTable;
|
||||||
//SQMTableModel *resultTableModel;
|
SQMTableModel *resultTableModel;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -65,6 +65,9 @@
|
|||||||
<height>421</height>
|
<height>421</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<attribute name="verticalHeaderStretchLastSection">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
@ -16,15 +16,17 @@ int SQMTableModel::columnCount(const QModelIndex & /*parent*/) const {
|
|||||||
|
|
||||||
|
|
||||||
QVariant SQMTableModel::data(const QModelIndex &index, int role) 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) {
|
return sqmMatrix.at(col).at(row);
|
||||||
// int row = index.row();
|
}
|
||||||
// int col = index.column();
|
}
|
||||||
|
catch (...) {
|
||||||
// return sqmMatrix.at(col).at(row);
|
return QVariant();
|
||||||
return "test";
|
|
||||||
}
|
}
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SQMTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
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;
|
base = pBase;
|
||||||
exp = pExp;
|
exp = pExp;
|
||||||
mod = pMod;
|
mod = pMod;
|
||||||
|
|
||||||
|
CalculateSqmMatrix(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,12 +93,24 @@ void SQMTableModel::CalculateSqmMatrix(int startRow) {
|
|||||||
string bin = IntToBinary(exp);
|
string bin = IntToBinary(exp);
|
||||||
binLen = bin.length();
|
binLen = bin.length();
|
||||||
|
|
||||||
|
// Fill vector with 0
|
||||||
|
vector<int> colSqn, colMul;
|
||||||
|
for (int i = 0; i <= binLen; i++) {
|
||||||
|
colSqn.push_back(0);
|
||||||
|
colMul.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize bin column
|
// Initialize bin column
|
||||||
vector<int> colBin;
|
vector<int> colBin;
|
||||||
for (int i = 0; i < binLen; i++) {
|
for (int i = 0; i <= binLen; i++) {
|
||||||
colBin.push_back(bin[i] - '0');
|
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++) {
|
for (int i = startRow; i < binLen; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
Reference in New Issue
Block a user