void MtxLP::cleanTmpRows(int n){ int size = tmp_rows.size(); if (n < 0) n = size; else if (n > size) throw runtime_error("trying to delete too many temp. rows!"); for (int i = 0; i < n; i++){ delRow(tmp_rows.top()); tmp_rows.pop(); } }
relTable::relTable(const QString &tableName, int player_id, int hide, QWidget *parent) : QWidget(parent) { model = new QSqlRelationalTableModel; model -> setTable(tableName); model -> setEditStrategy(QSqlTableModel::OnFieldChange); model -> select(); view = new QTableView; view -> setModel(model); view -> setSelectionBehavior(QAbstractItemView::SelectRows); for(int i=0;i<hide;i++) view -> hideColumn(i); QPushButton *addrowButton = new QPushButton(tr("Add")); QPushButton *delrowButton = new QPushButton(tr("Delete")); QHBoxLayout *buttonBox = new QHBoxLayout; buttonBox -> addWidget(addrowButton); buttonBox -> addWidget(delrowButton); connect(addrowButton, SIGNAL(clicked()), this, SLOT(addRow())); connect(delrowButton, SIGNAL(clicked()), this, SLOT(delRow())); QLabel *totalLabel = new QLabel; totalLabel -> setText("Totale: "); QLabel *totalVal = new QLabel; totalVal -> setText("valore"); QHBoxLayout *totLayout = new QHBoxLayout; totLayout -> addWidget(totalLabel); totLayout -> addWidget(totalVal); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout -> addWidget(view); mainLayout -> addLayout(totLayout); mainLayout -> addLayout(buttonBox); setLayout(mainLayout); }
TableEditor::TableEditor(const QString &tableName, QWidget *parent) : QDialog(parent) { model = new QSqlTableModel(this); model->setTable(tableName); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); view = new QTableView; view->setModel(model); view->setSelectionBehavior( QAbstractItemView::SelectRows ); // view->hideColumn(1); quitButton = new QPushButton(tr("Quit")); submitButton = new QPushButton(tr("Submit")); submitButton->setDefault(true); addrowButton = new QPushButton(tr("Add Record")); delrowButton = new QPushButton(tr("Remove Record")); revertButton = new QPushButton(tr("&Revert")); buttonBox = new QDialogButtonBox(Qt::Vertical); buttonBox->addButton(addrowButton, QDialogButtonBox::ActionRole); buttonBox->addButton(delrowButton, QDialogButtonBox::ActionRole); buttonBox->addButton(revertButton, QDialogButtonBox::ActionRole); buttonBox->addButton(submitButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); connect(submitButton, SIGNAL(clicked()), this, SLOT(submit())); connect(addrowButton, SIGNAL(clicked()), this, SLOT(addRow())); connect(delrowButton, SIGNAL(clicked()), this, SLOT(delRow())); connect(revertButton, SIGNAL(clicked()), model, SLOT(revertAll())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(view); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("Table view: ") + tableName ); }