Add QMacPasteboardMime::count(QMimeData*).

As QTBUG-25076 points out, the ### comment indicates
that we want to add virtual function to
QMacPasteboardMime.

The default implementation returns 1. Reimplement 
for QMacPastebardMimeUrl and return the url count.

Change-Id: Ie300574eab9991af625986805d2b030914291cc0
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Morten Johan Sorvig 2012-05-23 12:31:39 +02:00 committed by Qt by Nokia
parent 4b4975ceae
commit 48e104aa1d
3 changed files with 17 additions and 8 deletions

View File

@ -305,14 +305,8 @@ QMacPasteboard::setMimeData(QMimeData *mime_src)
QString flavor(c->flavorFor(mimeType));
if (!flavor.isEmpty()) {
QVariant mimeData = static_cast<QMacMimeData*>(mime_src)->variantData(mimeType);
#if 0
//### Grrr, why didn't I put in a virtual int QMacPasteboardMime::count()? --Sam
const int numItems = c->convertFromMime(mimeType, mimeData, flavor).size();
#else
int numItems = 1; //this is a hack but it is much faster than allowing conversion above
if (c->convertorName() == QLatin1String("FileURL"))
numItems = mime_src->urls().count();
#endif
int numItems = c->count(mime_src);
for (int item = 0; item < numItems; ++item) {
const int itemID = item+1; //id starts at 1
promises.append(QMacPasteboard::Promise(itemID, c, mimeType, mimeData, item));

View File

@ -74,6 +74,7 @@ public:
virtual QString flavorFor(const QString &mime) = 0;
virtual QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav) = 0;
virtual QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav) = 0;
virtual int count(QMimeData *mimeData);
};
QT_END_NAMESPACE

View File

@ -168,6 +168,14 @@ QMacPasteboardMime::~QMacPasteboardMime()
globalMimeList()->removeAll(this);
}
/*!
Returns the item count for the given \a mimeData
*/
int QMacPasteboardMime::count(QMimeData *mimeData)
{
return 1;
}
class QMacPasteboardMimeAny : public QMacPasteboardMime {
private:
@ -586,6 +594,7 @@ public:
bool canConvert(const QString &mime, QString flav);
QVariant convertToMime(const QString &mime, QList<QByteArray> data, QString flav);
QList<QByteArray> convertFromMime(const QString &mime, QVariant data, QString flav);
int count(QMimeData *mimeData);
};
QString QMacPasteboardMimeFileUri::convertorName()
@ -648,6 +657,11 @@ QList<QByteArray> QMacPasteboardMimeFileUri::convertFromMime(const QString &mime
return ret;
}
int QMacPasteboardMimeFileUri::count(QMimeData *mimeData)
{
return mimeData->urls().count();
}
class QMacPasteboardMimeUrl : public QMacPasteboardMime {
public:
QMacPasteboardMimeUrl() : QMacPasteboardMime(MIME_ALL) { }