1 /***************************************************** vim:set ts=4 sw=4 sts=4:
2 Model for listing Talkers, typically in a QTreeView.
4 Copyright : (C) 2005 by Gary Cramblitt <garycramblitt@comcast.net>
6 Original author: Gary Cramblitt <garycramblitt@comcast.net>
7 Current Maintainer: Gary Cramblitt <garycramblitt@comcast.net>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 *******************************************************************************/
24 #ifndef TALKERLISTMODEL_H
25 #define TALKERLISTMODEL_H
28 #include <QtCore/QAbstractListModel>
29 #include <QtCore/QModelIndex>
32 #include <kdemacros.h>
35 #include "talkercode.h"
40 * Model for list of configured talkers.
41 * Intended for use with talkerList QTreeView.
42 * Each row of the displayed view corresponds to a TalkerCode in the model.
44 class KDE_EXPORT TalkerListModel
: public QAbstractListModel
48 explicit TalkerListModel(TalkerCode::TalkerCodeList talkers
= TalkerCode::TalkerCodeList(), QObject
*parent
= 0);
50 // Inherited method overrides.
51 int rowCount(const QModelIndex
&parent
= QModelIndex()) const;
52 int columnCount(const QModelIndex
&parent
= QModelIndex()) const;
53 QModelIndex
index(int row
, int column
, const QModelIndex
&parent
= QModelIndex()) const;
54 QModelIndex
parent(const QModelIndex
& index
) const;
55 QVariant
data(const QModelIndex
&index
, int role
) const;
56 QVariant
headerData(int section
, Qt::Orientation orientation
,
57 int role
= Qt::DisplayRole
) const;
58 Qt::ItemFlags
flags(const QModelIndex
&index
) const;
59 bool removeRow(int row
, const QModelIndex
& parent
= QModelIndex());
62 * The list of TalkerCodes for this model.
64 const TalkerCode::TalkerCodeList
datastore() const { return m_talkerCodes
; }
65 void setDatastore(TalkerCode::TalkerCodeList talkers
= TalkerCode::TalkerCodeList());
67 * Returns the TalkerCode for a specified row of the model/view.
69 TalkerCode
getRow(int row
) const;
71 * Adds a new row to the model/view containing the specified TalkerCode.
73 bool appendRow(TalkerCode
& talker
);
75 * Updates a row of the model/view with information from specified TalkerCode.
77 bool updateRow(int row
, TalkerCode
& talker
);
79 * Swaps two rows of the model/view.
81 bool swap(int i
, int j
);
83 * Clears the model/view.
87 * Returns the highest ID of all TalkerCodes. Useful when generating a new TalkerCode.
89 int highestTalkerId() const { return m_highestTalkerId
; }
91 * Loads the TalkerCodes into the model/view from the config file.
92 * @param config Pointer to KConfig object holding the config file info.
94 void loadTalkerCodesFromConfig(KConfig
* config
);
97 // Returns the displayable portion of the talkerCode corresponding to a column of the view.
98 QVariant
dataColumn(const TalkerCode
& talkerCode
, int column
) const;
99 // QList of TalkerCodes.
100 TalkerCode::TalkerCodeList m_talkerCodes
;
101 // Highest talker ID. Used to generate a new ID.
102 int m_highestTalkerId
;
105 #endif // TALKERLISTMODEL_H