Example #1
0
//---------------------------------------------------------------------------
void __fastcall TNamedObjectList::Notify(void *Ptr, TListNotification Action)
{
  TObjectList::Notify(Ptr, Action);
  if (AutoSort && (Action == lnAdded)) AlphaSort();
  Recount();
}
Main_Window::Main_Window(std::string login_user, DStore dbase)
{
	ds = dbase;	
	currentuser = login_user;
  	//Title
	setWindowTitle("Amazon Shop");

	// Overall layout
	OverallLayout = new QHBoxLayout();

	//this is smaller layout within overall layout
	SearchOptionLayout = new QVBoxLayout();
	OverallLayout->addLayout(SearchOptionLayout);

	//Terms text
	SearchTermsLabel = new QLabel("Search Terms");
	SearchOptionLayout->addWidget(SearchTermsLabel);

	//Creating line edit to enter terms to search
	SearchTermsInput = new QLineEdit();
	SearchOptionLayout->addWidget(SearchTermsInput);

	//Creating exclusive group check-box
	CheckboxLayout = new QHBoxLayout();
	SearchOptionLayout->addLayout(CheckboxLayout);

	AND = new QRadioButton(tr("AND"));
	CheckboxLayout->addWidget(AND);

	OR = new QRadioButton(tr("OR"));
	CheckboxLayout->addWidget(OR);

	AND->setAutoExclusive(true);
	AND->setChecked(true);

	//Add the search button
	SearchButton = new QPushButton("SEARCH");
	connect(SearchButton, SIGNAL(clicked()), this, SLOT(SEARCH()));
	SearchOptionLayout->addWidget(SearchButton);

	//Add the alphabetical merge-sort button
	SortOptionLayout = new QHBoxLayout();
	SearchOptionLayout->addLayout(SortOptionLayout);

	AlphaSortButton = new QPushButton("Sort Search Alphabetically");
	connect(AlphaSortButton, SIGNAL(clicked()), this, SLOT(AlphaSort()));
	SortOptionLayout->addWidget(AlphaSortButton);

	//Add the review merge-sort button
	ReviewSortButton = new QPushButton("Sort Search by Average Rating");
	connect(ReviewSortButton, SIGNAL(clicked()), this, SLOT(RSort()));
	SortOptionLayout->addWidget(ReviewSortButton);

	//Create dropdown menu to select user
	UserDropdown = new QComboBox();
	
	//iterating through user vector to print into menu
	for(unsigned int i=0; i<ds.getUserVector().size(); i++)
	{
		std::vector<User*> myVector= ds.getUserVector();
		User* user= myVector[i];
		QString qstr= QString::fromStdString(user->getName());
		UserDropdown->addItem(qstr);
	}	
	SearchOptionLayout->addWidget(UserDropdown);
	connect(UserDropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(filler(int)));

	//Horizontal layout for add and view cart buttons
	CartOptionLayout = new QHBoxLayout();
	SearchOptionLayout->addLayout(CartOptionLayout);

	//Create add cart button
	AddCartButton = new QPushButton("Add-to-Cart");
	connect(AddCartButton, SIGNAL(clicked()), this, SLOT(ADDCART()));
	CartOptionLayout->addWidget(AddCartButton);

	//Create view cart button
	ViewCartButton = new QPushButton("View-Cart");
	connect(ViewCartButton, SIGNAL(clicked()), this, SLOT(VIEWCART()));
	CartOptionLayout->addWidget(ViewCartButton);

	//Enter valid file to save to text
	SaveLabel = new QLabel("Type valid file to save to");
	SearchOptionLayout->addWidget(SaveLabel);

	//Creating line edit to enter terms to search
	SaveInput = new QLineEdit();
	SearchOptionLayout->addWidget(SaveInput);

	//Save database to a file button
	SaveButton = new QPushButton("Save Text File");
	connect(SaveButton, SIGNAL(clicked()), this, SLOT(SAVE()));
	SearchOptionLayout->addWidget(SaveButton);

	//Quit program button
	QuitButton = new QPushButton("QUIT");
	connect(QuitButton, SIGNAL(clicked()), this, SLOT(QUIT()));
	SearchOptionLayout->addWidget(QuitButton);

	//Create product list and layout
	ProductLayout = new QVBoxLayout();
	OverallLayout->addLayout(ProductLayout);

	//Create text for Products
	ProductsLabel = new QLabel("Products That Match Search");
	ProductLayout->addWidget(ProductsLabel);

	//Create empty list that will have products from search
	ProductList = new QListWidget();
	prodref = ProductList;
	connect(ProductList, SIGNAL(currentRowChanged(int)), this, SLOT(ProductChange(int)));
	ProductLayout->addWidget(ProductList);

	//Create review list and layout
	ReviewLayout = new QVBoxLayout();
	OverallLayout->addLayout(ReviewLayout);

	//Create text for Reviews
	ReviewsLabel = new QLabel("Reviews of Product");
	ReviewLayout->addWidget(ReviewsLabel);

	//Create empty list that will have reviews of products from search
	ReviewList = new QListWidget();
	ReviewLayout->addWidget(ReviewList);

	//Create add reviews layout
	AddReviewLayout = new QVBoxLayout();
	OverallLayout->addLayout(AddReviewLayout);

	//Create text for adding reviews
	AddReviewsLabel = new QLabel("Add a Review Section");
	AddReviewLayout->addWidget(AddReviewsLabel);

	//Creating text for adding rating
	AddReviewsRating = new QLabel("Enter an integer between 1-5");
	AddReviewLayout->addWidget(AddReviewsRating);

	//Creating line edit to enter rating of product
	RatingLine = new QLineEdit();
	AddReviewLayout->addWidget(RatingLine);

	//Creating text for adding date
	AddReviewsDate = new QLabel("Enter a date: YYYY-MM-DD");
	AddReviewLayout->addWidget(AddReviewsDate);

	//Creating line edit to enter date of product
	DateLine = new QLineEdit();
	AddReviewLayout->addWidget(DateLine);

	//Creating text for string of text
	AddReviewsText = new QLabel("Type in review text");
	AddReviewLayout->addWidget(AddReviewsText);

	//Creating line edit to enter string of text of product
	TextLine = new QLineEdit();
	AddReviewLayout->addWidget(TextLine);

	AddReviewButton = new QPushButton("ADD REVIEW");
	connect(AddReviewButton, SIGNAL(clicked()), this, SLOT(ADDREVIEW()));
	AddReviewLayout->addWidget(AddReviewButton);

	setLayout(OverallLayout);
}