KTutorial
0.5.1
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00003 * Copyright (C) 2009 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00004 * Copyright (C) 2010 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00005 * Copyright (C) 2012 by Daniel Calviño Sánchez <danxuliu@gmail.com> * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; If not, see <http://www.gnu.org/licenses/>. * 00019 ***************************************************************************/ 00020 00021 #include "TutorialListModel.h" 00022 00023 #include <KLocalizedString> 00024 00025 #include "../TutorialInformation.h" 00026 #include "../TutorialManager.h" 00027 00028 namespace ktutorial { 00029 namespace view { 00030 00031 //public: 00032 00033 int TutorialListModel::rowCount(const QModelIndex& /*parent = QModelIndex()*/) const { 00034 return mTutorialManager->tutorialInformations().count(); 00035 } 00036 00037 QVariant TutorialListModel::data(const QModelIndex& index, int role) const { 00038 if (role != Qt::DisplayRole) { 00039 return QVariant(); 00040 } 00041 00042 const TutorialInformation* tutorialInformation = 00043 getTutorialInformationForIndex(index); 00044 if (tutorialInformation == 0) { 00045 return QVariant(); 00046 } 00047 00048 return tutorialInformation->name(); 00049 } 00050 00051 QVariant TutorialListModel::headerData(int section, Qt::Orientation /*orientation*/, 00052 int role /*= Qt::DisplayRole*/) const { 00053 if (role != Qt::DisplayRole) { 00054 return QVariant(); 00055 } 00056 00057 if (section != 0) { 00058 return QVariant(); 00059 } 00060 00061 return i18nc("@title:column", "Tutorials name"); 00062 } 00063 00064 const TutorialInformation* TutorialListModel::getTutorialInformationForIndex( 00065 const QModelIndex& index) const { 00066 if (!index.isValid()) { 00067 return 0; 00068 } 00069 00070 if (index.row() >= mTutorialManager->tutorialInformations().count()) { 00071 return 0; 00072 } 00073 00074 return mTutorialManager->tutorialInformations()[index.row()]; 00075 } 00076 00077 } 00078 }