/** * Recursively adds an item to the Shopper's cart while quantity > 1, * otherwise a single item is added to the cart. * @param item An 'Item' reference object being added to cart. * @param quantity The number of times that item is added to cart. */ void Shopper::addItemToCart(const Item& item, int quantity) { cart.addItem(item); if (quantity > 1) addItemToCart(item, quantity-1); }
MainWindow::MainWindow(ActualDataStore* inDS) { ds = inDS; userNames = ds->getUsersNames(); // Title setWindowTitle("Amazon"); // Overall layout overallLayout = new QVBoxLayout(); // // Search group for searching functionality sGroup = new SearchGroup(ds); overallLayout->addWidget(sGroup); // // Section for interacting with users // Layout userGroupLayout = new QHBoxLayout(); overallLayout->addLayout(userGroupLayout); // Button for selecting current user userButtonIdentifier = new QLabel("Current User:"******"Add to Cart"); userGroupLayout->addWidget(addCartButton); // Viewcart button viewCartButton = new QPushButton("View Cart"); connect(viewCartButton, SIGNAL(clicked()), this, SLOT(openViewCartWindow())); userGroupLayout->addWidget(viewCartButton); // // Section for dealing with database // Layout dbGroupLayout = new QHBoxLayout(); overallLayout->addLayout(dbGroupLayout); // Save functionality newDBField = new QLineEdit(); newDBField->setPlaceholderText("Enter new database filename"); saveButton = new QPushButton("Save"); connect(saveButton, SIGNAL(clicked()), this, SLOT(saveDatabase())); dbGroupLayout->addWidget(newDBField); dbGroupLayout->addWidget(saveButton); // Quit quitButton = new QPushButton("Quit"); connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); dbGroupLayout->addWidget(quitButton); // Allow enter/return key to act as go button connect(newDBField, SIGNAL(returnPressed()), this, SLOT(saveDatabase())); // Mapper to reroute addCartButton to sGroup signalMapper = new QSignalMapper(this); connect(addCartButton, SIGNAL(clicked()), signalMapper, SLOT(map())); signalMapper->setMapping(addCartButton, userSelButton->currentText()); connect(signalMapper, SIGNAL(mapped(QString)), sGroup, SLOT(addItemToCart(QString))); // Set overall layout setLayout(overallLayout); }