void InfoManage::on_newButton_clicked() { Item *item = new Item(); item->name = ui->namelineEdit->text(); item->type = ui->typelineEdit->text(); item->barcode = ui->barcodelineEdit->text(); item->price = ui->pricelineEdit->text().toDouble(); item->measurement = ui->measurelineEdit->text(); item->cost = ui->costlineEdit->text().toDouble(); item->amount = ui->countlineEdit->text().toDouble(); item->comment = ui->commentlineEdit->text(); if(item->comment.isEmpty()) item->comment = "none"; if(!correctBarcode(item->barcode)){ QMessageBox::warning(this, tr("NEW Warning"), tr("barcode not correct!") ); return; } if(finditem(item->barcode,itemlist)!=itemlist.end()){ QMessageBox::warning(this, tr("NEW Warning"), tr("already existed!") ); return; } ui->tableWidget->insertRow(itemlist.size()); itemlist.push_back(*item); showitem(itemlist); }
void InfoManage::loadFile(const QString &fileName) //! [42] //! [43] { QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning(this, tr("Application"),tr("Cannot read file %1:\n%2.").arg(fileName).arg(file.errorString())); return; } QTextStream in(&file); #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif //ui->textEdit->setPlainText(in.readAll()); itemlist.clear(); for(int i=ui->tableWidget->rowCount()-1;i>=0;i--){ ui->tableWidget->removeRow(i); } Item item; int i=0; while(!in.atEnd()){ in>>item.name>>item.type>>item.barcode>>item.price>>item.measurement>>item.cost>>item.amount>>item.comment; itemlist.push_back(item); ui->tableWidget->insertRow(i); i++; } showitem(itemlist); for(int j=0;j<8;j++){ ui->tableWidget->resizeColumnToContents (j); } #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif setCurrentFile(fileName); statusBar()->showMessage(tr("File loaded"), 2000); }
void showmenu(struct MENU *menu) { struct ITEM *itemptr; /* points to each item in turn */ int ctr = 1; /* counts each item */ wbkgd(menu->menuwin, BOXATTR); #if 0 wattrset(menu->menuwin, BOXATTR); /* set to bg+/b */ colorwin(menu->menuwin); /* color window */ #endif box(menu->menuwin, ACS_VLINE, ACS_HLINE); /* draw border */ itemptr = menu->itemlist; /* point to start */ wattrset(menu->menuwin, STDATTR); if (strlen(menu->desc) > 0) mvwprintw(menu->menuwin, 0, 2, " %s ", menu->desc); do { /* display items */ wmove(menu->menuwin, ctr, 1); showitem(menu, itemptr, NOTSELECTED); /* show items, initially unselected */ ctr++; itemptr = itemptr->next; } while (ctr <= menu->itemcount); update_panels(); doupdate(); }
void dumpInternalState( a_state *x ) { a_parent *parent; a_shift_action *tx; a_reduce_action *rx; size_t col, new_col; set_size *mp; an_item **item; printf( "state %d: %p (%u)\n", x->sidx, x, x->kersize ); printf( " parent states:" ); col = 4; for( parent = x->parents; parent != NULL; parent = parent->next ) { printf( " %d(%p)", parent->state->sidx, parent->state ); --col; if( col == 0 ) { printf( "\n" ); col = 5; } } printf( "\n" ); for( item = x->items; *item != NULL; ++item ) { showitem( *item, " ." ); } printf( "actions:" ); col = 8; for( tx = x->trans; tx->sym != NULL; ++tx ) { new_col = col + 1 + strlen( tx->sym->name ) + 1 + 1 + 3; if( new_col > 79 ) { putchar('\n'); new_col -= col; } col = new_col; printf( " %s:s%03d", tx->sym->name, tx->state->sidx ); } putchar( '\n' ); col = 0; for( rx = x->redun; rx->pro != NULL; ++rx ) { for( mp = Members( rx->follow ); mp != setmembers; ) { --mp; new_col = col + 1 + strlen( symtab[*mp]->name ); if( new_col > 79 ) { putchar('\n'); new_col -= col; } col = new_col; printf( " %s", symtab[*mp]->name ); } new_col = col + 1 + 5; if( new_col > 79 ) { putchar('\n'); new_col -= col; } col = new_col; printf( ":r%03d", rx->pro->pidx ); } putchar( '\n' ); }
void InfoManage::on_clearButton_clicked() { ui->namelineEdit->clear(); ui->typelineEdit->clear(); ui->barcodelineEdit->clear(); ui->countlineEdit->clear(); ui->pricelineEdit->clear(); ui->measurelineEdit->clear(); ui->costlineEdit->clear(); ui->commentlineEdit->clear(); showitem(itemlist); }
void InfoManage::on_addButton_clicked() { QString barcode = ui->barcodelineEdit->text(); double count = ui->countlineEdit->text().toDouble(); if(!correctBarcode(barcode)){ QMessageBox::warning(this, tr("ADD Warning"), tr("barcode not correct!") ); return; } std::vector<Item>::iterator p = finditem(barcode,itemlist); if(p==itemlist.end()){ QMessageBox::warning(this, tr("ADD Warning"), tr("not found!") ); return; } p->amount += count; showitem(itemlist); }
void InfoManage::on_searchButton_clicked() { QString name = ui->namelineEdit->text(); QString type = ui->typelineEdit->text(); QString barcode = ui->barcodelineEdit->text(); std::vector<Item> ilist; if(!barcode.isEmpty()){ if(finditem(barcode,ilist)==ilist.end()){ QMessageBox::warning(this, tr("Application"),tr("Incorrect Barcode!"));//deal with the error when finding fails return; } ilist.push_back(*finditem(barcode,itemlist)); } else{ if(!name.isEmpty()){ std::vector<Item>::iterator p; for(p=itemlist.begin();p<itemlist.end();p++){ if(p->name==name){ if(!type.isEmpty()){ if(p->type==type) ilist.push_back(*p); } else ilist.push_back(*p); } } } else{ std::vector<Item>::iterator p; for(p=itemlist.begin();p<itemlist.end();p++){ if(p->type==type){ ilist.push_back(*p); } } } } showitem(ilist); }
static void resolve( a_state *x, set_size *work, a_reduce_action **reduce ) { a_shift_action *tx, *ux; a_reduce_action *rx; set_size *w; set_size *mp; index_n i; a_prec symprec, proprec, prevprec; w = work; for( rx = x->redun; rx->pro != NULL; ++rx ) { for( mp = Members( rx->follow ); mp != setmembers; ) { --mp; if( reduce[*mp] != NULL ) { prevprec = reduce[*mp]->pro->prec; proprec = rx->pro->prec; if( prevprec.prec == 0 || proprec.prec == 0 || prevprec.prec == proprec.prec ) { *w++ = *mp; /* resolve to the earliest production */ if( rx->pro->pidx >= reduce[*mp]->pro->pidx ) { continue; } } else if( prevprec.prec > proprec.prec ) { /* previous rule had higher precedence so leave it alone */ continue; } } reduce[*mp] = rx; } } while( w != work ) { --w; if( symtab[*w]->token == errsym->token ) continue; printf( "r/r conflict in state %d on %s:\n", x->sidx, symtab[*w]->name); ++RR_conflicts; for( rx = x->redun; rx->pro != NULL; ++rx ) { if( IsBitSet( rx->follow, *w ) ) { showitem( rx->pro->items, "" ); } } printf( "\n" ); for( rx = x->redun; rx->pro != NULL; ++rx ) { if( IsBitSet( rx->follow, *w ) ) { ShowSentence( x, symtab[*w], rx->pro, NULL ); } } printf( "---\n\n" ); } ux = x->trans; for( tx = ux; tx->sym != NULL; ++tx ) { i = tx->sym->idx; if( i >= nterm || reduce[i] == NULL ) { *ux++ = *tx; } else { /* shift/reduce conflict detected */ check_for_user_hooks( x, tx, reduce[i]->pro->pidx ); symprec = tx->sym->prec; proprec = reduce[i]->pro->prec; if( symprec.prec == 0 || proprec.prec == 0 ) { if( tx->sym != errsym ) { printf( "s/r conflict in state %d on %s:\n", x->sidx, tx->sym->name ); ++SR_conflicts; printf( "\tshift to %d\n", tx->state->sidx ); showitem( reduce[i]->pro->items, "" ); printf( "\n" ); ShowSentence( x, tx->sym, reduce[i]->pro, NULL ); ShowSentence( x, tx->sym, NULL, tx->state ); printf( "---\n\n" ); } *ux++ = *tx; reduce[i] = NULL; } else { if( symprec.prec > proprec.prec ) { *ux++ = *tx; reduce[i] = NULL; } else if( symprec.prec == proprec.prec ) { if( symprec.assoc == R_ASSOC ) { *ux++ = *tx; reduce[i] = NULL; } else if( symprec.assoc == NON_ASSOC ) { ux->sym = tx->sym; ux->state = errstate; ++ux; reduce[i] = NULL; } } } } } ux->sym = NULL; for( rx = x->redun; rx->pro != NULL; ++rx ) { Clear( rx->follow ); } for( i = 0; i < nterm; ++i ) { if( reduce[i] != NULL ) { SetBit( reduce[i]->follow, i ); reduce[i] = NULL; } } }
void operatemenu(struct MENU *menu, int *position, int *aborted) { struct ITEM *itemptr; int row = *position; int exitloop = 0; int ch; char *keyptr; menukeyhelp(); *aborted = 0; menumoveto(menu, &itemptr, row); menu->descwin = newwin(1, COLS, LINES - 2, 0); menu->descpanel = new_panel(menu->descwin); do { wmove(menu->menuwin, row, 1); showitem(menu, itemptr, SELECTED); /* * Print item description */ wattrset(menu->descwin, DESCATTR); colorwin(menu->descwin); wmove(menu->descwin, 0, 0); wprintw(menu->descwin, " %s", itemptr->desc); update_panels(); doupdate(); wmove(menu->menuwin, row, 2); ch = wgetch(menu->menuwin); wmove(menu->menuwin, row, 1); showitem(menu, itemptr, NOTSELECTED); switch (ch) { case KEY_UP: if (row == 1) row = menu->itemcount; else row--; itemptr = itemptr->prev; if (itemptr->itemtype == SEPARATOR) { row--; itemptr = itemptr->prev; } break; case KEY_DOWN: if (row == menu->itemcount) row = 1; else row++; itemptr = itemptr->next; if (itemptr->itemtype == SEPARATOR) { row++; itemptr = itemptr->next; } break; case 12: refresh_screen(); break; case 13: exitloop = 1; break; /* case 27: exitloop = 1;*aborted = 1;row=menu->itemcount;break; */ case '^': break; /* ignore caret key */ default: keyptr = strchr(menu->shortcuts, toupper(ch)); if ((keyptr != NULL) && keyptr - menu->shortcuts < menu->itemcount) { row = keyptr - menu->shortcuts + 1; exitloop = 1; } } } while (!(exitloop)); *position = row; /* position of executed option is in *position */ del_panel(menu->descpanel); delwin(menu->descwin); update_panels(); doupdate(); }