//Encargado de buscar un registro y mostrarlo void MainWindow::on_searchRecord_triggered() { //toma el vector de campos vector<Field*> fields = this->fileRecord.getFields(); QString str; //muestra una ventana para que se busque el registro a partir de su clave for(int i = 0; i< fields.size(); i++){ Field* currentField = fields.at(i); if(currentField->isKey()){ InputDialog* idialog = new InputDialog(); idialog->setField(currentField); idialog->exec(); if(idialog->getString().isEmpty()){ return; } str = idialog->getString(); delete idialog; } } //Obtiene un indice primario de la busqueda en el mapa de indices primarios PrimaryIndex* index = this->fileRecord.searchRecord(str.toStdString()); //En caso de que no se encuentre el registro, este indice primario es nulo if(index == NULL){ QMessageBox::critical(this,"Error","El registro que buscaba no se encontro"); return; }else{ //se obtiene un registro a partir del indice primario Record* record = this->fileRecord.getRecord(index); vector<string> r = record->getRecord(); //se hace el modelo para poder mostrar el registro QStandardItemModel* model = new QStandardItemModel(1,1,this); //se hacen los encabezados de la tabla for(int i = 0; i < fields.size(); i++){ model->setHorizontalHeaderItem(i,new QStandardItem(QString::fromStdString(fields[i]->getName()))); } //se la fila para el registro for(int i = 0; i < fields.size(); i++){ model->setItem(0,i,new QStandardItem(QString::fromStdString(r[i]))); } //se elimina el registro de memoria porque esta guardado en el archivo delete record; //se asigna el modelo a la tabla del main ui->MWTable->setModel(model); } }
//se encarga de eliminar un registro, solamente lo marca y lo elimina de los indices primarios //para que despues se le pase el compactar void MainWindow::on_deleteRecord_triggered() { vector<Field*> fields = this->fileRecord.getFields(); QString str; for(int i = 0; i< fields.size(); i++){ Field* currentField = fields.at(i); if(currentField->isKey()){ //se le muestra una nueva ventana para pedir la llave primaria InputDialog* idialog = new InputDialog(); idialog->setField(currentField); idialog->exec(); if(idialog->getString().isEmpty()){ return; } str = idialog->getString(); delete idialog; } } //toma el indice primario por medio de una busqueda PrimaryIndex* index = this->fileRecord.searchRecord(str.toStdString()); if(index == NULL){ QMessageBox::critical(this,"Error","No se encontro el registro con la llave ingresada"); return; }else{ //se borra el registro de los indices primarios y se marca con un * en el archivo de registros if(this->fileRecord.deleteRecord(index)){ vector<PrimaryIndex*> indexes = this->fileRecord.getIndexes(); stringstream ss; for(int i = 0; i < indexes.size(); i++){ ss<<indexes.at(i)->toString(); if(i != indexes.size() -1){ ss<<'/'; } } this->indicesFile.seekp(0,ios_base::beg); this->indicesFile.write(ss.str().c_str(),ss.str().length()); this->indicesFile.flush(); QMessageBox::information(this,"Correcto","Se ha podido eliminar el registro correctamente"); }else{ QMessageBox::critical(this,"Error","No se pudo eliminar el registro, no se encuentra la llave"); } } }
void InputTag::emitData() { KILE_DEBUG() << "InputTag::emitData() " << m_ki->getName(); InputDialog *dlg = new InputDialog(m_data.text, m_options, m_history, m_hint, m_alter, m_ki, m_parent, "input_dialog"); if (dlg->exec()) { if((!dlg->tag().isEmpty()) && hasHistory()) { addToHistory(dlg->tag()); } TagData td(m_data); td.tagBegin.replace("%R",dlg->tag()); td.tagEnd.replace("%R",dlg->tag()); QString alt = dlg->useAlternative() ? "*" : ""; td.tagBegin.replace("%A", alt); td.tagEnd.replace("%A", alt); if(dlg->useLabel()) { td.tagEnd += dlg->label(); td.dy++; } if(dlg->usedSelection()) { m_ki->clearSelection(); } // if a filename was given for a \input- or \include-command, // the cursor is moved out of the braces if ( (m_options & (KileAction::ShowBrowseButton | KileAction::FromLabelList | KileAction::FromBibItemList)) && !dlg->tag().isEmpty() ) { td.dx += dlg->tag().length() + 1; } // insert tag emit(triggered(td)); // refresh document structure and project tree when a file was inserted if(dlg->useAddProjectFile()) { m_ki->docManager()->projectAddFile(QFileInfo(m_ki->getCompileName()).absolutePath() + '/' + dlg->tag()); } } delete dlg; }
void ImageIndexEditor::addNode() { //CatalogTreeNode* selectedNode = _index->getSelectedNode(); CatalogTreeNode* selectedNode = _index->getSelectedNode(); if (selectedNode == NULL) { // JOptionPane.showMessageDialog(this, tr("selectAddNode"), // tr("info"), JOptionPane.INFORMATION_MESSAGE); QMessageBox::information(this, tr("Information"), tr("Select a node where you want to add a child node.")); } else { #if 1 QString name = JOptionPane::showInputDialog(this, tr("Please enter a name for the node you want to add."), tr("Question"), JOptionPane::QUESTION_MESSAGE); if (name != NULL) { if(!_index->insertNodeIntoModel(name, selectedNode)) { JOptionPane::showMessageDialog(this, tr("The name \"%1}\" is a duplicate. Node names\nin the path to the root must be unique.").arg(name), tr("error"), JOptionPane::ERROR_MESSAGE); } } #else QString name; InputDialog* dlg = new InputDialog(tr("Please enter a name for the node you want to add."),name); if(dlg->exec() == QDialog::Accepted) { name = dlg->value(); } if(name == "") { if(!_index->insertNodeIntoModel(name, selectedNode)) { QMessageBox::critical(this, tr("Error"), tr("The name \"%1}\" is a duplicate. Node names\n in the path to the root must be unique.").arg(name)); } } #endif } //invalidate(); }
void ImageIndexEditor::renameNode() { CatalogTreeNode* selectedNode = _index->getSelectedNode(); if (selectedNode == NULL) { JOptionPane::showMessageDialog(this, tr("Please enter a name for the node."), tr("Info"), JOptionPane::INFORMATION_MESSAGE); } else { #if 1 QString name = JOptionPane::showInputDialog(this, tr("Please enter a new name for the node."), selectedNode->getUserObject()); if (name != NULL) { if (!_index->nodeChange(selectedNode, name)){ JOptionPane::showMessageDialog(this, tr("The name \"%1\" is a duplicate. Node names\nin the path to the root must be unique.").arg(name),tr("error"), JOptionPane::ERROR_MESSAGE); } } #else QString name; InputDialog* dlg = new InputDialog(tr("Please enter a new name for the node."),name); if(dlg->exec() == QDialog::Accepted) { name = dlg->value(); } if(name == "") { if(!_index->insertNodeIntoModel(name, selectedNode)) { QMessageBox::critical(this, tr("Error"), tr("The name \"%1\" is a duplicate. Node names\nin the path to the root must be unique.").arg(name)); } #endif } // invalidate(); } void ImageIndexEditor::deleteNode() { CatalogTreeNode* selectedNode = _index->getSelectedNode(); if (selectedNode == NULL) { // JOptionPane.showMessageDialog(this, tr("selectDeleteNode"), // tr("info"), JOptionPane.INFORMATION_MESSAGE); QMessageBox::information(this, tr("Info"), tr("Select the node you want to delete.")); } else { int numNodes = countSubNodes(selectedNode); int numIcons = countIcons(selectedNode); // int response = JOptionPane.showConfirmDialog(this, java.text.MessageFormat.format( // tr("confirmDeleteNode"), new Object[] // {(String)selectedNode.getUserObject(), Integer.valueOf(numNodes), Integer.valueOf(numIcons)}), // tr("question"), JOptionPane.YES_NO_OPTION, // JOptionPane.QUESTION_MESSAGE); // if (response == JOptionPane.YES_OPTION) { // _index.removeNodeFromModel(selectedNode); // } switch(QMessageBox::question(this, tr("Question"), tr("Delete node, %1, its %2 subnodes, and all %3 image indices?").arg(selectedNode->getUserObject().toString()).arg(numNodes).arg(numIcons))) { case QMessageBox::Yes: _index->removeNodeFromModel(selectedNode); default: break; } } }
int input(int wi, int h, QWidget *w, int argc, QStringList args) { int i, type = 0; QString title, label, filename; bool edit=false, full=true; for(i=0; i < argc; i++) { if(args[i] == "-s") { type = 0; } if(args[i] == "-l") { type = 1; } if(args[i] == "-b") { type = 2; } if(args[i] == "-p") { type = 3; } if(args[i] == "-t") { title = args[i+1]; } if(args[i] == "-L") { label = args[i+1]; } if(args[i] == "-F") { if(args[i+1][0] != '-') { filename = args[i+1]; } } if(args[i] =="-E") { edit = true; } if(args[i] == "-g") { full = false; } } InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w); if(full) { w->setCaption(title); QPEApplication::showWidget( w ); } if( id->exec() == 1) { printf("%s\n", id->getString().latin1()); return 0; } else { return -1; } }
//Encargado de insertar un nuevo registro al archivo void MainWindow::on_insertRecord_triggered() { //verifica que existan campos en el archivo if(this->fileRecord.fieldsSize() == 0){ QMessageBox::warning(this,"Error","No tiene campos en el archivo, por favor ingrese un campo para continuar"); return; } //Validar que cuando se ingrese la llave, esta sea unica vector<string> record; vector<Field*> tmpfields = this->fileRecord.getFields(); for(int i = 0; i < tmpfields.size(); i++){ Field* currentField = tmpfields[i]; InputDialog* idialog = new InputDialog(); idialog->setField(currentField); idialog->exec(); QString text = idialog->getString(); record.push_back(text.toStdString()); delete idialog; } //verifica que la cantidad de ingresos sea igual a la cantidad de campos if(record.size() != tmpfields.size()){ QMessageBox::critical(this,"Error","Error en la cantidad de campos que lleno"); return; } //crea un nuevo registro Record* newRecord = new Record(tmpfields,record); //verficica que la llave primaria no exista if(this->fileRecord.addRecord(newRecord)){ //Obtiene un vector de indices principales vector<PrimaryIndex*> indexes = this->fileRecord.getIndexes(); //genera como un toString para los indicies stringstream ss; for(int i = 0; i < indexes.size(); i++){ ss<<indexes.at(i)->toString(); if(i != indexes.size() -1){ ss<<'/'; } } //guarda los indices primarios en el archivo this->indicesFile.seekp(0,ios_base::beg); this->indicesFile.write(ss.str().c_str(),ss.str().length()); this->indicesFile.flush(); QMessageBox::information(this,"Correcto","Se ingreso correctamente el nuevo registro"); delete newRecord; //lo borra de memoria, pero ya esta guardado en el archivo }else{ //borra el nuevo registro porque no sirvio de nada QMessageBox::critical(this,"Error","Hubo un error al insertar el nuevo registro"); delete newRecord; } }