Convert CoverSearchResult lists correctly

This commit is contained in:
David Sansome 2011-05-22 14:10:54 +00:00
parent 2dbf6a4871
commit fc97e4bb8c
2 changed files with 18 additions and 17 deletions

View File

@ -191,6 +191,7 @@ int main(int argc, char *argv[]) {
qRegisterMetaType<CoverSearchResult>("CoverSearchResult");
qRegisterMetaType<CoverSearchResults>("CoverSearchResults");
qRegisterMetaType<QList<CoverSearchResult> >("QList<CoverSearchResult>");
qRegisterMetaType<Directory>("Directory");
qRegisterMetaType<DirectoryList>("DirectoryList");
qRegisterMetaType<Subdirectory>("Subdirectory");

View File

@ -72,6 +72,20 @@ PythonEngine::~PythonEngine() {
PythonQt::cleanup();
}
template <typename T>
static void RegisterListConverter(const char* other_class_name) {
typedef QList<T> L;
PythonQtConv::registerMetaTypeToPythonConverter(qMetaTypeId<L>(),
PythonQtConvertListOfValueTypeToPythonList<L, T>);
PythonQtConv::registerMetaTypeToPythonConverter(QMetaType::type(other_class_name),
PythonQtConvertListOfValueTypeToPythonList<L, T>);
PythonQtConv::registerPythonToMetaTypeConverter(qMetaTypeId<L>(),
PythonQtConvertPythonListToListOfValueType<L, T>);
PythonQtConv::registerPythonToMetaTypeConverter(QMetaType::type(other_class_name),
PythonQtConvertPythonListToListOfValueType<L, T>);
}
bool PythonEngine::EnsureInitialised() {
if (initialised_)
return true;
@ -92,23 +106,9 @@ bool PythonEngine::EnsureInitialised() {
python_qt->addDecorators(new ObjectDecorators);
// Register converters for list types
PythonQtConv::registerMetaTypeToPythonConverter(qMetaTypeId<SongList>(),
PythonQtConvertListOfValueTypeToPythonList<SongList, Song>);
PythonQtConv::registerMetaTypeToPythonConverter(QMetaType::type("QList<Song>"),
PythonQtConvertListOfValueTypeToPythonList<SongList, Song>);
PythonQtConv::registerMetaTypeToPythonConverter(qMetaTypeId<DirectoryList>(),
PythonQtConvertListOfValueTypeToPythonList<DirectoryList, Directory>);
PythonQtConv::registerMetaTypeToPythonConverter(qMetaTypeId<CoverSearchResults>(),
PythonQtConvertListOfValueTypeToPythonList<CoverSearchResults, CoverSearchResult>);
PythonQtConv::registerPythonToMetaTypeConverter(qMetaTypeId<SongList>(),
PythonQtConvertPythonListToListOfValueType<SongList, Song>);
PythonQtConv::registerPythonToMetaTypeConverter(QMetaType::type("QList<Song>"),
PythonQtConvertPythonListToListOfValueType<SongList, Song>);
PythonQtConv::registerPythonToMetaTypeConverter(qMetaTypeId<DirectoryList>(),
PythonQtConvertPythonListToListOfValueType<DirectoryList, Directory>);
PythonQtConv::registerPythonToMetaTypeConverter(qMetaTypeId<CoverSearchResults>(),
PythonQtConvertPythonListToListOfValueType<CoverSearchResults, CoverSearchResult>);
RegisterListConverter<Song>("QList<Song>");
RegisterListConverter<Directory>("QList<Directory>");
RegisterListConverter<CoverSearchResult>("QList<CoverSearchResult>");
// Connect stdout, stderr
connect(python_qt, SIGNAL(pythonStdOut(QString)), SLOT(PythonStdOut(QString)));