00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "omglocality.h"
00022 #include "omglocalitiesmodel.h"
00023 #include <QStringList>
00024 #include <QFileInfo>
00025
00026 OmgLocalitiesModel::OmgLocalitiesModel()
00027 {
00028
00029 }
00030 OmgLocalitiesModel::~OmgLocalitiesModel()
00031 {
00032
00033 }
00034 void OmgLocalitiesModel::setModel(OmgModel * const thepNicheModel)
00035 {
00036 if (rowCount() > 0)
00037 {
00038
00039 beginRemoveRows(QModelIndex(),0,rowCount()-1);
00040 endRemoveRows();
00041 }
00042 if (columnCount() > 0)
00043 {
00044 beginRemoveColumns(QModelIndex(),0,columnCount()-1);
00045 endRemoveColumns();
00046 }
00047
00048 mpNicheModel = thepNicheModel;;
00049
00050
00051 if (rowCount() > 1)
00052 {
00053 beginInsertRows(QModelIndex(),0,rowCount()-1);
00054 endInsertRows();
00055 }
00056 if (columnCount() > 1)
00057 {
00058 beginInsertColumns(QModelIndex(),0,columnCount()-1);
00059 endInsertColumns();
00060 }
00061 }
00062 int OmgLocalitiesModel::columnCount ( const QModelIndex & theParent ) const
00063 {
00064
00065
00066
00067
00068
00069
00070
00071 if (!mpNicheModel)
00072 {
00073 return 0;
00074 }
00075
00076 if (mpNicheModel->localities().count() < 1)
00077 {
00078 return 0;
00079 }
00080 else
00081 {
00082 int myCount = mpNicheModel->localities().at(0).samples().count() + 4;
00083 return myCount;
00084 }
00085 }
00086 int OmgLocalitiesModel::rowCount ( const QModelIndex & theParent ) const
00087 {
00088 if (!mpNicheModel)
00089 {
00090 return 0;
00091 }
00092 if (!mpNicheModel->localities().count())
00093 {
00094 return 0;
00095 }
00096 return mpNicheModel->localities().count();
00097 }
00098 QVariant OmgLocalitiesModel::data ( const QModelIndex & theIndex,
00099 int theRole ) const
00100 {
00101 if (!mpNicheModel)
00102 {
00103 return QVariant();
00104 }
00105 if (!theIndex.isValid())
00106 {
00107 return QVariant();
00108 }
00109 if (theRole != Qt::DisplayRole)
00110 {
00111 return QVariant();
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 if (!mpNicheModel->localities().count())
00123 {
00124 return QVariant();
00125 }
00126 if (theIndex.row() > mpNicheModel->localities().count())
00127 {
00128 return QVariant();
00129 }
00130 if (theIndex.column() == 0 )
00131 {
00132
00133 return QVariant(mpNicheModel->localities().at(theIndex.row()).id());
00134 }
00135 if (theIndex.column() == 1 )
00136 {
00137
00138 return QVariant(mpNicheModel->localities().at(theIndex.row()).longitude());
00139 }
00140 if (theIndex.column() == 2 )
00141 {
00142
00143 return QVariant(mpNicheModel->localities().at(theIndex.row()).latitude());
00144 }
00145 if (theIndex.column() == 3 )
00146 {
00147
00148 return QVariant(mpNicheModel->localities().at(theIndex.row()).abundance());
00149 }
00150
00151
00152 unsigned int mySampleNumber = theIndex.column() - 4;
00153 return QVariant(mpNicheModel->localities().at(theIndex.row()).samples().at(mySampleNumber));
00154 }
00155
00156
00157 QVariant OmgLocalitiesModel::headerData(int theSection, Qt::Orientation theOrientation,
00158 int theRole) const
00159 {
00160 if (!mpNicheModel)
00161 {
00162 return QVariant();
00163 }
00164 if (theRole != Qt::DisplayRole)
00165 {
00166 return QVariant();
00167 }
00168 if (theOrientation == Qt::Horizontal)
00169 {
00170
00171 if (theSection==0)
00172 {
00173 return QString(tr("ID"));
00174 }
00175 if (theSection==1)
00176 {
00177 return QString(tr("Lon"));
00178 }
00179 if (theSection==2)
00180 {
00181 return QString(tr("Lat"));
00182 }
00183 if (theSection==3)
00184 {
00185 return QString(tr("Count"));
00186 }
00187
00188 QStringList myList = mpNicheModel->creationLayerNames();
00189
00190
00191 if (myList.count() > (theSection-4))
00192 {
00193 QFileInfo myFileInfo(myList.at(theSection-4));
00194 return QString(myFileInfo.baseName());
00195 }
00196 else
00197 {
00198
00199 return QString("Layer %1").arg(theSection);
00200 }
00201 }
00202 else
00203 {
00204
00205 return QString("%1").arg(theSection);
00206 }
00207 return QVariant();
00208 }