| 125 | //========================================================================= |
| 126 | |
| 127 | QJsonModel::QJsonModel(QObject* parent) |
| 128 | : QAbstractItemModel(parent) |
| 129 | , mHeadItem(new QJsonTreeItem) |
| 130 | , mRootItem(new QJsonTreeItem(mHeadItem)) { |
| 131 | mHeadItem->appendChild(mRootItem); |
| 132 | mHeaders.append(i18n("Key")); |
| 133 | mHeaders.append(i18n("Value")); |
| 134 | mHeaders.append(i18n("Size in Bytes")); |
| 135 | |
| 136 | // icons |
| 137 | QPainter painter; |
| 138 | QPixmap pix(64, 64); |
| 139 | |
| 140 | QFont font; |
| 141 | font.setPixelSize(60); |
| 142 | |
| 143 | const auto color = qApp->palette().color(QPalette::Text); |
| 144 | painter.setPen(QPen(color)); |
| 145 | |
| 146 | // draw the icon for JSON array |
| 147 | pix.fill(QColor(Qt::transparent)); |
| 148 | painter.begin(&pix); |
| 149 | painter.setFont(font); |
| 150 | painter.drawText(pix.rect(), Qt::AlignCenter, QLatin1String("[ ]")); |
| 151 | painter.end(); |
| 152 | mArrayIcon = QIcon(pix); |
| 153 | |
| 154 | // draw the icon for JSON object |
| 155 | pix.fill(QColor(Qt::transparent)); |
| 156 | painter.begin(&pix); |
| 157 | painter.setFont(font); |
| 158 | painter.drawText(pix.rect(), Qt::AlignCenter, QLatin1String("{ }")); |
| 159 | painter.end(); |
| 160 | mObjectIcon = QIcon(pix); |
| 161 | } |
| 162 | |
| 163 | QJsonModel::~QJsonModel() { |
| 164 | // delete mRootItem; |