|
|
/*------------------------------------------------------------------------------
|
|
|
-- This file is a part of the QLop Software
|
|
|
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
|
|
|
--
|
|
|
-- This program is free software; you can redistribute it and/or modify
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
|
|
-- (at your option) any later version.
|
|
|
--
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
-- GNU General Public License for more details.
|
|
|
--
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
-- along with this program; if not, write to the Free Software
|
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
-------------------------------------------------------------------------------*/
|
|
|
/*-- Author : Alexis Jeandet
|
|
|
-- Mail : alexis.jeandet@member.fsf.org
|
|
|
----------------------------------------------------------------------------*/
|
|
|
#include "qlopdatabaseviewermodel.h"
|
|
|
|
|
|
QLopDataBaseViewerModel::QLopDataBaseViewerModel(QObject *parent)
|
|
|
: QAbstractTableModel(parent)
|
|
|
{
|
|
|
beginResetModel();
|
|
|
endResetModel();
|
|
|
}
|
|
|
|
|
|
QLopDataBaseViewerModel::~QLopDataBaseViewerModel()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
int QLopDataBaseViewerModel::rowCount(const QModelIndex &parent) const
|
|
|
{
|
|
|
return QLopDataBase::count();
|
|
|
}
|
|
|
|
|
|
int QLopDataBaseViewerModel::columnCount(const QModelIndex &parent) const
|
|
|
{
|
|
|
return 5;
|
|
|
}
|
|
|
|
|
|
QVariant QLopDataBaseViewerModel::data(const QModelIndex &index, int role) const
|
|
|
{
|
|
|
if (!index.isValid() || role != Qt::DisplayRole)
|
|
|
return QVariant();
|
|
|
QLopData* data=QLopDataBase::self()->getDataFromIdex(index.row());
|
|
|
if(data)
|
|
|
{
|
|
|
switch (index.column()) {
|
|
|
case 0:
|
|
|
return data->name;
|
|
|
break;
|
|
|
case 1:
|
|
|
return data->source;
|
|
|
break;
|
|
|
case 2:
|
|
|
return data->typeStr();
|
|
|
break;
|
|
|
case 3:
|
|
|
return data->unit;
|
|
|
break;
|
|
|
case 4:
|
|
|
return data->size();
|
|
|
break;
|
|
|
default:
|
|
|
return data->name;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
else QVariant();
|
|
|
}
|
|
|
|
|
|
QVariant QLopDataBaseViewerModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
{
|
|
|
//if (role == Qt::SizeHintRole)
|
|
|
// return QSize(1, 1);
|
|
|
if(orientation==Qt::Horizontal && role==Qt::DisplayRole)
|
|
|
{
|
|
|
switch (section) {
|
|
|
case 0:
|
|
|
return QVariant("Name");
|
|
|
break;
|
|
|
case 1:
|
|
|
return QVariant("Source");
|
|
|
break;
|
|
|
case 2:
|
|
|
return QVariant("Type");
|
|
|
break;
|
|
|
case 3:
|
|
|
return QVariant("Unit");
|
|
|
break;
|
|
|
case 4:
|
|
|
return QVariant("Size");
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return QVariant();
|
|
|
}
|
|
|
|
|
|
void QLopDataBaseViewerModel::DBChanged()
|
|
|
{
|
|
|
beginResetModel();
|
|
|
endResetModel();
|
|
|
}
|
|
|
|
|
|
|