forked from e8tools/tool1cd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/issue-241
- Loading branch information
Showing
13 changed files
with
395 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (...) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,8 @@ void StreamDevice::close() | |
setOpenMode(NotOpen); | ||
} | ||
|
||
bool StreamDevice::isSequential() const | ||
{ | ||
return false; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.