def removeRow(self, row, index): """Remove a row the model. Call values_edited to update the totals in the Money Left Over table.""" if self._data != [] and index.row() != len(self._data) - 1: self._data.pop(row) else: QMessageBox.information(QApplication.activeWindow(), "No Row Selected", "No row selected for deletion.") self.values_edited.emit() self.layoutChanged.emit() return True
def connectToDatabase(self): """Create a QSqlDatabase object and connect to the database.""" database = QSqlDatabase.addDatabase("QSQLITE") database.setDatabaseName("data/inventory.db") database.setConnectOptions("QSQLITE_ENABLE_REGEXP") if not database.open(): error = database.lastError().text() QMessageBox.critical(QApplication.activeWindow(), "Connection Error", f"Something went wrong: {error}") sys.exit(1) # Handle if the database is missing and SQLite creates a new, # empty database tables_needed = { "Staff", "Customers", "Orders", "Products", "Categories" } no_tables = tables_needed - set(database.tables()) if no_tables: QMessageBox.critical(QApplication.activeWindow(), "Error", f'{no_tables} missing.') sys.exit(1)