Qt 4.8
Public Functions | Public Variables | List of all members
QMimeDataPrivate Class Reference
Inheritance diagram for QMimeDataPrivate:
QObjectPrivate QObjectData

Public Functions

QVariant getData (const QString &format) const
 
void removeData (const QString &format)
 
QVariant retrieveTypedData (const QString &format, QVariant::Type type) const
 
void setData (const QString &format, const QVariant &data)
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QList< QMimeDataStructdataList
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 57 of file qmimedata.cpp.

Functions

◆ getData()

QVariant QMimeDataPrivate::getData ( const QString format) const

Definition at line 91 of file qmimedata.cpp.

92 {
93  QVariant data;
94  for (int i=0; i<dataList.size(); i++) {
95  if (dataList.at(i).format == format) {
96  data = dataList.at(i).data;
97  break;
98  }
99  }
100  return data;
101 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant data
Definition: qmimedata.cpp:54
QString format
Definition: qmimedata.cpp:53
QList< QMimeDataStruct > dataList
Definition: qmimedata.cpp:67
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char * data(const QByteArray &arr)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ removeData()

void QMimeDataPrivate::removeData ( const QString format)

Definition at line 70 of file qmimedata.cpp.

71 {
72  for (int i=0; i<dataList.size(); i++) {
73  if (dataList.at(i).format == format) {
74  dataList.removeAt(i);
75  return;
76  }
77  }
78 }
QString format
Definition: qmimedata.cpp:53
QList< QMimeDataStruct > dataList
Definition: qmimedata.cpp:67
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ retrieveTypedData()

QVariant QMimeDataPrivate::retrieveTypedData ( const QString format,
QVariant::Type  type 
) const

Definition at line 103 of file qmimedata.cpp.

104 {
105  Q_Q(const QMimeData);
106 
107  QVariant data = q->retrieveData(format, type);
108  if (data.type() == type || !data.isValid())
109  return data;
110 
111  // provide more conversion possiblities than just what QVariant provides
112 
113  // URLs can be lists as well...
114  if ((type == QVariant::Url && data.type() == QVariant::List)
115  || (type == QVariant::List && data.type() == QVariant::Url))
116  return data;
117 
118  // images and pixmaps are interchangeable
119  if ((type == QVariant::Pixmap && data.type() == QVariant::Image)
120  || (type == QVariant::Image && data.type() == QVariant::Pixmap))
121  return data;
122 
123  if (data.type() == QVariant::ByteArray) {
124  // see if we can convert to the requested type
125  switch(type) {
126 #ifndef QT_NO_TEXTCODEC
127  case QVariant::String: {
128  const QByteArray ba = data.toByteArray();
130  if (format == QLatin1String("text/html"))
131  codec = QTextCodec::codecForHtml(ba, codec);
132  return codec->toUnicode(ba);
133  }
134 #endif // QT_NO_TEXTCODEC
135  case QVariant::Color: {
136  QVariant newData = data;
137  newData.convert(QVariant::Color);
138  return newData;
139  }
140  case QVariant::List: {
141  if (format != QLatin1String("text/uri-list"))
142  break;
143  // fall through
144  }
145  case QVariant::Url: {
146  QByteArray ba = data.toByteArray();
147  // Qt 3.x will send text/uri-list with a trailing
148  // null-terminator (that is *not* sent for any other
149  // text/* mime-type), so chop it off
150  if (ba.endsWith('\0'))
151  ba.chop(1);
152 
153  QList<QByteArray> urls = ba.split('\n');
154  QList<QVariant> list;
155  for (int i = 0; i < urls.size(); ++i) {
156  QByteArray ba = urls.at(i).trimmed();
157  if (!ba.isEmpty())
158  list.append(QUrl::fromEncoded(ba));
159  }
160  return list;
161  }
162  default:
163  break;
164  }
165 
166  } else if (type == QVariant::ByteArray) {
167 
168  // try to convert to bytearray
169  switch(data.type()) {
170  case QVariant::ByteArray:
171  case QVariant::Color:
172  return data.toByteArray();
173  break;
174  case QVariant::String:
175  return data.toString().toUtf8();
176  break;
177  case QVariant::Url:
178  return data.toUrl().toEncoded();
179  break;
180  case QVariant::List: {
181  // has to be list of URLs
182  QByteArray result;
183  QList<QVariant> list = data.toList();
184  for (int i = 0; i < list.size(); ++i) {
185  if (list.at(i).type() == QVariant::Url) {
186  result += list.at(i).toUrl().toEncoded();
187  result += "\r\n";
188  }
189  }
190  if (!result.isEmpty())
191  return result;
192  break;
193  }
194  default:
195  break;
196  }
197  }
198  return data;
199 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void chop(int n)
Removes n bytes from the end of the byte array.
int type
Definition: qmetatype.cpp:239
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QTextCodec * codecForHtml(const QByteArray &ba)
Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
#define Q_Q(Class)
Definition: qglobal.h:2483
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QByteArray trimmed() const
Returns a byte array that has whitespace removed from the start and the end.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char * data(const QByteArray &arr)
static QTextCodec * codec(MYSQL *mysql)
Definition: qsql_mysql.cpp:220
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QTextCodec * codecForName(const QByteArray &name)
Searches all installed QTextCodec objects and returns the one which best matches name; the match is c...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ setData()

void QMimeDataPrivate::setData ( const QString format,
const QVariant data 
)

Definition at line 80 of file qmimedata.cpp.

81 {
82  // remove it first if the format is already here.
83  removeData(format);
84  QMimeDataStruct mimeData;
85  mimeData.format = format;
86  mimeData.data = data;
87  dataList += mimeData;
88 }
void removeData(const QString &format)
Definition: qmimedata.cpp:70
QVariant data
Definition: qmimedata.cpp:54
QString format
Definition: qmimedata.cpp:53
QList< QMimeDataStruct > dataList
Definition: qmimedata.cpp:67
static const char * data(const QByteArray &arr)

Properties

◆ dataList

QList<QMimeDataStruct> QMimeDataPrivate::dataList

Definition at line 67 of file qmimedata.cpp.


The documentation for this class was generated from the following file: