Reformat Session

remotes/origin/HEAD
markuspg 8 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. * This file is part of Labcontrol.
* *
@ -19,6 +19,7 @@
#include <QDebug> #include <QDebug>
#include "session.h"
#include "sessionsmodel.h" #include "sessionsmodel.h"
lc::SessionsModel::SessionsModel(QObject *argParent) : 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(); return sessionsList.back();
} }
int lc::SessionsModel::columnCount(const QModelIndex &parent) const { int lc::SessionsModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent); Q_UNUSED(parent);
return 2; 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()) if (!index.isValid())
return QVariant{}; return QVariant{};
@ -48,7 +52,9 @@ QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const {
return QVariant{}; 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) { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) { switch (section) {
case 0: case 0:
@ -66,21 +72,24 @@ QVariant lc::SessionsModel::headerData(int section, Qt::Orientation orientation,
return QVariant{}; return QVariant{};
} }
void lc::SessionsModel::push_back( Session *argSession ) { void lc::SessionsModel::push_back(Session *argSession)
{
connect( argSession, &Session::SessionFinished, connect( argSession, &Session::SessionFinished,
this, &SessionsModel::RemoveSession ); this, &SessionsModel::RemoveSession );
argSession->setParent(this); argSession->setParent(this);
sessionsList.push_back(argSession); sessionsList.push_back(argSession);
} }
void lc::SessionsModel::RemoveSession( Session *argSession ) { void lc::SessionsModel::RemoveSession(Session *argSession)
{
if (sessionsList.removeAll(argSession)) { if (sessionsList.removeAll(argSession)) {
qDebug() << "Successfully removed" << argSession << "from lc::SessionsModel"; qDebug() << "Successfully removed" << argSession << "from lc::SessionsModel";
argSession->deleteLater(); argSession->deleteLater();
} }
} }
int lc::SessionsModel::rowCount(const QModelIndex &parent) const { int lc::SessionsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent); Q_UNUSED(parent);
return sessionsList.length(); 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. * This file is part of Labcontrol.
* *
@ -22,14 +22,16 @@
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include "session.h"
namespace lc { namespace lc {
class SessionsModel : public QAbstractTableModel { class Session;
class SessionsModel : public QAbstractTableModel
{
Q_OBJECT Q_OBJECT
public: public:
explicit SessionsModel(QObject *parent = 0); explicit SessionsModel(QObject *parent = nullptr);
SessionsModel(const SessionsModel &) = delete; SessionsModel(const SessionsModel &) = delete;
Session *back() const; Session *back() const;
int columnCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const;
@ -38,10 +40,6 @@ public:
void push_back(Session *argSession); void push_back(Session *argSession);
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const;
signals:
public slots:
private: private:
QList<Session *> sessionsList; QList<Session *> sessionsList;
@ -49,6 +47,6 @@ private slots:
void RemoveSession(Session *argSession); void RemoveSession(Session *argSession);
}; };
} } // namespace lc
#endif // SESSIONSMODEL_H #endif // SESSIONSMODEL_H

Loading…
Cancel
Save