Skip to content

Commit

Permalink
GUI: просмотр контейнера конфигурации поставщика.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpas committed Apr 6, 2018
1 parent 479e953 commit b8db439
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions src/gtool1cd/models/table_data_model.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "table_data_model.h"
#include <QFont>
#include "stream_device.h"
#include <TempStream.h>
#include <UZLib.h>
#include <QDebug>

TableDataModel::TableDataModel(Table *table, Index *index)
: table(table), _index(index) {}
Expand Down Expand Up @@ -141,28 +144,42 @@ bool TableDataModel::isClobValue(const QModelIndex &index) const
|| f->get_type() == type_fields::tf_text;
}

V8Catalog *TableDataModel::getCatalog(const QModelIndex &index) const
TStream *new_stream(int64_t needed_size)
{
Field *f = table->get_field(index.column());
TableRecord *record = _index == nullptr
? table->get_record(index.row())
: table->get_record(_index->get_numrec(index.row()));

TStream *data_stream;
const int threshold = 10 * 1024 * 1024;
if (needed_size < threshold) {
return new TMemoryStream();
}
return new TTempStream();
}

if (!record->try_store_blob_data(f, data_stream, true)) {
if (!record->try_store_blob_data(f, data_stream, false)){
return nullptr;
int inflate_stream(TStream* &stream)
{
int counter = 0;
while (true) {
TStream *unpacked_stream = new_stream(stream->GetSize());
stream->SetPosition(0);
try {
ZInflateStream(stream, unpacked_stream);
} catch (ZError &) {
return counter;
}
stream = unpacked_stream;
if (counter++ > 10) {
return counter;
}
}
}

{
auto *cat = new V8Catalog(data_stream, false, false);
if (cat->isOpen() && cat->is_catalog()) {
return cat;
}
delete cat;
V8Catalog *TableDataModel::getCatalog(const QModelIndex &index) const
{
TStream *data_stream = getBlobStream(index);

auto *cat = new V8Catalog(data_stream, false, false);
if (cat->isOpen() && cat->is_catalog()) {
return cat;
}
delete cat;

return nullptr;
}
Expand All @@ -183,8 +200,12 @@ TStream *TableDataModel::getBlobStream(const QModelIndex &index) const
: table->get_record(_index->get_numrec(index.row()));

TStream *out;
if (!record->try_store_blob_data(f, out, true)) {
if (!record->try_store_blob_data(f, out, false)) {
return nullptr;
}

int count = inflate_stream(out);
qDebug() << "Deflate count: " << count;

return out;
}

0 comments on commit b8db439

Please sign in to comment.