DumontEXE 0.0.1
cmcApplicationsModel.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
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://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.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 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include "cmcApplicationsModel.h"
00026 
00027 namespace cmcDatabaseApi {
00028 
00029 cmcApplicationsModel::cmcApplicationsModel(void):
00030   QAbstractItemModel()
00031 {
00032 //  TRACE_FUNCTION
00033 
00034   connect( cmcObject::apps(), SIGNAL(updated()), this, SLOT(applicationsChanged()) );
00035 }
00036 
00037 cmcApplicationsModel::~cmcApplicationsModel()
00038 {
00039 //  TRACE_FUNCTION
00040 }
00041 
00042 void cmcApplicationsModel::applicationsChanged(void)
00043 {
00044   reset();
00045 }
00046 
00047 QObject * cmcApplicationsModel::objectPointerFromIndex( const QModelIndex & index ) const
00048 {
00049   QObject * retVal;
00050 
00051   if( index.isValid() )
00052   {
00053     retVal = static_cast<QObject*>(index.internalPointer());
00054   }
00055   else
00056   {
00057     retVal = cmcObject::apps();
00058   }
00059 
00060   return( retVal );
00061 }
00062 
00063 
00064 QModelIndex cmcApplicationsModel::index( int row, int col, const QModelIndex & parent ) const
00065 {
00066   /*
00067   ** Check the row and column ranges.  If they are out of range
00068   **  then just return an invalid index item.
00069   **
00070   */
00071   if( col < 0 || col > 1 || row < 0 || row >= rowCount(parent) )
00072     return( QModelIndex() );
00073 
00074   /*
00075   ** We calculate a pointer to the object we are referring to and
00076   **  store it here - this helps simplify the object casting.
00077   **
00078   */
00079   const QObject *p = 
00080     objectPointerFromIndex( parent );
00081 
00082 //  if( QString("cmcForms") == p-> metaObject()-> className() )
00083 //  {
00084 //    return( createIndex( row, col, ((cmcForms*)p)-> get(row)) );
00085 //  }
00086 
00087   /*
00088   ** Return a new index based for the object we're interested in.
00089   **
00090   */
00091   return( createIndex( row, col, p-> children().at(row) ) );
00092 }
00093 
00094 QModelIndex cmcApplicationsModel::parent( const QModelIndex & child ) const
00095 {
00096   const QObject *p =
00097     objectPointerFromIndex( child );
00098 
00099   if( !p ) return( QModelIndex() );
00100 
00101   const QObject *parent = p-> parent();
00102 
00103   if( !parent ) return( QModelIndex() );
00104 
00105   const QObject *grandparent = parent-> parent();
00106 
00107   if( !grandparent ) return( QModelIndex() );
00108 
00109   int row = grandparent-> children().indexOf( (QObject*) parent );
00110 
00111   return( createIndex( row, child.column(), (void*) parent ) );
00112 }
00113 
00114 int cmcApplicationsModel::rowCount( const QModelIndex & parent ) const
00115 {
00116   /*
00117   ** Get a pointer to the object this index points to.
00118   **
00119   */
00120   const QObject *p =
00121     objectPointerFromIndex( parent );
00122 
00123 //  if( QString("cmcForms") == p-> metaObject()-> className() )
00124 //  {
00125 //    return( ((cmcForms*)p)-> count() );
00126 //  }
00127 
00128   return( p-> children().count() );
00129 }
00130 
00131 int cmcApplicationsModel::columnCount( const QModelIndex & parent ) const
00132 {
00133   return( 2 );
00134 }
00135 
00136 QVariant cmcApplicationsModel::data( const QModelIndex & index, int role ) const
00137 {
00138   /*
00139   ** The index must be valid for us to do anything at all
00140   **
00141   */
00142   if( !index.isValid() ) return( QVariant() );
00143 
00144   /*
00145   ** Get a pointer to the object we're pointing
00146   **  to.
00147   **
00148   */
00149   const QObject *p =
00150     objectPointerFromIndex( index );
00151 
00152   /*
00153   ** No matter what we're returning a variant.
00154   **
00155   */
00156   QVariant retVal;
00157 
00158   /*
00159   ** Each column has a different meaning.
00160   **
00161   */
00162   switch( index.column() )
00163   {
00164     case 0: // objectName
00165     {
00166       switch( role )
00167       {
00168         case Qt::DisplayRole: 
00169         {
00170           retVal = QVariant( p-> objectName() );
00171           if( p-> objectName() == "" )
00172           {
00173             retVal = QVariant( p-> metaObject()-> className() );
00174           }
00175           break;
00176         }
00177 
00178         case Qt::ToolTipRole:
00179         {
00180           retVal = QVariant( p-> property("description") );
00181           break;
00182         }
00183       }
00184       break;
00185     }
00186 
00187     case 1: // objectComment
00188     {
00189       switch( role )
00190       {
00191         case Qt::EditRole:
00192         case Qt::DisplayRole:
00193         {
00194           retVal = p-> property("comment");
00195           break;
00196         }
00197       }
00198       break;
00199     }
00200   }
00201 
00202   return( retVal );
00203 }
00204 
00205 QVariant cmcApplicationsModel::headerData( int section, Qt::Orientation orientation, int role ) const
00206 {
00207   if( role != Qt::DisplayRole ) return( QVariant() );
00208   
00209   if( section == 0 ) return( QVariant("Object Name") );
00210   if( section == 1 ) return( QVariant("Comment")     );
00211 
00212   return( QVariant() );
00213 }
00214 
00215 Qt::ItemFlags cmcApplicationsModel::flags( const QModelIndex & index) const
00216 {
00217   if( index.column() == 1 ) return( Qt::ItemIsEditable | Qt::ItemIsEnabled );
00218 
00219   return( 0 );
00220 }
00221 
00222 bool cmcApplicationsModel::setData( const QModelIndex & index, const QVariant & value, int role )
00223 {
00224   /*
00225   ** Get a pointer to the object we are pointing to.
00226   **
00227   */
00228   QObject *p =
00229     objectPointerFromIndex( index );
00230 
00231   /*
00232   ** If this is the second column we are editing, then we're good to go.
00233   **
00234   */
00235   if( index.column() == 1 && role == Qt::EditRole )
00236   {
00237     p-> setProperty( "comment", value );
00238     dataChanged( index, index );
00239     return( true );
00240   }
00241 
00242   return( false );
00243 }
00244 
00245 
00246 } // endnamespace Commence
00247 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com