Reformat Session

remotes/origin/HEAD
markuspg 6 years ago
parent 688c1ee3fd
commit c3e623f236

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -19,6 +19,7 @@
#include <QDebug>
#include "session.h"
#include "sessionsmodel.h"
lc::SessionsModel::SessionsModel(QObject *argParent) :
@ -26,16 +27,19 @@ lc::SessionsModel::SessionsModel( QObject *argParent ) :
{
}
lc::Session *lc::SessionsModel::back() const {
lc::Session *lc::SessionsModel::back() const
{
return sessionsList.back();
}
int lc::SessionsModel::columnCount(const QModelIndex &parent) const {
int lc::SessionsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 2;
}
QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const {
QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant{};
@ -48,7 +52,9 @@ QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const {
return QVariant{};
}
QVariant lc::SessionsModel::headerData(int section, Qt::Orientation orientation, int role) const {
QVariant lc::SessionsModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0:
@ -66,21 +72,24 @@ QVariant lc::SessionsModel::headerData(int section, Qt::Orientation orientation,
return QVariant{};
}
void lc::SessionsModel::push_back( Session *argSession ) {
void lc::SessionsModel::push_back(Session *argSession)
{
connect( argSession, &Session::SessionFinished,
this, &SessionsModel::RemoveSession );
argSession->setParent(this);
sessionsList.push_back(argSession);
}
void lc::SessionsModel::RemoveSession( Session *argSession ) {
void lc::SessionsModel::RemoveSession(Session *argSession)
{
if (sessionsList.removeAll(argSession)) {
qDebug() << "Successfully removed" << argSession << "from lc::SessionsModel";
argSession->deleteLater();
}
}
int lc::SessionsModel::rowCount(const QModelIndex &parent) const {
int lc::SessionsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return sessionsList.length();
}

@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Markus Prasser
* Copyright 2014-2018 Markus Prasser, Tobias Weiss
*
* This file is part of Labcontrol.
*
@ -22,14 +22,16 @@
#include <QAbstractTableModel>
#include "session.h"
namespace lc {
class SessionsModel : public QAbstractTableModel {
class Session;
class SessionsModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit SessionsModel(QObject *parent = 0);
explicit SessionsModel(QObject *parent = nullptr);
SessionsModel(const SessionsModel &) = delete;
Session *back() const;
int columnCount(const QModelIndex &parent) const;
@ -38,10 +40,6 @@ public:
void push_back(Session *argSession);
int rowCount(const QModelIndex &parent) const;
signals:
public slots:
private:
QList<Session *> sessionsList;
@ -49,6 +47,6 @@ private slots:
void RemoveSession(Session *argSession);
};
}
} // namespace lc
#endif // SESSIONSMODEL_H

Loading…
Cancel
Save