now drawing model
This commit is contained in:
parent
0bded9e4a2
commit
d5b969d1e7
@ -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();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ private:
|
||||
Ui::MainWindow *ui;
|
||||
QSpinBox *spinBase, *spinExp, *spinMod;
|
||||
QTableView *resultTable;
|
||||
//SQMTableModel *resultTableModel;
|
||||
SQMTableModel *resultTableModel;
|
||||
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -65,6 +65,9 @@
|
||||
<height>421</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="verticalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
<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 {
|
||||
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<int> colSqn, colMul;
|
||||
for (int i = 0; i <= binLen; i++) {
|
||||
colSqn.push_back(0);
|
||||
colMul.push_back(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Initialize bin column
|
||||
vector<int> 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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user