DumontEXE 0.0.1
cmcObjects.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 <QStringList>
00026 
00027 #include "cmcObjects.h"
00028 #include "cmcApplication.h"
00029 
00030 namespace cmcDatabaseApi {
00031 
00032 cmcObjects::cmcObjects( const cmcObjects & copy ):
00033   cmcObject( copy )
00034 {
00035 }
00036 
00037 cmcObjects::cmcObjects( cmcObject * parent ):
00038   cmcObject(parent)
00039 {
00040 }
00041 
00042 cmcObjects::cmcObjects( const QString & i_objectName, cmcApplication * i_application, cmcObject * i_parent ):
00043   cmcObject( i_objectName, i_application, i_parent )
00044 {
00045 }
00046 
00047 
00048 cmcObjects::~cmcObjects()
00049 {
00050 }
00051 
00052 long cmcObjects::count(void)
00053 {
00054 //  if( children().count() != m_names.count() ) load();
00055 
00056   return( children().count() );
00057 }
00058 
00059 long cmcObjects::add( cmcObject * object )
00060 {
00061   object-> setParent( this );
00062 
00063   /*
00064   ** Add the object to the list of objects.
00065   **
00066   */
00067 //  m_objects.append( object );
00068 
00069   /*
00070   ** Connect a destroyed signal to the list so that if the object is destroyed
00071   **  it is automatically removed from the list of pointers.
00072   **
00073   */
00074 //  connect( object, SIGNAL(destroyed(QObject*)), this, SLOT(on_objectDestroyed(QObject*)) );
00075 
00076   /*
00077   ** Emit a signal that indicates an object was added to
00078   **  the collection.
00079   **
00080   */
00081   emit( objectAdded(object) );
00082 
00083   /*
00084   ** Return the current list count.
00085   **
00086   */
00087   return( count() );
00088 
00089 } // endlong cmcObjects::add( cmcObject * object )
00090 
00091 long cmcObjects::remove( cmcObject * object )
00092 {
00093   /*
00094   ** This is real hazardous.  An unparented object
00095   **  can mean a lost, dangling object.
00096   **
00097   */
00098   object-> setParent(NULL);
00099 
00100   /*
00101   ** Remove the object from the list of objects.
00102   **
00103   */
00104 //  m_objects.removeAll( object );
00105 
00106   /*
00107   ** Emit a signal that indicates an object was removed from
00108   **  the collection.
00109   **
00110   */
00111   emit objectRemoved(object);
00112 
00113   /*
00114   ** Return the new collection count.
00115   **
00116   */
00117 //  return( m_objects.count() );
00118   return( count() );
00119 }
00120 
00121 cmcObject * cmcObjects::get( const long index )
00122 {
00123   if( index < count() )
00124   {
00125     return( qobject_cast<cmcObject*>(children().at(index)) );
00126   }
00127 
00128   return( NULL );
00129 }
00130 
00131 /*!
00132 ** \bug This function searches, first, the object names to find a match
00133 **  for an item.  If an item could not be found, then it searches for
00134 **  an item by its alias name.  This, however, is a problem, because upon
00135 **  requesting the alias name, some of the xml code starts to run.  The
00136 **  problem with this is, this xml code is running before we have the
00137 **  object document fully initialized.  Therefore, we have split the search
00138 **  for the object name vs the alias name up into two separate searches.
00139 **  This way, when the object is first initializing we can pretty much
00140 **  count on that we are going to request an item NOT by its alias name,
00141 **  and that this request is going to come at the point of object 
00142 **  initialization.  This is safe.  The object gets constructed, the document
00143 **  gets loaded, and the world is fine.  After the object is loaded then
00144 **  regular alias searches can proceed without any trouble.  Ideally, 
00145 **  however, we would prefer that the xml system didn't suffer from this
00146 **  sort of anomoly, since we're really not sure why its a problem to 
00147 **  request dom stuff before the document is loaded.  It might be because
00148 **  we are caching dom elements and then ruining the cached items by
00149 **  reloading the document.  Need to work on this.  It is probably going
00150 **  to cause a problem in the system when dumont is used on an application
00151 **  that is not \ref cdaReady.
00152 **
00153 **
00154 */
00155 cmcObject * cmcObjects::get( const QString & name )
00156 {
00157   int i = indexOf( name );
00158 
00159   if( i != -1 )
00160     return( qobject_cast<cmcObject*>(children().at(i)) );
00161 
00162   return( NULL );
00163 }
00164 
00165 QStringList cmcObjects::list()
00166 {
00167   return( m_names );
00168 }
00169 
00170 bool cmcObjects::contains( const QString & name )
00171 {
00172   return( m_names.indexOf(name) != -1? true:false );
00173 }
00174 
00175 /*!
00176 ** \bug There are some problems with this indexOf function.  It is scanning
00177 **  children() for items, and returning index values of them, but all of the
00178 **  children might not be loaded yet.  They really need to get loaded.
00179 **  The objects collection really needs to be upgraded to a dynamic-cache
00180 **  sort of operation.
00181 **
00182 */
00183 long cmcObjects::indexOf( const QString & name )
00184 {
00185   /*
00186   ** First search for regular names
00187   **
00188   */
00189   for( int i=0; i<children().count(); i++ )
00190   {
00191     cmcObject * child = qobject_cast<cmcObject*>(children().at(i));
00192     if( child && child-> objectName() == name )
00193       return( i );
00194   }
00195 
00196   /*
00197   ** Now search for alias names
00198   **
00199   */
00200   for( int i=0; i<children().count(); i++ )
00201   {
00202     cmcObject * child = qobject_cast<cmcObject*>(children().at(i));
00203     if( child && child-> aliasName()  == name )
00204       return( i );
00205   }
00206 
00207   return( -1 );
00208 
00209 }
00210 
00211 
00212 void cmcObjects::on_objectDestroyed( QObject * object )
00213 {
00214   remove( (cmcObject*) object );
00215 }
00216 
00217 } // endnamespace cmcDatabaseApi
00218 
00219 
 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