int PurchaseEditor::getCategoryId() { QSqlQuery query(db); int code=-1; QString currentText = ui->categoriesCombo->currentText(); Azahar *myDb = new Azahar; myDb->setDatabase(db); code = myDb->getCategoryId(currentText); return code; }
void SubcategoryEditor::addNewChild() { //launch dialog to ask for the new child. Using this same dialog. SubcategoryEditor *scEditor = new SubcategoryEditor(this); scEditor->setDb(db); Azahar *myDb = new Azahar; myDb->setDatabase(db); scEditor->setCatList( catList ); scEditor->setScatList( scatList ); scEditor->setDialogType(dialogType+1);//incrementing because this dialog is a child dialog (parentType+1) if (dialogType == 1) { //From "Add Department" dialog, creating a category. scEditor->setLabelForName(i18n("New category:")); scEditor->setLabelForList(i18n("Select the child subcategories for this category:")); scEditor->populateList( myDb->getSubCategoriesList() ); } else if (dialogType == 2) { //From "Add Category" dialog, creating a subcategory. No child allowed. scEditor->setLabelForName(i18n("New subcategory:")); scEditor->setLabelForList(i18n("")); scEditor->hideListView(); //subcategories does not have children. } if ( scEditor->exec() ) { QString text = scEditor->getName(); QStringList children = scEditor->getChildren(); qDebug()<<text<<" CHILDREN:"<<children; if (dialogType == 1) { //The dialog is launched from the "Add Department" dialog. So we are going to create a category. //Create the category if (!myDb->insertCategory(text)) { qDebug()<<"Error:"<<myDb->lastError(); delete myDb; return; } //insert new category to the box catList << text; ui->listView->addItem(text); //mark item as checkable ui->listView->item(ui->listView->count()-1)->setFlags(ui->listView->item(ui->listView->count()-1)->flags() |Qt::ItemIsUserCheckable); ui->listView->item(ui->listView->count()-1)->setCheckState(Qt::Checked); //mark as checked. qulonglong cId = myDb->getCategoryId(text); //create the m2m relations for the new category->subcategory. foreach(QString cat, children) { //get subcategory id qulonglong scId = myDb->getSubCategoryId(cat); //create the link [category] --> [subcategory] myDb->insertM2MCategorySubcategory(cId, scId); } } else if (dialogType == 2) { //The dialog is launched from the "Add Category" dialog. So we are going to create a subcategory which does have a child.
void PromoEditor::setFilter() { QRegExp regexp = QRegExp(ui->editName->text()); if (ui->chByName->isChecked()) { //1st if: Filter by DESC. if (!regexp.isValid() || ui->editName->text().isEmpty() || (ui->editName->text()=="*") ) model->setFilter(""); else model->setFilter(QString("products.name REGEXP '%1'").arg(ui->editName->text())); } else { // filter by category... int catId=-1; QString catText = ui->comboCategory->currentText(); Azahar *myDb = new Azahar; myDb->setDatabase(db); catId = myDb->getCategoryId(catText); //qDebug()<<"Category:"<<catText<<" Id:"<<catId; model->setFilter(QString("products.category=%1").arg(catId)); } }