1 /***************************************************************************
2 ** Class: GLViewer_MimeSource
3 ** Descr: Needs for a work with QClipboard
5 ** Created: UI team, 22.03.04
6 ****************************************************************************/
8 //#include <GLViewerAfx.h>
9 #include "GLViewer_MimeSource.h"
10 #include "GLViewer_BaseObjects.h"
13 //using namespace std;
15 GLViewer_MimeSource::~GLViewer_MimeSource()
19 bool GLViewer_MimeSource::setObjects( QValueList<GLViewer_Object*> theObjects )
21 if( !theObjects.empty() )
23 QStringList aObjectsType;
24 QValueList<QByteArray> aObjects;
25 QValueList<GLViewer_Object*>::const_iterator anIt = theObjects.begin();
26 QValueList<GLViewer_Object*>::const_iterator anEndIt = theObjects.end();
29 for( ; anIt != anEndIt; anIt++ )
31 aObjects.append( (*anIt)->getByteCopy() );
32 aObjByteSize += aObjects.last().size();
33 aObjectsType.append( (*anIt)->getObjectType() );
36 int anISize = sizeof( int );
37 QString aTypes = aObjectsType.join("");
38 int aStrByteSize = aTypes.length();
39 int aObjNum = aObjects.count();
41 myByteArray = QByteArray( anISize * (1 + 2*aObjNum) + aStrByteSize + aObjByteSize );
43 int anIndex = 0, j = 0;
44 char* aPointer = (char*)&aObjNum;
45 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
46 myByteArray[anIndex] = *aPointer;
48 QStringList::const_iterator aStrIt = aObjectsType.begin();
49 QStringList::const_iterator aEndStrIt = aObjectsType.end();
50 for( j = 1; aStrIt != aEndStrIt; aStrIt++, j++ )
52 int aStrLen = (*aStrIt).length();
53 aPointer = (char*)&aStrLen;
54 for( ; anIndex < anISize*( 1 + j ); anIndex++, aPointer++ )
55 myByteArray[anIndex] = *aPointer;
58 int aCurIndex = anIndex;
59 const char* aStr = aTypes.data();
61 for( j = 0 ; anIndex < aCurIndex + aStrByteSize; aPointer++, anIndex++, j++ )
62 myByteArray[anIndex] = aStr[j];
65 QValueList<QByteArray>::iterator anObjIt = aObjects.begin();
66 QValueList<QByteArray>::iterator anEndObjIt = aObjects.end();
67 for( j = 1; anObjIt != anEndObjIt; anObjIt++, j++ )
69 int aObjLen = (int)((*anObjIt).size());
70 aPointer = (char*)&aObjLen;
71 for( ; anIndex < aCurIndex + anISize*j; anIndex++, aPointer++ )
72 myByteArray[anIndex] = *aPointer;
76 anObjIt = aObjects.begin();
78 for( ; anObjIt != anEndObjIt; anObjIt++ )
80 int aObjLen = (int)((*anObjIt).size());
81 for( j = 0 ; anIndex < aCurIndex + aObjLen; anIndex++, aPointer++, j++ )
82 myByteArray[anIndex] = (*anObjIt)[j];
91 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
92 //If you want to use new class, following two method must be redefined
93 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
94 GLViewer_Object* GLViewer_MimeSource::getObject( QByteArray theArray, QString theType )
96 if( !theArray.isEmpty() )
98 if( theType == "GLViewer_MarkerSet" )
100 GLViewer_MarkerSet* aObject = new GLViewer_MarkerSet( 0, (float)0.0, 0 );
101 if( aObject->initializeFromByteCopy( theArray ) )
104 else if ( theType == "GLViewer_Polyline" )
106 GLViewer_Polyline* aObject = new GLViewer_Polyline( 0, (float)0.0, 0 );
107 if( aObject->initializeFromByteCopy( theArray ) )
110 else if( theType == "GLViewer_TextObject" )
112 GLViewer_TextObject* aObject = new GLViewer_TextObject( 0, 0, 0, QColor(255,255,255), 0 );
113 if( aObject->initializeFromByteCopy( theArray ) )
121 QValueList<GLViewer_Object*> GLViewer_MimeSource::getObjects( QByteArray theArray, QString theType )
123 if( !theArray.isEmpty() )
125 int anISize = sizeof( int );
126 if( theType == "GLViewer_Objects" )
128 QStringList aTypeList;
129 QValueList<QByteArray> aObjects;
130 QValueList<GLViewer_Object*> aObjectList;
132 QValueList<int> aTypeSizeList;
133 QValueList<int> aObjSizeList;
135 char* aPointer = (char*)&aObjNum;
137 int anIndex = 0, j = 0;
138 for( anIndex = 0; anIndex < anISize; anIndex++, aPointer++ )
139 *aPointer = theArray[anIndex];
141 for( j = 0; j < aObjNum; j++ )
144 aPointer = (char*)&aTempVal;
145 for( ; anIndex < anISize*(j+2); anIndex++, aPointer++ )
146 *aPointer = theArray[anIndex];
147 aTypeSizeList.append( aTempVal );
150 int aCurIndex = anIndex;
151 for( j = 0; j < aObjNum; j++ )
154 for( ; anIndex < aCurIndex + aTypeSizeList[j]; anIndex++ )
156 char aLetter = theArray[anIndex];
157 aTempStr.append( aLetter );
159 aTypeList.append( aTempStr );
163 for( j = 0; j < aObjNum; j++ )
166 aPointer = (char*)&aTempVal;
167 for( ; anIndex < aCurIndex + anISize*(j+1); anIndex++, aPointer++ )
168 *aPointer = theArray[anIndex];
169 aObjSizeList.append( aTempVal );
173 for( j = 0; j < aObjNum; j++ )
175 QByteArray aTempArray(aObjSizeList[j]);
176 for( ; anIndex < aCurIndex + aObjSizeList[j]; anIndex++ )
177 aTempArray[anIndex-aCurIndex] = theArray[anIndex];
178 aObjects.append( aTempArray );
182 for( j = 0; j < aObjNum; j++ )
183 aObjectList.append( getObject( aObjects[j], aTypeList[j] ) );
189 return QValueList<GLViewer_Object*>();
192 const char* GLViewer_MimeSource::format( int theIndex ) const
196 case 0: return "GLViewer_Objects";
197 //case 1: return "GLViewer_MarkerSet";
198 //case 2: return "GLViewer_Polyline";
199 //case 3: return "GLViewer_TextObject";
205 QByteArray GLViewer_MimeSource::encodedData( const char* theObjectType ) const
207 if( theObjectType == "GLViewer_Objects" )