ListNode *addTwoNumbers(ListNode *l1, ListNode *l2, int carry) { if (l1 == NULL && l2 == NULL){ return (carry == 0) ? NULL : new ListNode(carry); } int sum = getVal(l1) + getVal(l2) + carry; ListNode *l3 = new ListNode(sum % 10); l3->next = addTwoNumbers(toNext(l1), toNext(l2), sum / 10); return l3; }
ScreenControl::ScreenControl(QWidget *parent) : QWidget(parent) { setupUi(this); _autoSave=false; _keyColumns=1; _searchType=Query; _shown=false; _listReportName=QString(); _print->setVisible(! _listReportName.isEmpty()); _model = new XSqlTableModel; connect (_new, SIGNAL(clicked()), this, SLOT(newRow())); connect (_save, SIGNAL(clicked()), this, SIGNAL(saveClicked())); connect (_save, SIGNAL(clicked()), this, SLOT(save())); connect (_print, SIGNAL(clicked()), this, SIGNAL(printClicked())); connect (_print, SIGNAL(clicked()), this, SLOT(print())); connect (_prev, SIGNAL(clicked()), this, SLOT(toPrevious())); connect (_next, SIGNAL(clicked()), this, SLOT(toNext())); connect (_search, SIGNAL(clicked()), this, SLOT(search())); connect (_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(enableSave())); _view->setVisible(FALSE); _save->setEnabled(false); _model->setEditStrategy(QSqlTableModel::OnManualSubmit); }
ModelEditDialog::ModelEditDialog(QAbstractItemModel * model, IModelEditPanel * panel, Logbook::Ptr logbook, const QModelIndex & index, QWidget * parent) : QDialog(parent), m_model(model), m_panel(panel), m_logbook(logbook) { m_mapper = new QDataWidgetMapper(this); m_mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit); m_mapper->setModel(m_model); QAbstractItemDelegate * d = m_panel->createDelegate(this); if (d != NULL) m_mapper->setItemDelegate(d); else m_mapper->setItemDelegate(new CustomDelegate(this)); m_btnPrev = new QPushButton(tr("Previous")); m_btnNext = new QPushButton(tr("Next")); //FIXME: HAX so that the search box in MapLocationEditor gets a // returnPressed() event instead of submitting the dialog. m_btnPrev->setDefault(false); m_btnPrev->setAutoDefault(false); m_btnNext->setDefault(false); m_btnNext->setAutoDefault(false); QHBoxLayout * hbox = new QHBoxLayout(); hbox->addStretch(); hbox->addWidget(m_btnPrev); hbox->addWidget(m_btnNext); QWidget * pnl_widget = dynamic_cast<QWidget *>(m_panel); assert(pnl_widget != NULL); QVBoxLayout * vbox = new QVBoxLayout(); vbox->addWidget(pnl_widget); vbox->addLayout(hbox); setLayout(vbox); QAbstractItemModel * m = model; QSortFilterProxyModel * p = dynamic_cast<QSortFilterProxyModel *>(m); while (p != NULL) { m = p->sourceModel(); p = dynamic_cast<QSortFilterProxyModel *>(m); } CustomTableModel * tm = dynamic_cast<CustomTableModel *>(m); if (tm) tm->bind(m_logbook->session()); m_panel->bind(m_logbook->session(), m_mapper); connect(m_btnNext, SIGNAL(clicked()), m_mapper, SLOT(toNext())); connect(m_btnPrev, SIGNAL(clicked()), m_mapper, SLOT(toPrevious())); connect(m_mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(mapperIndexChanged(int))); if (index.isValid()) m_mapper->setCurrentIndex(index.row()); }
//! [Set up widgets] Window::Window(QWidget *parent) : QWidget(parent) { setupModel(); nameLabel = new QLabel(tr("Na&me:")); nameEdit = new QLineEdit(); addressLabel = new QLabel(tr("&Address:")); addressEdit = new QTextEdit(); typeLabel = new QLabel(tr("&Type:")); typeComboBox = new QComboBox(); nextButton = new QPushButton(tr("&Next")); previousButton = new QPushButton(tr("&Previous")); nameLabel->setBuddy(nameEdit); addressLabel->setBuddy(addressEdit); typeLabel->setBuddy(typeComboBox); //! [Set up widgets] //! [Set up the mapper] QSqlTableModel *relModel = model->relationModel(typeIndex); typeComboBox->setModel(relModel); typeComboBox->setModelColumn(relModel->fieldIndex("description")); mapper = new QDataWidgetMapper(this); mapper->setModel(model); mapper->setItemDelegate(new QSqlRelationalDelegate(this)); mapper->addMapping(nameEdit, model->fieldIndex("name")); mapper->addMapping(addressEdit, model->fieldIndex("address")); mapper->addMapping(typeComboBox, typeIndex); //! [Set up the mapper] //! [Set up connections and layouts] connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int))); QGridLayout *layout = new QGridLayout(); layout->addWidget(nameLabel, 0, 0, 1, 1); layout->addWidget(nameEdit, 0, 1, 1, 1); layout->addWidget(previousButton, 0, 2, 1, 1); layout->addWidget(addressLabel, 1, 0, 1, 1); layout->addWidget(addressEdit, 1, 1, 2, 1); layout->addWidget(nextButton, 1, 2, 1, 1); layout->addWidget(typeLabel, 3, 0, 1, 1); layout->addWidget(typeComboBox, 3, 1, 1, 1); setLayout(layout); setWindowTitle(tr("SQL Widget Mapper")); mapper->toFirst(); }
void toNext( int i, ListA& l, int &index ) { if( i > 0 ) { //increment index and decrement the counter while sending the cursor to the next spot in the list l.gotoNext(); i--; index++; //recursive function call toNext( i, l, index ); } }
void LinkedList::locateEntity(const Entity &key, int &index, Entity* &entity) { Node * node = head; int i = 0; while (toNext(node)) { if (key.compareKeyTo(*node->entity) == 0) { index = i; entity = node->entity; return; } i++; } index = NO_MATCHING_ENTITY_INDEX_FLAG; entity = NULL; }
//! [Set up widgets] Window::Window(QWidget *parent) : QWidget(parent) { setupModel(); nameLabel = new QLabel(tr("Na&me:")); nameEdit = new QLineEdit(); addressLabel = new QLabel(tr("&Address:")); addressEdit = new QTextEdit(); ageLabel = new QLabel(tr("A&ge (in years):")); ageSpinBox = new QSpinBox(); nextButton = new QPushButton(tr("&Next")); previousButton = new QPushButton(tr("&Previous")); nameLabel->setBuddy(nameEdit); addressLabel->setBuddy(addressEdit); ageLabel->setBuddy(ageSpinBox); //! [Set up widgets] //! [Set up the mapper] mapper = new QDataWidgetMapper(this); mapper->setModel(model); mapper->addMapping(nameEdit, 0); mapper->addMapping(addressEdit, 1); mapper->addMapping(ageSpinBox, 2); connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int))); //! [Set up the mapper] //! [Set up the layout] QGridLayout *layout = new QGridLayout(); layout->addWidget(nameLabel, 0, 0, 1, 1); layout->addWidget(nameEdit, 0, 1, 1, 1); layout->addWidget(previousButton, 0, 2, 1, 1); layout->addWidget(addressLabel, 1, 0, 1, 1); layout->addWidget(addressEdit, 1, 1, 2, 1); layout->addWidget(nextButton, 1, 2, 1, 1); layout->addWidget(ageLabel, 3, 0, 1, 1); layout->addWidget(ageSpinBox, 3, 1, 1, 1); setLayout(layout); setWindowTitle(tr("Simple Widget Mapper")); mapper->toFirst(); }
Entity* LinkedList::entityAt(int index) { if ((index >= getCount()) || (index < 0)) { return NULL; } Node * node = head; for (int i = 0; toNext(node); i++) { if (i == index) { return node->entity; } } // should never get here return NULL; }
int binarysearch( ListA& l, int ArraySize, int compare, int index ) { int hold,tempi = ArraySize/2; ListA newL( tempi+1 ); //if the array size is larger than one run this condition if( ArraySize > 1 ) { l.gotoBeginning(); //put the cursor on the middle of the list toNext( tempi, l, index ); l.getCursor( hold ); //if the number appears in the lower half of the list runs this condition if( compare < hold ) { tempi = ArraySize/2; //creates a new list from the bottom half of the current list l.gotoBeginning(); newList( newL, tempi, l ); //passes the new list for recursion return binarysearch( newL, tempi, compare, index-tempi ); } //if the number appears in the upperhalf of the list runs this condition else { tempi = ArraySize - ArraySize/2; //creates a new list from the top half of the current list newList( newL, tempi, l ); //passes the new list for recursion return binarysearch( newL, tempi, compare, index ); } } else //this is the end condition return index; //the function should never reach this point this is just to stop the warning return -1; }
MapData::MapData(QWidget *parent) : QDialog(parent), ui(new Ui::MapData) { ui->setupUi(this); this->setupModel(); mapper = new QDataWidgetMapper(this); mapper->setModel(model); mapper->addMapping(ui->lineEdit,0); mapper->addMapping(ui->plainTextEdit,1); connect(ui->tmbPrev,SIGNAL(clicked()),mapper,SLOT(toPrevious())); connect(ui->tmbNext,SIGNAL(clicked()),mapper,SLOT(toNext())); connect(mapper,SIGNAL(currentIndexChanged(int)),this,SLOT(tombolApdet(int))); mapper->toFirst(); }
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*))); }
formControl::formControl(QWidget *parent) : QWidget(parent) { setupUi(this); _autoSave=false; _searchType=Query; _shown=false; connect (_new, SIGNAL(clicked()), this, SLOT(newRow())); connect (_save, SIGNAL(clicked()), this, SIGNAL(saveClicked())); connect (_save, SIGNAL(clicked()), this, SLOT(save())); connect (_print, SIGNAL(clicked()), this, SLOT(print())); connect (_prev, SIGNAL(clicked()), this, SLOT(toPrevious())); connect (_next, SIGNAL(clicked()), this, SLOT(toNext())); connect (_search, SIGNAL(clicked()), this, SLOT(search())); //Hiding future functionality that has been commented out for now _print->setVisible(FALSE); _view->setVisible(FALSE); }
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())); }
ListNode *deleteDuplicates(ListNode *head) { ListNode* p = head; ListNode* pTmp = NULL; ListNode* keepNode = NULL; ListNode* pNewHead = NULL; bool canuse = false; //pTmp = toNext(p,&canuse); //printf("canuse:%d,p->val=%d,pTmp->val=%d\n", canuse,p->val,pTmp->val); //return NULL; while( p != NULL ) { pTmp = toNext(p,&canuse); //printf("canuse:%d,p->val=%d,%s \n", canuse,p->val,pTmp == NULL?"NULL":"not NULL"); //return NULL; if ( canuse ) { if ( keepNode == NULL ) { p->next = NULL; keepNode = p; pNewHead = keepNode; } else { p->next = NULL; keepNode->next = p; keepNode = keepNode->next; } //keepNode->next = NULL; } p = pTmp; } return pNewHead; }
/** \fn void EditMediaDialog::makeConnections() * \brief makes the connections used by EditMediaDialog */ void EditMediaDialog::makeConnections() { connect(ui_->nextButton, SIGNAL(clicked()), this, SLOT(toNext())); connect(ui_->previousButton, SIGNAL(clicked()), this, SLOT(toPrevious())); }
void Wordreciting::startDailyMission() { int mLevel = Word::getMaxLevel(); std::vector <std::queue <Word*>> wordWithLevel(mLevel + 1); for (int i = 0; i < wordlist->size(); i++) { Word *word = wordlist->getWord(i); int wLevel = word->getLevel(); if (wLevel != -1) { wordWithLevel[wLevel].push(word); } } std::vector <int> probability; for (int i = 0; i < strategy->newProportion; i++) { probability.push_back(Word::getDefaultLevel()); } for (int i = 0; i <= mLevel; i++) { if (i != Word::getDefaultLevel()) { int tot = (mLevel + 2) * (mLevel + 1) / 2; int jm = static_cast <int> ((100 - strategy->newProportion) * ((1.0 + i) / tot)); if (jm < 1) jm = 1; for (int j = 0; j < jm; j++) probability.push_back(i); } } while (probability.size() != 100) { probability.push_back(Word::getDefaultLevel()); } std::random_shuffle(probability.begin(), probability.end()); dailywordreciting = new DailyWordreciting(); for (int i = 0; i < strategy->dailyNumber; i++) { bool finished = true; for (int j = 0; j <= mLevel; j++) { if (!wordWithLevel[j].empty()) { finished = false; break; } } if (finished) break; while (1) { int rd = probability[rand() % probability.size()]; if (!wordWithLevel[rd].empty()) { dailywordreciting->push(wordWithLevel[rd].front(), 1); wordWithLevel[rd].pop(); break; } } } curWord = nullptr; toNext(); }
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")); }
/** * 隧道管理界面类实现 * 继承自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())); }
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); }
bool LinkedList::toNext() { return toNext(current); }
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(); } }