Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-241
Browse files Browse the repository at this point in the history
  • Loading branch information
ava57r committed Apr 7, 2018
2 parents 1a30061 + 2019ec6 commit 23ae9be
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 162 deletions.
139 changes: 139 additions & 0 deletions src/gtool1cd/BlobViewer/blob_viewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "blob_viewer.h"
#include "ui_blob_viewer.h"
#include <Parse_tree.h>
#include "../models/skobka_tree_model.h"
#include "../models/v8catalog_tree_model.h"
#include "../QHexEdit/qhexedit.h"
#include "../models/stream_device.h"
#include <Table.h>

BlobViewer::BlobViewer(QWidget *parent) :
QWidget(parent),
ui(new Ui::BlobViewer)
{
ui->setupUi(this);
}

BlobViewer::~BlobViewer()
{
delete ui;
}

void BlobViewer::setText(const QString &textData)
{
ui->tabWidget->removeTab(0);
ui->tabWidget->removeTab(0);
ui->tabWidget->removeTab(0);

QTextDocument *qd = new QTextDocument(textData);
qd->setDocumentLayout(new QPlainTextDocumentLayout(qd));
ui->plainTextEdit->setDocument(qd);

ui->tabWidget->addTab(ui->textDataTab, tr("Текст"));
ui->tabWidget->setCurrentWidget(ui->textDataTab);

if (textData.startsWith("{")) {
try {
auto t = parse_1Ctext(textData.toStdString(), "");
if (t != nullptr) {
ui->treeView->setModel(new SkobkaTreeModel( std::move(t) ));
ui->tabWidget->addTab(ui->parsedDataTab, tr("Дерево"));
ui->tabWidget->setCurrentWidget(ui->parsedDataTab);
}
} catch (...) {
}
}
}

QString extract_text_data(QIODevice *device)
{
auto buf = device->read(3);
if (buf.size() != 3) {
return QString::null;
}
if (buf[0] == '\xEF'
&& buf[1] == '\xBB'
&& buf[2] == '\xBF') {
return QString(device->readAll());
}

if (buf[0] == 'M'
&& buf[1] == 'O'
&& buf[2] == 'X') {
buf = device->read(3);
if (buf.size() != 3) {
return QString::null;
}
if (buf[0] == 'C'
&& buf[1] == 'E'
&& buf[2] == 'L') {
device->read(7); // заголовочные данные
device->read(3); // BOM
return QString(device->readAll());
}
}
return QString::null;
}

void BlobViewer::setStream(TStream *stream, const QString &rootName)
{
ui->tabWidget->removeTab(0);
ui->tabWidget->removeTab(0);
ui->tabWidget->removeTab(0);

auto cat = new V8Catalog(stream, false, true);
V8CatalogTreeModel *catalog_model = nullptr;
if (cat->isOpen() && cat->is_catalog()) {
catalog_model = new V8CatalogTreeModel(cat, rootName);
} else {
delete cat;
}

auto device = new StreamDevice(stream);
device->open(QIODevice::ReadOnly);

QString textData = extract_text_data(device);

device->close();

auto doc = QHexDocument::fromDevice(device);
ui->frame->setDocument(doc);

ui->tabWidget->addTab(ui->blobDataTab, tr("BLOB"));
ui->tabWidget->setCurrentWidget(ui->blobDataTab);

{
if (catalog_model) {
ui->tabWidget->addTab(ui->parsedDataTab, tr("Дерево"));
ui->tabWidget->setCurrentWidget(ui->parsedDataTab);
ui->treeView->setModel(catalog_model);
ui->treeView->expandAll();
return;
}

if (!textData.isNull()) {

ui->tabWidget->addTab(ui->textDataTab, tr("Текст"));
ui->tabWidget->setCurrentWidget(ui->textDataTab);

QTextDocument *qd = new QTextDocument(textData);
qd->setDocumentLayout(new QPlainTextDocumentLayout(qd));
ui->plainTextEdit->setDocument(qd);
ui->plainTextEdit->setDocumentTitle(rootName);

if (textData.startsWith("{")) {
try {
auto t = parse_1Ctext(textData.toStdString(), "");
if (t != nullptr) {
ui->treeView->setModel(new SkobkaTreeModel( std::move(t) ));
ui->treeView->expandAll();
ui->tabWidget->addTab(ui->parsedDataTab, tr("Дерево"));
ui->tabWidget->setCurrentWidget(ui->parsedDataTab);
}
} catch (...) {
}
}
}
}

}
28 changes: 28 additions & 0 deletions src/gtool1cd/BlobViewer/blob_viewer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef BLOB_VIEWER_H
#define BLOB_VIEWER_H

#include <QWidget>
#include <TStream.hpp>

namespace Ui {
class BlobViewer;
}

class BlobViewer : public QWidget
{
Q_OBJECT

public:
explicit BlobViewer(QWidget *parent = 0);
~BlobViewer();

void setText(const QString &textData);

void setStream(TStream *stream, const QString &rootName);

private:

Ui::BlobViewer *ui;
};

#endif // BLOB_VIEWER_H
124 changes: 124 additions & 0 deletions src/gtool1cd/BlobViewer/blob_viewer.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BlobViewer</class>
<widget class="QWidget" name="BlobViewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<property name="tabBarAutoHide">
<bool>true</bool>
</property>
<widget class="QWidget" name="parsedDataTab">
<attribute name="title">
<string>Данные</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="treeView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="textDataTab">
<attribute name="title">
<string>Текст</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="blobDataTab">
<attribute name="title">
<string>BLOB</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QHexEdit" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QHexEdit</class>
<extends>QFrame</extends>
<header>QHexEdit/qhexedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
6 changes: 3 additions & 3 deletions src/gtool1cd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ file (GLOB MODEL_SOURCES "models/*.cpp")
set(HEADER_FILES mainwindow.h starter.h littlelogwindow.h cache.h table_fields_window.h table_data_window.h
skobkatextwindow.h models/tables_list_model.h models/fields_list_model.h models/table_data_model.h
export_table_to_xml_dialog.h configurations_window.h
${MODEL_HEADERS} ${QHEXEDIT_HEADERS})
${MODEL_HEADERS} ${QHEXEDIT_HEADERS} BlobViewer/blob_viewer.h)
set(UI_FILES mainwindow.ui starter.ui littlelogwindow.ui table_fields_window.ui table_data_window.ui
skobkatextwindow.ui export_table_to_xml_dialog.ui configurations_window.ui)
skobkatextwindow.ui export_table_to_xml_dialog.ui configurations_window.ui BlobViewer/blob_viewer.ui)
set(SOURCE_FILES main.cpp mainwindow.cpp starter.cpp littlelogwindow.cpp cache.cpp table_fields_window.cpp table_data_window.cpp
skobkatextwindow.cpp export_table_to_xml_dialog.cpp configurations_window.cpp
${MODEL_SOURCES} ${QHEXEDIT_SOURCES})
${MODEL_SOURCES} ${QHEXEDIT_SOURCES} BlobViewer/blob_viewer.cpp)

add_executable(gtool1cd WIN32 ${SOURCE_FILES} ${HEADER_FILES} ${UI_FILES})

Expand Down
11 changes: 7 additions & 4 deletions src/gtool1cd/models/skobka_tree_model.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "skobka_tree_model.h"

const int PATH_COLUMN = 0;
const int DATA_COLUMN = 1;

SkobkaTreeModel::SkobkaTreeModel(unique_ptr<Tree> data_tree)
: data_tree(std::move(data_tree))
{
Expand Down Expand Up @@ -89,7 +92,7 @@ QVariant SkobkaTreeModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) {
Tree *item = static_cast<Tree*>(index.internalPointer());
switch (index.column()) {
case 0: {
case DATA_COLUMN: {
if (item->get_type() == node_type::nd_list) {
QString result = QString(tr("{Элементов: %1}")).arg(item->get_num_subnode());
return result;
Expand All @@ -98,7 +101,7 @@ QVariant SkobkaTreeModel::data(const QModelIndex &index, int role) const
item->outtext(presentation);
return QString::fromStdString(presentation);
}
case 1:
case PATH_COLUMN:
return QString::fromStdString(item->path());
}
}
Expand All @@ -110,9 +113,9 @@ QVariant SkobkaTreeModel::headerData(int section, Qt::Orientation orientation, i
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
switch (section) {
case 0:
case DATA_COLUMN:
return tr("Значение");
case 1:
case PATH_COLUMN:
return tr("Путь");
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/gtool1cd/models/stream_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ void StreamDevice::close()
setOpenMode(NotOpen);
}

bool StreamDevice::isSequential() const
{
return false;
}

4 changes: 3 additions & 1 deletion src/gtool1cd/models/stream_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class StreamDevice : public QIODevice
explicit StreamDevice(TStream *stream);
virtual ~StreamDevice();

bool isSequential() const override;
void close() override;

protected:

qint64 readData(char *data, qint64 maxlen) override;
qint64 writeData(const char *data, qint64 len) override;
qint64 size() const override;
qint64 pos() const override;
bool seek(qint64 pos) override;
void close() override;

private:
TStream *stream;
Expand Down
4 changes: 2 additions & 2 deletions src/gtool1cd/models/table_data_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const TableRecord *TableDataModel::getRecord(const QModelIndex &index) const

}

QIODevice *TableDataModel::getBlobStream(const QModelIndex &index) const
TStream *TableDataModel::getBlobStream(const QModelIndex &index) const
{
Field *f = table->get_field(index.column());
TableRecord *record = _index == nullptr
Expand All @@ -186,5 +186,5 @@ QIODevice *TableDataModel::getBlobStream(const QModelIndex &index) const
if (!record->try_store_blob_data(f, out, true)) {
return nullptr;
}
return new StreamDevice(out);
return out;
}
Loading

0 comments on commit 23ae9be

Please sign in to comment.