DumontEXE 0.0.1
cmcField.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 <QString>
00026 #include <QDomDocument>
00027 #include <QDomNode>
00028 #include <QDomElement>
00029 #include <QDate>
00030 
00031 #include "cmcField.h"
00032 #include "cmcSubField.h"
00033 #include "cmcForm.h"
00034 #include "cmcFieldDefs.h"
00035 #include "cmcFieldDef.h"
00036 
00037 namespace cmcDatabaseApi {
00038 
00039 cmcField::cmcField( const cmcField & copy ):
00040   cmcObject( copy )
00041 {
00042 }
00043 
00044 cmcField::cmcField
00045 (
00046   const QString & fieldName,
00047   cmcApplication * application,
00048   QObject * parent
00049 ):
00050   cmcObject( fieldName, application, parent )
00051 {
00052 //  TRACE_FUNCTION
00053 
00054   reset();
00055 
00056 }
00057 
00058 cmcField::~cmcField()
00059 {
00060 //  TRACE_FUNCTION
00061 }
00062 
00063 void cmcField::reset()
00064 {
00065   /*
00066   ** Indicate that we don't know what the previous value is.
00067   **  We will 'discover' it as soon as we try to manipulate 
00068   **  the value in some way (either on a read or write).
00069   **
00070   */
00071   m_gotPreviousValue = false;
00072 
00073 }
00074 
00075 void cmcField::clear()
00076 {
00077   value( "" );
00078 }
00079 
00080 bool cmcField::isField()
00081 {
00082   return( true );
00083 }
00084 
00085 bool cmcField::isConnection()
00086 {
00087   return( false );
00088 }
00089 
00090 bool cmcField::isBlank()
00091 {
00092   return( value() == "" );
00093 }
00094 
00095 bool cmcField::isNotBlank()
00096 {
00097   return( !isBlank() );
00098 }
00099 
00100 bool cmcField::isGuid()
00101 {
00102   QString tValue = value();
00103 
00104   return
00105   (
00106     tValue.left(1)  == "{" &&
00107     tValue.right(1) == "}" &&
00108     tValue.length() == 38
00109   );
00110 }
00111 
00112 bool cmcField::isNotGuid()
00113 {
00114   return( !isGuid() );
00115 }
00116 
00117 long cmcField::length()
00118 {
00119   return( value().length() );
00120 }
00121 
00122 bool cmcField::contains( const QString & subString )
00123 {
00124   return( value().contains( subString ) );
00125 }
00126 
00127 QString cmcField::name()
00128 {
00129   return( objectName() );
00130 }
00131 
00132 QString cmcField::fieldName()
00133 {
00134   return( name() );
00135 }
00136 
00137 long cmcField::index()
00138 {
00139   return( definition()-> index() );
00140 }
00141 
00142 void cmcField::append( QString appendValue, QString separator )
00143 {
00144   if( value().length() > 0 )
00145   {
00146     value( value() + separator + appendValue );
00147   }
00148   else
00149   {
00150     value( appendValue );
00151   }
00152 }
00153 
00154 bool cmcField::isTrue()
00155 {
00156   return( cmcObject::isTrue( value() ) );
00157 }
00158 
00159 bool cmcField::isFalse()
00160 {
00161   return( cmcObject::isFalse( value() ) );
00162 }
00163 
00164 void cmcField::value( QDate newValue )
00165 {
00166   value( newValue.toString("M/d/yyyy") );
00167 }
00168 
00169 void cmcField::value( long newValue )
00170 {
00171   value( QString::number(newValue) );
00172 }
00173 
00174 void cmcField::value( double newValue )
00175 {
00176   value( QString::number(newValue) );
00177 }
00178 
00179 QDate cmcField::toDate()
00180 {
00181   return( QDate::fromString( value(), "M/d/yyyy" ) );
00182 }
00183 
00184 QTime cmcField::toTime()
00185 {
00186   return( QTime::fromString( value(), "h:mm AP" ) );
00187 }
00188 
00189 QString cmcField::unpackDateTime()
00190 {
00191   return( cmcObject::unpackDateTime(value()) );
00192 }
00193 
00194 QString cmcField::line( long lineNumber, long maxChar )
00195 {
00196   QStringList stringList = value().split("\r\n");
00197 
00198   QString retVal;
00199 
00200   if( stringList.count() > lineNumber )
00201   {
00202     retVal = stringList.at(lineNumber);
00203   }
00204 
00205   if( maxChar != -1 )
00206   {
00207     retVal = retVal.left(maxChar);
00208   }
00209 
00210   return( retVal ); 
00211 
00212 }
00213 
00214 
00215 QString cmcField::var( QString fieldName )
00216 {
00217   return( cmcObject::var(value(),fieldName) );
00218 }
00219 
00220 void cmcField::var( QString fieldName, QString newValue )
00221 {
00222   value( cmcObject::var( value(), fieldName, newValue ) );
00223 }
00224 
00225 void cmcField::delVar( QString fieldName )
00226 {
00227   value( cmcObject::delVar( value(), fieldName ) );
00228 }
00229 
00230 cmcSubField * cmcField::subField( QString subFieldName )
00231 {
00232   return( new cmcSubField( subFieldName, app(), this ) );
00233 }
00234 
00235 cmcForm * cmcField::form()
00236 {
00237   return( qobject_cast<cmcForm*>(parent()) );
00238 }  
00239 
00240 cmcFieldDef * cmcField::definition()
00241 {
00242   if( !m_definition )
00243        m_definition  = 
00244          form()-> 
00245            categoryDef()-> 
00246              fieldDefs()-> get( name() );
00247   return( m_definition );
00248 }  
00249 
00250 bool cmcField::undo()
00251 {
00252   bool retVal = false;
00253   if( isDirty() )
00254   {
00255     value( m_previousValue );
00256     retVal = true;
00257   }
00258   return( retVal );
00259   
00260 }
00261 
00262 bool cmcField::isDirty()
00263 {
00264   return( value() != previousValue() );
00265 }  
00266 
00267 QString cmcField::previousValue()
00268 {
00269   return( m_previousValue );
00270 }  
00271 
00272 QString cmcField::changeLog()
00273 {
00274   /*!
00275   ** \returns Formatted ChangeLog or an empty string if there were no changes
00276   **
00277   */
00278   QString retVal;
00279 
00280   if( isDirty() )
00281     retVal = dq( name()          ) + " from " + 
00282              dq( previousValue() ) + " to "   + 
00283              dq( value()         );
00284 
00285 //  qDebug( "changeLog == %s", retVal.toAscii().data() );
00286 
00287   return( retVal );
00288 }
00289 
00290 } // endnamespace cmcDatabaseApi
00291 
 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