File indexing completed on 2024-12-22 04:17:23

0001 /***************************************************************************
0002                     string.cpp  -  the base string type
0003                              -------------------
0004     begin                : Sept 29, 2004
0005     copyright            : (C) 2004 by The University of Toronto
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "string_kst.h"
0019 #include "stringscriptinterface.h"
0020 
0021 #include <QTextDocument>
0022 #include <QXmlStreamWriter>
0023 
0024 namespace Kst {
0025 
0026 const QString String::staticTypeString = "String";
0027 const QString String::staticTypeTag = "string";
0028 
0029 String::String(ObjectStore *store)
0030     : Primitive(store, 0L), _orphan(false), _editable(false) {
0031 
0032   _value.clear();
0033   setFlag(true);
0034   _initializeShortName();
0035 
0036 }
0037 
0038 
0039 ScriptInterface* String::createScriptInterface() {
0040   return new StringGenSI(this);
0041 }
0042 
0043 
0044 void String::_initializeShortName() {
0045   _shortName = 'T'+QString::number(_stringnum);
0046   if (_stringnum>max_stringnum)
0047     max_stringnum = _stringnum;
0048   _stringnum++;
0049 }
0050 
0051 
0052 String::~String() {
0053 }
0054 
0055 
0056 const QString& String::typeString() const {
0057   return staticTypeString;
0058 }
0059 
0060 
0061 void String::save(QXmlStreamWriter &s) {
0062   if (provider()) { // Don't save datasource- or vector-derived strings
0063     return;
0064   }
0065   s.writeStartElement("string");
0066   if (_orphan) {
0067     s.writeAttribute("orphan", "true");
0068   }
0069   if (_editable) {
0070     s.writeAttribute("editable", "true");
0071   }
0072   s.writeAttribute("value", value());
0073   saveNameInfo(s, STRINGNUM);
0074   s.writeEndElement();
0075 }
0076 
0077 
0078 void String::internalUpdate() {
0079   // do nothing
0080 }
0081 
0082 
0083 String& String::operator=(const QString& v) {
0084   setValue(v);
0085   return *this;
0086 }
0087 
0088 
0089 String& String::operator=(const char *v) {
0090   setValue(v);
0091   return *this;
0092 }
0093 
0094 
0095 void String::setValue(const QString& inV) {
0096   _value = inV;
0097 }
0098 
0099 
0100 QString String::_automaticDescriptiveName() const {
0101   if (_orphan) {
0102     return value();
0103   } else {
0104     return Primitive::_automaticDescriptiveName();
0105   }
0106 }
0107 
0108 
0109 QString String::descriptionTip() const {
0110   return tr("String: %1").arg(Name());
0111 }
0112 
0113 
0114 QString String::sizeString() const {
0115   return QString::number(_value.size());
0116 }
0117 
0118 
0119 QString String::propertyString() const {
0120   return _value;
0121 }
0122 
0123 }
0124 
0125 // vim: ts=2 sw=2 et