Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 87 → Rev 88

/trunk/TrainDatabase/traintablemodel.cpp
1,6 → 1,8
#include <QDebug>
#include <QPushButton>
 
#include "traintablemodel.h"
#include "dbexception.h"
 
TrainTableModel::TrainTableModel( DBAccess* access, QObject *parent) :
QAbstractTableModel(parent)
32,6 → 34,7
case 2: return record->getCost();
case 3: return QString( record->getStockType().c_str() );
case 4: return QString( record->getNotes().c_str() );
case 5: return QString( "Delete" );
}
}
return QVariant();
46,6 → 49,7
case 2: return QString( "Cost" );
case 3: return QString( "Type" );
case 4: return QString( "Notes" );
case 5: return QString( "Delete" );
}
}
}
74,7 → 78,14
case 4: record->setNotes( value.toString().toStdString() );
break;
}
try{
access->updateRecord( record );
}catch( DBException ex ){
qDebug() << ex.what();
}
}
 
emit dataChanged( index, index );
return true;
}
 
84,3 → 95,21
 
emit dataChanged( topIndex, bottomIndex );
}
 
void TrainTableModel::updateLastRecord(){
beginInsertRows( QModelIndex(), access->getNumberOfRecords(), access->getNumberOfRecords() );
endInsertRows();
 
emit dataChanged( QModelIndex(), QModelIndex() );
}
 
void TrainTableModel::deleteRow( int row ){
TrainRecord* rec = access->getRecord( row);
 
beginRemoveRows( QModelIndex(), rec->getKey(), rec->getKey() );
endRemoveRows();
 
access->deleteRecord( rec );
 
emit dataChanged( QModelIndex(), QModelIndex() );
}