TreeModel.h

00001 /*
00002  * @(#)TreeModel.h  0.2.0 / 2007-12-17
00003  *
00004  * Copyright (c) 2007, ETF and contributors. All rights reserved.
00005  *
00006  * This software is licensed under the LGPL, version 2.1, license.
00007  * A copy of the license is included in the file LICENSE-LGPL.txt.
00008  */
00009 #ifndef TREEMODEL_H
00010 #define TREEMODEL_H
00011 
00012 #include "JavaQxQSwing.h"
00013 
00014 /*^**************************************************************************^*/
00015 /*- TreeNode Class.                                                          -*/
00016 /*^**************************************************************************^*/
00017 
00018 class JQTreeBridge;
00019 
00026 class JAVAQX_EXPORT TreeNode
00027 {
00028 public:
00029   TreeNode();
00030   TreeNode(jobject node, TreeNode *parent);
00031   virtual ~TreeNode();
00032 public:
00033   jobject node();
00034   TreeNode *parent();
00035   QVariant data();
00036   int row();
00037   int childCount();
00038   bool isLeaf();
00039   TreeNode *child(int row);
00040   void addChild(TreeNode *child);
00041 public:
00042   static void initialize(JNIEnv *env, jclass cls);
00043 private:
00044   void expand();
00045 private:
00046   jobject m_node;
00047   TreeNode *m_parentNode;
00048   int m_childCount;
00049   QList<TreeNode *> m_childNodes;
00050 private:
00051   static jmethodID sm_getChildCountMID;
00052   static jmethodID sm_getChildAtMID;
00053 };
00054 
00055 /*^**************************************************************************^*/
00056 /*- TreeModel Class.                                                         -*/
00057 /*^**************************************************************************^*/
00058 
00065 class JAVAQX_EXPORT TreeModel : public QAbstractItemModel
00066 {
00067 public:
00068   TreeModel(JQTreeBridge *treeBridge);
00069   virtual ~TreeModel();
00070 public:
00071   TreeNode *getRootNode();
00072 public:
00073   Qt::ItemFlags flags(const QModelIndex &index) const;
00074   QModelIndex parent(const QModelIndex &index) const;
00075   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00076   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00077   QModelIndex index(int row, int column,
00078                     const QModelIndex &parent = QModelIndex()) const;
00079   QVariant data(const QModelIndex &index, int role) const;
00080   QVariant headerData(int section, Qt::Orientation orientation,
00081                       int role = Qt::DisplayRole) const;
00082 private:
00083   JQTreeBridge *m_treeBridge;
00084   TreeNode *m_rootNode;
00085   TreeNode *m_modelRootNode;
00086 };
00087 
00088 #endif // TREEMODEL_H
00089 
00090 /*^*****************************************************************************
00091   File History:
00092 
00093  - 2007-12-17 15:09:19 Slobodan
00094    Initial version
00095 
00096 *****************************************************************************^*/

Copyright © 2007 ETF and contributors. All Rights Reserved.