36 lines
866 B
C++
36 lines
866 B
C++
|
|
#include "halls_model.h"
|
||
|
|
|
||
|
|
#include <QSqlError>
|
||
|
|
|
||
|
|
HallsModel::HallsModel(QObject *parent, const QSqlDatabase &database)
|
||
|
|
: BaseSqlTableModel(parent, database) {}
|
||
|
|
|
||
|
|
void HallsModel::initialize() {
|
||
|
|
|
||
|
|
setTable("halls");
|
||
|
|
|
||
|
|
setEditStrategy(QSqlTableModel::OnFieldChange);
|
||
|
|
|
||
|
|
bool success = select();
|
||
|
|
if (!success) {
|
||
|
|
qWarning() << "Error:" << lastError().text();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
QVariant HallsModel::headerData(int section, Qt::Orientation orientation,
|
||
|
|
int role) const {
|
||
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||
|
|
switch (section) {
|
||
|
|
case HallsColumns::Id:
|
||
|
|
return tr("ID");
|
||
|
|
case HallsColumns::Name:
|
||
|
|
return tr("Name");
|
||
|
|
case HallsColumns::Capacity:
|
||
|
|
return tr("Capacity");
|
||
|
|
default:
|
||
|
|
return QVariant();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return QSqlTableModel::headerData(section, orientation, role);
|
||
|
|
}
|