demos/interview/model.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2004-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the demonstration applications of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef MODEL_H
00025 #define MODEL_H
00026 
00027 #include <QAbstractItemModel>
00028 #include <QVector>
00029 
00030 class Model : public QAbstractItemModel
00031 {
00032     Q_OBJECT
00033 
00034 public:
00035     Model(int rows, int columns, QObject *parent = 0);
00036     ~Model();
00037 
00038     QModelIndex index(int row, int column, const QModelIndex &parent) const;
00039     QModelIndex parent(const QModelIndex &child) const;
00040 
00041     int rowCount(const QModelIndex &parent) const;
00042     int columnCount(const QModelIndex &parent) const;
00043 
00044     QVariant data(const QModelIndex &index, int role) const;
00045     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00046 
00047     bool hasChildren(const QModelIndex &parent) const;
00048     Qt::ItemFlags flags(const QModelIndex &index) const;
00049     bool isDragEnabled(const QModelIndex &index) const;
00050 
00051 private:
00052 
00053     struct Node
00054     {
00055   Node(Node *parent = 0) : parent(parent), children(0) {}
00056   ~Node() { delete children; }
00057   Node *parent;
00058   QVector<Node> *children;
00059     };
00060 
00061     Node *node(int row, Node *parent) const;
00062     Node *parent(Node *child) const;
00063     int row(Node *node) const;
00064 
00065     int rc, cc;
00066     QVector<Node> *tree;
00067 };
00068 
00069 #endif

Generated on Thu Mar 15 11:52:33 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1