00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "customfields_p.h"
00023
00024 CustomField::CustomField()
00025 : mType( TextType ), mScope( LocalScope )
00026 {
00027 }
00028
00029 CustomField::CustomField( const QString &key, const QString &title, Type type, Scope scope )
00030 : mKey( key ), mTitle( title ), mType( type ), mScope( scope )
00031 {
00032 }
00033
00034 CustomField CustomField::fromVariantMap( const QVariantMap &map, Scope scope )
00035 {
00036 return CustomField( map.value( QLatin1String( "key" ) ).toString(),
00037 map.value( QLatin1String( "title" ) ).toString(),
00038 stringToType( map.value( QLatin1String( "type" ) ).toString() ),
00039 scope );
00040 }
00041
00042 void CustomField::setKey( const QString &key )
00043 {
00044 mKey = key;
00045 }
00046
00047 QString CustomField::key() const
00048 {
00049 return mKey;
00050 }
00051
00052 void CustomField::setTitle( const QString &title )
00053 {
00054 mTitle = title;
00055 }
00056
00057 QString CustomField::title() const
00058 {
00059 return mTitle;
00060 }
00061
00062 void CustomField::setType( Type type )
00063 {
00064 mType = type;
00065 }
00066
00067 CustomField::Type CustomField::type() const
00068 {
00069 return mType;
00070 }
00071
00072 void CustomField::setScope( Scope scope )
00073 {
00074 mScope = scope;
00075 }
00076
00077 CustomField::Scope CustomField::scope() const
00078 {
00079 return mScope;
00080 }
00081
00082 void CustomField::setValue( const QString &value )
00083 {
00084 mValue = value;
00085 }
00086
00087 QString CustomField::value() const
00088 {
00089 return mValue;
00090 }
00091
00092 QVariantMap CustomField::toVariantMap() const
00093 {
00094 QVariantMap map;
00095 map.insert( QLatin1String( "key" ), mKey );
00096 map.insert( QLatin1String( "title" ), mTitle );
00097 map.insert( QLatin1String( "type" ), typeToString( mType ) );
00098
00099 return map;
00100 }
00101
00102 CustomField::Type CustomField::stringToType( const QString &type )
00103 {
00104 if ( type == QLatin1String( "text" ) )
00105 return CustomField::TextType;
00106 if ( type == QLatin1String( "numeric" ) )
00107 return CustomField::NumericType;
00108 if ( type == QLatin1String( "boolean" ) )
00109 return CustomField::BooleanType;
00110 if ( type == QLatin1String( "date" ) )
00111 return CustomField::DateType;
00112 if ( type == QLatin1String( "time" ) )
00113 return CustomField::TimeType;
00114 if ( type == QLatin1String( "datetime" ) )
00115 return CustomField::DateTimeType;
00116
00117 return CustomField::TextType;
00118 }
00119
00120 QString CustomField::typeToString( CustomField::Type type )
00121 {
00122 switch ( type ) {
00123 case CustomField::TextType:
00124 default:
00125 return QLatin1String( "text" );
00126 break;
00127 case CustomField::NumericType:
00128 return QLatin1String( "numeric" );
00129 break;
00130 case CustomField::BooleanType:
00131 return QLatin1String( "boolean" );
00132 break;
00133 case CustomField::DateType:
00134 return QLatin1String( "date" );
00135 break;
00136 case CustomField::TimeType:
00137 return QLatin1String( "time" );
00138 break;
00139 case CustomField::DateTimeType:
00140 return QLatin1String( "datetime" );
00141 break;
00142 }
00143 }