#include "main_window.h" #include "date_time_delegate.h" // Set up the table view // #define ENABLE_SELECTION // Uncomment to enable highlighting #define DISABLE_SELECTION // Uncomment to disable highlighting MainWindow::MainWindow(qint32 userId, qint32 accessLevel, QWidget *parent) : QMainWindow(parent), userId_(userId), accessLevel_(accessLevel) { qInfo() << "Initializing main window..."; setupUi(this); configureAllTableViews(); configureAccessLevel(); qInfo() << "Main window initialized successfully"; }; void MainWindow::configureAccessLevel() { qInfo() << "Configuring access level..."; if (accessLevel_ < 1) { qCritical() << "Access level is less than 1"; QCoreApplication::quit(); } qInfo() << "Access level is" << accessLevel_; // Full access to all system functionalities // Manage system settings and user permissions // Can perform all actions of lower roles if (accessLevel_ < 100) { // Lower than Super Administrator } // Delete records (sessions, tickets, halls, movies, genres) // Modify system-critical data // Has all permissions of lower roles if (accessLevel_ < 82) { // Lower than Data Administrator findChild("DangerZonePage")->setDisabled(true); } // Add new sessions, movies, halls, and genres // Manage show schedules // Has all permissions of lower roles if (accessLevel_ < 64) { // Lower than Repertoire Manager findChild("DirectoriesManagementPage")->setDisabled(true); findChild("SessionManagementPage")->setDisabled(true); } // Edit session, movie, hall, and genre information // Adjust ticket prices // Has all permissions of lower roles if (accessLevel_ < 46) { // Lower than Data Editor } // View ticket sales // View attendance statistics // Has all permissions of lower roles if (accessLevel_ < 28) { // Lower than Sales Manager findChild("ReportsPage")->setDisabled(true); } // Sell tickets // Ticket refunds if (accessLevel_ < 10) { // Lower than Cashier findChild("MainWindow")->setDisabled(true); } // Nothing qInfo() << "Access level configured successfully"; } void MainWindow::configureAllTableViews() { qInfo() << "Configuring all QAbstractItemViews..."; // Find all QAbstractItemView children auto tableViews = findChildren(); for (QAbstractItemView *abstractItemView : tableViews) { // Check if the view is a QTableView if (auto *tableView = qobject_cast(abstractItemView)) { loadDefaultConfiguration(tableView); } } qInfo() << "All QAbstractItemViews configured successfully"; } void MainWindow::MainWindow::disableSelection(QTableView *tableView) { qInfo() << "Disabling selection for QAbstractItemView:" << tableView->objectName(); // Disable selection tableView->setSelectionMode(QAbstractItemView::NoSelection); // Clear the selection tableView->clearSelection(); // Disable focus tableView->setFocusPolicy(Qt::NoFocus); } void enableSelection(QTableView *tableView) { qInfo() << "Enabling selection for QAbstractItemView:" << tableView->objectName(); // Set the selection behavior tableView->setSelectionBehavior(QAbstractItemView::SelectRows); // Set the selection mode tableView->setSelectionMode(QAbstractItemView::SingleSelection); } void MainWindow::loadDefaultConfiguration(QTableView *tableView) { qInfo() << "Loading default configuration for QAbstractItemView:" << tableView->objectName(); DateTimeDelegate *dateTimeDelegate = new DateTimeDelegate(this); tableView->setItemDelegate(dateTimeDelegate); QHeaderView *horizontalHeader = tableView->horizontalHeader(); // Disable horizontal header highlight horizontalHeader->setHighlightSections(false); // Set the horizontal header to resize to contents horizontalHeader->setSectionResizeMode(QHeaderView::ResizeToContents); tableView->setSortingEnabled(true); // Enable sorting tableView->sortByColumn(0, Qt::AscendingOrder); // Disable editing tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); // Set the scroll mode tableView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); // Enable alternating row colors tableView->setAlternatingRowColors(true); #ifdef ENABLE_SELECTION enableSelection(view); #elif defined(DISABLE_SELECTION) disableSelection(tableView); #else #error "Define ENABLE_SELECTION or DISABLE_SELECTION" #endif }