Fix QMimeType::operator== to only compare mimetype names.

The name is the unique identifier. Code such as
if (oldItem.mimeType() == newItem.mimeType())
really wants to detect whether the item has a new mimetype (name),
not compare static mimetype data such as comments and icons.

Change-Id: I5fe56443295c91e1024c066ad6e7f93d842ae507
Reviewed-by: Wolf-Michael Bolle <wolf-michael.bolle@nokia.com>
This commit is contained in:
David Faure 2012-04-02 11:42:26 +02:00 committed by Qt by Nokia
parent 32db7de207
commit b069158ed3
3 changed files with 3 additions and 59 deletions

View File

@ -77,23 +77,6 @@ void QMimeTypePrivate::clear()
loaded = false;
}
/*!
\fn bool QMimeTypePrivate::operator==(const QMimeTypePrivate &other) const;
Returns true if \a other equals this QMimeTypePrivate object, otherwise returns false.
*/
bool QMimeTypePrivate::operator==(const QMimeTypePrivate &other) const
{
if (name == other.name &&
localeComments == other.localeComments &&
genericIconName == other.genericIconName &&
iconName == other.iconName &&
globPatterns == other.globPatterns) {
return true;
}
return false;
}
void QMimeTypePrivate::addGlobPattern(const QString &pattern)
{
globPatterns.append(pattern);
@ -184,10 +167,12 @@ QMimeType::~QMimeType()
/*!
\fn bool QMimeType::operator==(const QMimeType &other) const;
Returns true if \a other equals this QMimeType object, otherwise returns false.
The name is the unique identifier for a mimetype, so two mimetypes with
the same name, are equal.
*/
bool QMimeType::operator==(const QMimeType &other) const
{
return d == other.d || *d == *other.d;
return d == other.d || d->name == other.d->name;
}
/*!

View File

@ -59,8 +59,6 @@ public:
void clear();
bool operator==(const QMimeTypePrivate &other) const;
void addGlobPattern(const QString &pattern);
QString name;

View File

@ -176,20 +176,7 @@ void tst_qmimetype::genericIconName()
)
);
QMimeType otherQMimeType (
buildQMimeType (
qMimeTypeName(),
QString(),
qMimeTypeGenericIconName(),
qMimeTypeGlobPatterns()
)
);
// Verify that the GenericIconName is part of the equality test:
QCOMPARE(instantiatedQMimeType.genericIconName(), qMimeTypeGenericIconName());
QVERIFY(instantiatedQMimeType != otherQMimeType);
QVERIFY(!(instantiatedQMimeType == otherQMimeType));
}
// ------------------------------------------------------------------------------------------------
@ -205,20 +192,7 @@ void tst_qmimetype::iconName()
)
);
QMimeType otherQMimeType (
buildQMimeType (
qMimeTypeName(),
qMimeTypeGenericIconName(),
QString(),
qMimeTypeGlobPatterns()
)
);
// Verify that the IconName is part of the equality test:
QCOMPARE(instantiatedQMimeType.iconName(), qMimeTypeIconName());
QVERIFY(instantiatedQMimeType != otherQMimeType);
QVERIFY(!(instantiatedQMimeType == otherQMimeType));
}
// ------------------------------------------------------------------------------------------------
@ -234,21 +208,8 @@ void tst_qmimetype::suffixes()
)
);
QMimeType otherQMimeType (
buildQMimeType (
qMimeTypeName(),
qMimeTypeGenericIconName(),
qMimeTypeIconName(),
QStringList()
)
);
// Verify that the Suffixes are part of the equality test:
QCOMPARE(instantiatedQMimeType.globPatterns(), qMimeTypeGlobPatterns());
QCOMPARE(instantiatedQMimeType.suffixes(), QStringList() << QString::fromLatin1("png"));
QVERIFY(instantiatedQMimeType != otherQMimeType);
QVERIFY(!(instantiatedQMimeType == otherQMimeType));
}
// ------------------------------------------------------------------------------------------------