Skip to content
Snippets Groups Projects

WIP: #57 Én databaseinstans og testmodus for database

Closed Anders H. Rebner requested to merge database-test-modus into master
2 unresolved threads
Files
6
+ 8
7
"""Codebook.
"""GUI-interface towards database-table 'CodeBook'.
Contains functionality for viewing, editing and inserting new rows
in the database-table 'CodeBook'.
@@ -6,7 +6,6 @@ in the database-table 'CodeBook'.
from PySide2.QtWidgets import QTableView
from PySide2.QtSql import QSqlDatabase, QSqlTableModel
from PySide2.QtCore import Qt
from soitool.database import DBPATH # , Database
from soitool.style import CODEBOOK_HEADER_FONT, CODEBOOK_HEADER_BACKGROUND_CSS
# Name and type of database
@@ -17,17 +16,19 @@ DBTYPE = "QSQLITE"
class CodeBookTableView(QTableView):
"""TableView with a model of the 'codebook'-table from database.
This modified QTableView creates a CodeBookTableModel,
which reads the codebook-table.
User can add, edit and insert entries to the database through this View.
This modified QTableView creates a CodeBookTableModel, which reads the
codebook-table. User can add, edit, delete and insert entries through this
view.
Parameter 'database' should be an instance of soitool.database.Database,
and is used to create a QSqlDatabase from the database-file.
Raises RuntimeError if database does not open.
"""
def __init__(self):
def __init__(self, database):
super().__init__()
db = QSqlDatabase.addDatabase(DBTYPE, CONNAME)
db.setDatabaseName(DBPATH)
db.setDatabaseName(database.db_path)
if not db.open():
raise RuntimeError("Could not open database.")
Loading