-
Notifications
You must be signed in to change notification settings - Fork 1
/
Qt4DataFormatter.cpp
112 lines (91 loc) · 2.65 KB
/
Qt4DataFormatter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* QtFormatter.cpp
* Qt4DataFormatter
*
* Created by James Kyle on 5/4/10.
* Copyright 2010 KSpace MRI. All rights reserved.
*
*/
#include "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"
#include <QtCore/QString>
#include <QtCore/QModelIndex>
#include <QtXml/QDomNode>
#include <QtCore/QVariant>
#include <QtCore/QFile>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QList>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
// XML stuff
#include <QtXml/QDomElement>
// #define _DEBUG_
/* definition of the plugin function list is required here */
_pbxgdb_plugin_function_list *_pbxgdb_plugin_functions = NULL;
char* stringToFromatBuff(std::string message, int ID)
{
int bufLen = message.size() + 1;
char *formatBuff;
formatBuff = (char *)(_pbxgdb_plugin_functions->allocate(ID, bufLen));
strncpy(formatBuff, message.data(), bufLen);
formatBuff[bufLen - 1] = '\0';
// some debug output
#ifdef _DEBUG_
std::cout << message << std::endl;
#endif
return formatBuff;
}
char* printQString(QString *data, int ID)
{
std::string result;
if (NULL != _pbxgdb_plugin_functions ) {
result = _pbxgdb_plugin_functions->message(ID, "%s", qPrintable(*data));
} else
{
result = "Could not map object to QString";
}
return stringToFromatBuff(result, ID);
}
char* printQDomNode(QDomNode *data, int ID)
{
QString msg = QString("tagName: %1, text: %2")
.arg(data->toElement().tagName()).arg(data->toElement().text());
return printQString(&msg, ID);
}
char* printQModelIndex(QModelIndex *index, int ID)
{
QString *result = new QString;
if (NULL != _pbxgdb_plugin_functions)
{
*result = _pbxgdb_plugin_functions->message(ID, "row: %i, col: %i",
index->row(), index->column());
} else
{
*result = "Could not map object to QModelIndex";
}
return printQString(result, ID);
}
char* printQVariant(QVariant *variant, int ID)
{
QString *st = new QString(variant->toString());
return printQString(st, ID);
}
char* printQAbstractItemModel(QAbstractItemModel *model, int ID)
{
QString *repr = new QString("%1: rows %2, cols %3");
QString cl = model->metaObject()->className();
*repr = repr->arg(cl).arg(model->rowCount()).arg(model->columnCount());
return printQString(repr, ID);
}
char* printQFile(QFile *file, int ID)
{
QString *f = new QString(file->fileName());
return printQString(f, ID);
}
char* printQDomElement(QDomElement *e, int ID)
{
QString out = QString("tagName: %1, text: %2").arg(e->tagName())
.arg(e->text());
return printQString(&out, ID);
}