SqlItemView::SqlItemView(QWidget * parent) : QWidget(parent), m_row(0), m_changing(false), m_model(0) { setupUi(this); connect(firstButton, SIGNAL(clicked()), this, SLOT(toFirst())); connect(previousButton, SIGNAL(clicked()), this, SLOT(toPrevious())); connect(nextButton, SIGNAL(clicked()), this, SLOT(toNext())); connect(lastButton, SIGNAL(clicked()), this, SLOT(toLast())); connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(aApp_focusChanged(QWidget*,QWidget*))); }
docItem::docItem(QList<int> _list, int _curr, int _doc, QWidget *parent):QDialog(parent){ ui.setupUi(this); list = _list; curr = _curr; doc = _doc; QSqlQuery _v(QString("select docs.vid from docs where docs.id = \'%1\'").arg(doc)); _v.next(); vid = _v.value(0).toInt(); ui.spinBox_id_book->hide(); ui.tableWidget_res->setColumnHidden(0, true); ui.tableWidget_res->setColumnHidden(7, true); ui.tableWidget_res->setColumnHidden(8, true); if (vid == 1){ ui.tableWidget_res->setColumnHidden(6, true); ui.radioButton_identifier->hide(); } else if (vid == 2){ ui.lineEdit_place->hide(); ui.label_3->hide(); ui.lineEdit_identifier->setReadOnly(true); } openItem(); readSetting(); connect(ui.pushButton_close, SIGNAL(clicked()), this, SLOT(close())); connect(ui.lineEdit_search, SIGNAL(textEdited(QString)), this, SLOT(searchBook(QString))); connect(ui.tableWidget_res, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(selectBook())); connect(ui.pushButton_save, SIGNAL(clicked()), this, SLOT(saveItem())); connect(ui.pushButton_del, SIGNAL(clicked()), this, SLOT(deleteItem())); connect(ui.pushButton_toFirst, SIGNAL(clicked()), this, SLOT(toFirst())); connect(ui.pushButton_toLast, SIGNAL(clicked()), this, SLOT(toLast())); connect(ui.pushButton_toNext, SIGNAL(clicked()), this, SLOT(toNext())); connect(ui.pushButton_toPrev, SIGNAL(clicked()), this, SLOT(toPrev())); }
EmployeeForm::EmployeeForm(int id, QWidget *parent) : QDialog(parent) { nameEdit = new QLineEdit; nameLabel = new QLabel(tr("Na&me:")); nameLabel->setBuddy(nameEdit); departmentComboBox = new QComboBox; departmentLabel = new QLabel(tr("Depar&tment:")); departmentLabel->setBuddy(departmentComboBox); extensionLineEdit = new QLineEdit; extensionLineEdit->setValidator( new QIntValidator(0, 99999, this)); extensionLabel = new QLabel(tr("E&xtension:")); extensionLabel->setBuddy(extensionLineEdit); emailEdit = new QLineEdit; emailLabel = new QLabel(tr("&Email:")); emailLabel->setBuddy(emailEdit); startDateEdit = new QDateEdit; startDateEdit->setCalendarPopup(true); QDate today = QDate::currentDate(); startDateEdit->setDateRange( today.addDays(-90), today.addDays(90)); startDateLabel = new QLabel(tr("&Start Date:")); startDateLabel->setBuddy(startDateEdit); firstButton = new QPushButton(tr("<< &First")); previousButton = new QPushButton(tr("< &Previous")); nextButton = new QPushButton(tr("&Next >")); lastButton = new QPushButton(tr("&Last >>")); addButton = new QPushButton(tr("&Add")); deleteButton = new QPushButton(tr("&Delete")); closeButton = new QPushButton(tr("&Close")); buttonBox = new QDialogButtonBox; buttonBox->addButton(addButton, QDialogButtonBox::ActionRole); buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole); buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole); tableModel = new QSqlRelationalTableModel(this); tableModel->setTable("employee"); tableModel->setRelation(Employee_DepartmentId, QSqlRelation("department", "id", "name")); tableModel->setSort(Employee_Name, Qt::AscendingOrder); tableModel->select(); QSqlTableModel *relationModel = tableModel->relationModel(Employee_DepartmentId); departmentComboBox->setModel(relationModel); departmentComboBox->setModelColumn( relationModel->fieldIndex("name")); mapper = new QDataWidgetMapper(this); mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit); mapper->setModel(tableModel); mapper->setItemDelegate(new QSqlRelationalDelegate(this)); mapper->addMapping(nameEdit, Employee_Name); mapper->addMapping(departmentComboBox, Employee_DepartmentId); mapper->addMapping(extensionLineEdit, Employee_Extension); mapper->addMapping(emailEdit, Employee_Email); mapper->addMapping(startDateEdit, Employee_StartDate); if (id != -1) { for (int row = 0; row < tableModel->rowCount(); ++row) { QSqlRecord record = tableModel->record(row); if (record.value(Employee_Id).toInt() == id) { mapper->setCurrentIndex(row); break; } } } else { mapper->toFirst(); } connect(firstButton, SIGNAL(clicked()), mapper, SLOT(toFirst())); connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); connect(lastButton, SIGNAL(clicked()), mapper, SLOT(toLast())); connect(addButton, SIGNAL(clicked()), this, SLOT(addEmployee())); connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteEmployee())); connect(closeButton, SIGNAL(clicked()), this, SLOT(accept())); QHBoxLayout *topButtonLayout = new QHBoxLayout; topButtonLayout->setContentsMargins(20, 0, 20, 5); topButtonLayout->addStretch(); topButtonLayout->addWidget(firstButton); topButtonLayout->addWidget(previousButton); topButtonLayout->addWidget(nextButton); topButtonLayout->addWidget(lastButton); topButtonLayout->addStretch(); QGridLayout *mainLayout = new QGridLayout; mainLayout->addLayout(topButtonLayout, 0, 0, 1, 3); mainLayout->addWidget(nameLabel, 1, 0); mainLayout->addWidget(nameEdit, 1, 1, 1, 2); mainLayout->addWidget(departmentLabel, 2, 0); mainLayout->addWidget(departmentComboBox, 2, 1, 1, 2); mainLayout->addWidget(extensionLabel, 3, 0); mainLayout->addWidget(extensionLineEdit, 3, 1); mainLayout->addWidget(emailLabel, 4, 0); mainLayout->addWidget(emailEdit, 4, 1, 1, 2); mainLayout->addWidget(startDateLabel, 5, 0); mainLayout->addWidget(startDateEdit, 5, 1); mainLayout->addWidget(buttonBox, 7, 0, 1, 3); mainLayout->setRowMinimumHeight(6, 10); mainLayout->setRowStretch(6, 1); mainLayout->setColumnStretch(2, 1); setLayout(mainLayout); if (id == -1) { nextButton->setFocus(); } else { nameEdit->setFocus(); } setWindowTitle(tr("Edit Employees")); }
// Another constructor for string list iterator. strlistiterator::strlistiterator (strlist * s) { _strlist = s; toLast (); toFirst (); }
// Constructor for string list iterator. strlistiterator::strlistiterator (strlist & s) { _strlist = &s; toLast (); toFirst (); }
valuelistiterator<type_t>::valuelistiterator (valuelist<type_t> & v) { _valuelist = &v; toLast (); toFirst (); }
PaymentForm::PaymentForm(QSqlRelationalTableModel *modelCome, int id, QWidget *parent) : QDialog(parent), ui(new Ui::PaymentDialog) { ui->setupUi(this); model = modelCome; QSqlTableModel *relModel = model->relationModel(Payment_Customer_id); ui->customerComboBox->setModel(relModel); ui->customerComboBox->setModelColumn(relModel->fieldIndex("surname")); relModel = model->relationModel(Payment_Work_id - 1); ui->workComboBox->setModel(relModel); ui->workComboBox->setModelColumn(relModel->fieldIndex("name")); ui->priceEdit->setValidator(new QIntValidator(0, 999999, this)); mapper = new QDataWidgetMapper(this); mapper->setModel(model); mapper->addMapping(ui->customerComboBox, Payment_Customer_id); mapper->addMapping(ui->workComboBox, Payment_Work_id - 1); mapper->addMapping(ui->dateEdit, Payment_Date - 1); mapper->addMapping(ui->priceEdit, Payment_Price - 1); mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit); mapper->setItemDelegate(new QSqlRelationalDelegate(this)); if (id != -1) { for (int row = 0; row < model->rowCount(); ++row) { QSqlRecord record = model->record(row); if (record.value(Payment_Payment_id).toInt() == id) { mapper->setCurrentIndex(row); break; } } } else { mapper->toFirst(); } connect(ui->firstButton, SIGNAL(clicked()), mapper, SLOT(toFirst())); connect(ui->previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); connect(ui->nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); connect(ui->lastButton, SIGNAL(clicked()), mapper, SLOT(toLast())); connect(ui->addButton, SIGNAL(clicked()), this, SLOT(addRecord())); connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteRecord())); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(accept())); connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int))); connect(ui->workComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFields(int))); if (id == -1) { ui->nextButton->setFocus(); } else { ui->customerComboBox->setFocus(); } int row = mapper->currentIndex(); updateButtons(row); if (row == -1) { addRecord(); } }
ptrlistiterator<type_t>::ptrlistiterator (ptrlist<type_t> & p) { _ptrlist = &p; toLast (); toFirst (); }
MovimentoEditDialog::MovimentoEditDialog(QSqlRelationalTableModel* model, ColumnIndexes & colInd, int curRow, bool canSubmit, QWidget *parent) : QDialog(parent) , ui(new Ui::MovimentoEditDialog) , m_movModel(model) , m_insert(curRow<0) // se linha < 0, então é inserção, do contrário é edição , m_canSubmit(canSubmit) , m_colInd(colInd) { ui->setupUi(this); if ( m_insert ) ui->movimentoNavGroup->hide(); // se vai inserir, não haverá havegação. // seta as comboBox para que sejam alimentadas pelo relacionamento correspondente // exibindo a coluna "nome" ao inves de "id": // nomes de clientes na respectiva combo: QSqlTableModel *cliRelationModel = m_movModel->relationModel(m_colInd.movClienteId); ui->clienteCombo->setModel(cliRelationModel); ui->clienteCombo->setModelColumn(cliRelationModel->fieldIndex("name")); // como o relation model só duas colunas (chave e valor), poderia: //ui->clienteCombo->setModelColumn(1); // índice da coluna valor ui->clienteCombo->model()->sort(cliRelationModel->fieldIndex("name"), Qt::AscendingOrder); // tipos de movimento na respectiva combo: QSqlTableModel *tipoRelationModel = m_movModel->relationModel(m_colInd.movTipoId); ui->tipoCombo->setModel(tipoRelationModel); ui->tipoCombo->setModelColumn(tipoRelationModel->fieldIndex("name")); ui->tipoCombo->model()->sort(tipoRelationModel->fieldIndex("name"), Qt::AscendingOrder); // * ^^ Nos 2 "relationModel" acima, temos sempre duas colunas: "chave" e "valor associado". // cria um mapeador que relacionará widgets "sem-model" com // as colunas respectivas do model: m_movMapper = new QDataWidgetMapper(this); // "submitPolicy": "auto" ou "manual"; se "auto" irá completar alterações se a linha selecionada for alterada m_movMapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); // "manual" -> teremos que chamar "submit" no momento apropriado. // define o "model" a ser usado pelo "mapper": m_movMapper->setModel(m_movModel); // define o delegate que permite exibir colunas relacionadas em comboBox's m_movMapper->setItemDelegate(new QSqlRelationalDelegate(this)); // mapeia cada widget necessário para a coluna respectiva no model: m_movMapper->addMapping(ui->clienteCombo, m_colInd.movClienteId); m_movMapper->addMapping(ui->tipoCombo, m_colInd.movTipoId); m_movMapper->addMapping(ui->movDate, m_colInd.movDate); m_movMapper->addMapping(ui->descrEdit, m_colInd.movDescription); // conecta os botões de navegação diretamente aos slots do "mapper" // (neste caso, não é necessário criar novos slots para isso, exceto se quisermos fazer algo diferenciado) if ( !m_insert ) { connect(ui->movimentoNavFirstBtn, SIGNAL(clicked()), m_movMapper, SLOT(toFirst())); connect(ui->movimentoNavPrevBtn, SIGNAL(clicked()), m_movMapper, SLOT(toPrevious())); connect(ui->movimentoNavNextBtn, SIGNAL(clicked()), m_movMapper, SLOT(toNext())); connect(ui->movimentoNavLastBtn, SIGNAL(clicked()), m_movMapper, SLOT(toLast())); } // se for inserir, deve criar nova linha no model if ( m_insert ) // INSERIR { // insere uma nova linha no model (caso o insert seja cancelado, deverá ser removida): curRow = m_movModel->rowCount(); // altera curRow para o total de linhas // rowCount -> total de linhas -> uma nova linha no final: m_movModel->insertRow(curRow); // em inclusão, seta widgets de data (para forçar o default): ui->movDate->setDate( QDate::currentDate() ); setWindowTitle("INCLUIR novo movimento - "); // título do diálogo } else // ALTERAR setWindowTitle("ALTERAR um movimento - "); // título do diálogo QSqlDatabase db = m_movModel->database(); setWindowTitle( windowTitle() + db.driverName()); m_movMapper->setCurrentIndex(curRow); // seta a "row" do mapper // desabilta a opção do menu de sistema "fechar" ("X"); // desse modo só poderá fechar o diálogo com os botões "OK" e "CANCELAR" // e não precisaremos redefinir a virtual "closeEvent" para finalzação Qt::WindowFlags flags = windowFlags(); flags |= Qt::CustomizeWindowHint; // acrescenta: flags customizados flags &= ~Qt::WindowCloseButtonHint; // desabilita: closeButton setWindowFlags(flags); }
/** * 隧道管理界面类实现 * 继承自QWidget * @author fanxiang * @version 1.0.0 * @date 2013-08-18 */ ManageTunnelWidget::ManageTunnelWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ManageTunnelWidget) { ui->setupUi(this); mapper = new QDataWidgetMapper(this); linesModel = NULL; tunnelsModel = NULL; curvesModel = NULL; loadLinesData(); loadTunnelData(); /* 开始选中查找模式为学号模式 */ ui->radioButton->click(); /* 开始不能修改 */ currentRow = 0; changed = false; saveType = Save_Modify; cannotModify(); /* 线路及隧道数据列表更新信号槽 */ connect(ui->linesView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateTunnelsView(const QModelIndex &))); // 【作废】updateCurvesView已在setCurrentMapper中调用 //connect(ui->tunnelsView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateCurvesView(const QModelIndex &))); /* 添加删除隧道槽 */ connect(ui->newTunnelButton, SIGNAL(clicked()), this, SLOT(newTunnel())); connect(ui->deleteTunnelButton, SIGNAL(clicked()), this, SLOT(deleteTunnel())); /* 添加删除隧道对应曲线槽 */ //connect(ui->curvesView, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(changeCurveData())); connect(ui->newCurveButton, SIGNAL(clicked()), this, SLOT(newCurve())); connect(ui->deleteCurveButton, SIGNAL(clicked()), this, SLOT(deleteCurve())); /* 刷新线路隧道 */ connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshLinesView())); /* 具体隧道信息信号槽 */ connect(ui->tunnelsView, SIGNAL(clicked(QModelIndex)), this, SLOT(showTunnelDetail(const QModelIndex &))); //connect(ui->stumajorcombobox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(updateStuClasses(const QString &))); /* 修改隧道信息信号槽 */ connect(ui->lineEdit_tunnelid, SIGNAL(textChanged(QString)), this, SLOT(canSave())); connect(ui->lineEdit_name, SIGNAL(textChanged(QString)), this, SLOT(canSave())); connect(ui->lineEdit_IDstd, SIGNAL(textChanged(QString)), this, SLOT(canSave())); connect(ui->lineEdit_startPoint, SIGNAL(textChanged(QString)), this, SLOT(canSave())); connect(ui->lineEdit_endPoint, SIGNAL(textChanged(QString)), this, SLOT(canSave())); connect(ui->combobox_isNewLine, SIGNAL(currentIndexChanged(int)), this, SLOT(canSave())); connect(ui->combobox_lineType, SIGNAL(currentIndexChanged(int)), this, SLOT(canSave())); connect(ui->radioButton_isDoubleLine, SIGNAL(clicked()), this, SLOT(canSave())); connect(ui->radioButton_isSingleLine, SIGNAL(clicked()), this, SLOT(canSave())); connect(ui->radioButton_isUpLink, SIGNAL(clicked()), this, SLOT(canSave())); connect(ui->radioButton_isDownLink, SIGNAL(clicked()), this, SLOT(canSave())); connect(ui->radioButton_isBridge, SIGNAL(clicked()), this, SLOT(canSave())); connect(ui->radioButton_notBridge, SIGNAL(clicked()), this, SLOT(canSave())); // 隧道中的曲线界面双击修改后,也可点击保存按钮 connect(ui->curvesView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(canSave())); connect(ui->firstButton, SIGNAL(clicked()), this, SLOT(toFirst())); connect(ui->previousButton, SIGNAL(clicked()), this, SLOT(toPrevious())); connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(toNext())); connect(ui->lastButton, SIGNAL(clicked()), this, SLOT(toLast())); connect(ui->modifyButton, SIGNAL(clicked()), this, SLOT(canModify())); /* 查找隧道槽 */ connect(ui->findButton, SIGNAL(clicked()), this, SLOT(findTunnel())); connect(ui->findEdit,SIGNAL(textEdited(QString)),this,SLOT(showAllLines())); /* 编辑桥梁槽 */ connect(ui->editBridgeClearanceButton, SIGNAL(clicked()), this, SLOT(editBridgeClearance())); }