Reformat Session

remotes/origin/HEAD
markuspg 7 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,23 +19,27 @@
#include <QDebug> #include <QDebug>
#include "session.h"
#include "sessionsmodel.h" #include "sessionsmodel.h"
lc::SessionsModel::SessionsModel( QObject *argParent ) : lc::SessionsModel::SessionsModel(QObject *argParent) :
QAbstractTableModel{ argParent } QAbstractTableModel{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{};
@ -43,14 +47,16 @@ QVariant lc::SessionsModel::data(const QModelIndex &index, int role) const {
return QVariant{}; return QVariant{};
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return sessionsList.at( index.row() )->GetDataItem( index.column() ); return sessionsList.at(index.row())->GetDataItem(index.column());
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:
return tr("zTree Version"); return tr("zTree Version");
case 1: case 1:
@ -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,33 +22,31 @@
#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;
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
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;
private slots: private slots:
void RemoveSession( Session *argSession ); void RemoveSession(Session *argSession);
}; };
} } // namespace lc
#endif // SESSIONSMODEL_H #endif // SESSIONSMODEL_H

Loading…
Cancel
Save