Add hasChild function to check for a child in a QObject tree.

This commit is contained in:
Florian Geyer 2012-04-19 00:04:52 +02:00 committed by Felix Geyer
parent 246bc0115e
commit f8e2c95162
2 changed files with 15 additions and 0 deletions

View File

@ -38,4 +38,17 @@ QString humanReadableFileSize(qint64 bytes)
return QString("%1 %2").arg(QLocale().toString(size, 'f', 2), units.at(i));
}
bool hasChild(const QObject* parent, const QObject* child)
{
if (!parent || !child) {
return false;
}
Q_FOREACH (QObject* c, parent->children()) {
if (child == c || hasChild(c, child)) {
return true;
}
}
return false;
}
} // namespace Tools

View File

@ -18,11 +18,13 @@
#ifndef KEEPASSX_TOOLS_H
#define KEEPASSX_TOOLS_H
#include <QtCore/QObject>
#include <QtCore/QString>
namespace Tools {
QString humanReadableFileSize(qint64 bytes);
bool hasChild(const QObject* parent, const QObject* child);
} // namespace Tools