ij-16.png   inspectorJ -- JavaTM Profiler
sf project site browse source checkout source
SourceForge.net Logo



src/inspectorj/model/classtablemodel.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   inspectorJ - java profiler                                            *
00003  *   Copyright (C) 2007 by  James May
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include "inspectorj/model/classtablemodel.h"
00028 #include <iostream>
00029 
00030 namespace inspectorj {
00031 namespace model {
00032 
00033 using namespace inspectorj::jdwp;
00034 using inspectorj::toolset::ToolSetUtils;
00035 
00039 bool javaClassSort(JavaClass* lhs, JavaClass* rhs)
00040 {
00041     return *lhs < *rhs;
00042 }
00043 
00047 ClassTableModel::ClassTableModel(QVector<JavaClass*> &classes, SessionProfile **prof)
00048     : QAbstractTableModel(),
00049       totalClassesLoaded(0), 
00050       filteredClassesLoaded(0),
00051       profile(prof),
00052       classes(classes)
00053 {
00054 
00055 }
00056 
00060 ClassTableModel::~ClassTableModel()
00061 {
00062 }
00063 
00068 int ClassTableModel::rowCount(const QModelIndex &parent) const
00069 {
00070     return classes.size();
00071 }
00072 
00077 int ClassTableModel::columnCount(const QModelIndex &parent) const
00078 {
00079     return 1;
00080 }
00081 
00087 QVariant ClassTableModel::data(const QModelIndex &index, int role) const
00088 {
00089     if (!index.isValid())
00090         return QVariant();
00091     
00092     if (role == Qt::TextAlignmentRole) {
00093         return int(Qt::AlignLeft | Qt::AlignVCenter);
00094     } else if (role == Qt::DisplayRole) {
00095         return classes[index.row()]->getClassSignature();
00096     }
00097     return QVariant();    
00098 }
00099 
00103 QVariant ClassTableModel::headerData(int section, Qt::Orientation orientation,
00104                     int role) const
00105 {
00106     if(orientation == Qt::Horizontal) {
00107         if (role == Qt::TextAlignmentRole) {
00108             return int(Qt::AlignLeft | Qt::AlignVCenter);
00109         } else if (role == Qt::DisplayRole) {
00110             switch( section ){
00111                 case 0 : return QVariant(" Class References "); break;
00112             }   
00113         } 
00114         return QVariant();        
00115     }
00116     if(orientation == Qt::Vertical) {
00117         if (role == Qt::DisplayRole) {
00118             return QVariant("");  
00119         } 
00120         return QVariant();        
00121     }
00122     return QVariant();
00123 }
00124 
00130 void ClassTableModel::initModel(JDWPPacket& packet)
00131 {
00132     filteredClassesLoaded = 0;
00133     regexFilterList.clear();
00134     if (profile) {
00135         QStringList filters = (*profile)->getClassFilters();
00136         QStringListIterator filterIter(filters);
00137         while(filterIter.hasNext()) {
00138             QRegExp regexp;
00139             ToolSetUtils::createClassFilter(regexp, filterIter.next());
00140             regexFilterList << regexp;
00141         }
00142     }
00143     classes.clear();
00144     int count;
00145     packet >> count;
00146     totalClassesLoaded = count;
00147     
00148     while (count > 0) {
00149 
00150         jbyte refTypeTag;
00151         int status;
00152         ReferenceTypeID refTypeId;
00153         QString classSignature;
00154         
00155         packet >> refTypeTag;
00156         packet >> refTypeId;
00157         packet >> classSignature;
00158         packet >> status;
00159         
00160         QList<QRegExp>::iterator iter;
00161         iter = regexFilterList.begin();
00162         if (iter == regexFilterList.end()) {            
00163             // no filters evidently so add all classes
00164             
00165             JavaClass *javaClass = new JavaClass();
00166             
00167             javaClass->setRefTypeTag(refTypeTag);
00168             javaClass->setRefTypeId(refTypeId);
00169             javaClass->setJNIClassSignature(classSignature);
00170             javaClass->setClassSignature(ToolSetUtils::normalizeClassSignature(classSignature));
00171             javaClass->setStatus(status);
00172             
00173             classes.append(javaClass);
00174             filteredClassesLoaded++;
00175         }
00176         else {
00177             while (iter != regexFilterList.end()) {
00178                 QRegExp regexp;
00179                 regexp = *iter;
00180 
00181                 if (classSignature.contains(regexp)) {
00182                     JavaClass *javaClass = new JavaClass();
00183                     
00184                     javaClass->setRefTypeTag(refTypeTag);
00185                     javaClass->setRefTypeId(refTypeId);
00186                     javaClass->setJNIClassSignature(classSignature);
00187                     javaClass->setClassSignature(ToolSetUtils::normalizeClassSignature(classSignature));
00188                     javaClass->setStatus(status);                        
00189                     
00190                     classes.append(javaClass);                                                
00191                     // keep track of how many classes match our filters
00192                     filteredClassesLoaded++;
00193                 }
00194                 ++iter;
00195             }
00196         }
00197         count--;
00198     } 
00199     qSort(classes.begin(), classes.end(), javaClassSort);   
00200 }
00201 
00205 int ClassTableModel::getTotalClassesLoaded()
00206 {
00207     return totalClassesLoaded;
00208 }
00209 
00214 int ClassTableModel::getFilteredClassesLoaded()
00215 {
00216     return filteredClassesLoaded;
00217            
00218 }
00219 
00223 const JavaClass* ClassTableModel::getClassAtIndex(const QModelIndex& index)
00224 {
00225     return classes.at(index.row());
00226 }
00227 
00228 } // end namespace inspectorj
00229 } // end namespace model

Generated on Sun Aug 19 17:07:53 2007 for inspectorJ by  doxygen 1.5.1