This repository was archived by the owner on Apr 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrentalmanagementdialog.cpp
More file actions
105 lines (80 loc) · 4.29 KB
/
Copy pathrentalmanagementdialog.cpp
File metadata and controls
105 lines (80 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "rentalmanagementdialog.h"
#include "addrentaldialog.h"
#include <QMessageBox>
#include <QHeaderView>
RentalManagementDialog::RentalManagementDialog(QWidget *parent) : QDialog(parent), model(new QStandardItemModel(this)) {
QLabel *searchLabel = new QLabel("Search by name:");
rentalsView = new QTableView(this);
searchLineEdit = new QLineEdit(this);
searchButton = new QPushButton("Search", this);
addRentalButton = new QPushButton("Add Rental", this);
searchLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
searchLineEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
searchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
addRentalButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
searchLineEdit->setStyleSheet("QLineEdit {border-width: 5px; border-radius: 8px; border-color: #81B2D9;}");
searchButton->setStyleSheet("QPushButton {width: 150px; min-width: 150px; height: 30px; min-height: 30px; border-radius: 15px; background: #81B2D9; color: #F5F5F5; font-family: Inter; font-size: 20px; font-style: normal; font-weight: 600; line-height: normal;}""QPushButton:hover {background: #629FD0;}");
addRentalButton->setStyleSheet("QPushButton {width: 175px; min-width: 175px; height: 30px; min-height: 30px; border-radius: 15px; background: #81B2D9; color: #F5F5F5; font-family: Inter; font-size: 20px; font-style: normal; font-weight: 600; line-height: normal;}""QPushButton:hover {background: #629FD0;}");
rentalsView->setStyleSheet("QTableWidget {font-family: Inter; font-size: 15px; font-weight: 500; line-height: normal;}");
rentalsView->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color: #81B2D9;font-family: Inter; font-size: 15px; font-weight: 500; line-height: normal;}");
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QHBoxLayout *searchLayout = new QHBoxLayout();
searchLayout->addWidget(searchLabel);
searchLayout->addWidget(searchLineEdit);
searchLayout->addWidget(searchButton);
mainLayout->addLayout(searchLayout);
mainLayout->addWidget(rentalsView);
mainLayout->addWidget(addRentalButton);
setLayout(mainLayout);
connect(searchButton, &QPushButton::clicked, this, &RentalManagementDialog::onSearchClicked);
connect(addRentalButton, &QPushButton::clicked, this, &RentalManagementDialog::onAddRentalClicked);
resize(800,600);
loadRentalsData();
}
void RentalManagementDialog::loadRentalsData() {
model->clear();
model->setHorizontalHeaderLabels({"Rental ID", "Customer Name", "Movie ID", "Rental Date", "Return Date", "Status"});
QFile file("rentals.csv");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::warning(this, "Warning", "Cannot open rentals file.");
return;
}
QTextStream in(&file);
QString headerLine = in.readLine(); // Read the header line but do not process it
while (!in.atEnd()) {
QString line = in.readLine();
QList<QStandardItem *> standardItemsList;
for (const QString &field : line.split(',')) {
standardItemsList.append(new QStandardItem(field));
}
model->appendRow(standardItemsList);
}
file.close();
rentalsView->setModel(model);
rentalsView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
void RentalManagementDialog::onSearchClicked() {
filterRentals(searchLineEdit->text());
}
void RentalManagementDialog::filterRentals(const QString &searchText) {
for (int i = 0; i < model->rowCount(); ++i) {
bool match = false;
for (int j = 0; j < model->columnCount(); ++j) {
if (model->item(i, j)->text().contains(searchText, Qt::CaseInsensitive)) {
match = true;
break;
}
}
rentalsView->setRowHidden(i, !match);
}
}
void RentalManagementDialog::onAddRentalClicked() {
AddRentalDialog addRentalDialog(this);
// Execute the dialog and check if it was accepted
if (addRentalDialog.exec() == QDialog::Accepted) {
// If the rental was successfully added, update the rentals table
// You might need to adjust this based on how you're managing data
loadRentalsData(); // Reload or update the data in the rentals table
emit dataChanged();
}
}