Skip to content

Commit

Permalink
Merge branch 'origin/develop' into open-containers
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpas committed Apr 7, 2018
2 parents 0caeef5 + f7c2db4 commit 5e23a33
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 168 deletions.
8 changes: 4 additions & 4 deletions src/gtool1cd/BlobViewer/blob_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ void BlobViewer::setText(const QString &textData)

if (textData.startsWith("{")) {
try {
tree* t = parse_1Ctext(textData.toStdString(), "");
auto t = parse_1Ctext(textData.toStdString(), "");
if (t != nullptr) {
ui->treeView->setModel(new SkobkaTreeModel(t));
ui->treeView->setModel(new SkobkaTreeModel( std::move(t) ));
ui->tabWidget->addTab(ui->parsedDataTab, tr("Дерево"));
ui->tabWidget->setCurrentWidget(ui->parsedDataTab);
}
Expand Down Expand Up @@ -127,9 +127,9 @@ void BlobViewer::setStream(TStream *stream, const QString &rootName)

if (textData.startsWith("{")) {
try {
tree* t = parse_1Ctext(textData.toStdString(), "");
auto t = parse_1Ctext(textData.toStdString(), "");
if (t != nullptr) {
ui->treeView->setModel(new SkobkaTreeModel(t));
ui->treeView->setModel(new SkobkaTreeModel( std::move(t) ));
ui->treeView->expandAll();
ui->tabWidget->addTab(ui->parsedDataTab, tr("Дерево"));
ui->tabWidget->setCurrentWidget(ui->parsedDataTab);
Expand Down
42 changes: 31 additions & 11 deletions src/gtool1cd/models/skobka_tree_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
const int PATH_COLUMN = 0;
const int DATA_COLUMN = 1;

SkobkaTreeModel::SkobkaTreeModel(tree *data_tree)
: data_tree(data_tree)
SkobkaTreeModel::SkobkaTreeModel(unique_ptr<Tree> data_tree)
: data_tree(std::move(data_tree))
{

}
Expand All @@ -17,16 +17,27 @@ int SkobkaTreeModel::rowCount(const QModelIndex &parent) const
return 0;
}

tree *parentItem = parent.isValid() ? static_cast<tree*>(parent.internalPointer()) : data_tree;
return parentItem->get_num_subnode();
int result = 0;

if (parent.isValid())
{
Tree *parentItem = static_cast<Tree*>(parent.internalPointer());
result = parentItem->get_num_subnode();
}
else
{
result = data_tree->get_num_subnode();
}

return result;
}

int SkobkaTreeModel::columnCount(const QModelIndex &parent) const
{
return 2;
}

static int index_of(tree *parent, tree *child)
static int index_of(Tree *parent, Tree *child)
{
if (parent == nullptr) {
return -1;
Expand All @@ -45,8 +56,17 @@ QModelIndex SkobkaTreeModel::index(int row, int column, const QModelIndex &paren
return QModelIndex();
}

tree *parentItem = parent.isValid() ? static_cast<tree*>(parent.internalPointer()) : data_tree;
tree *childItem = parentItem->get_subnode(row);
Tree * childItem = nullptr;
if(parent.isValid())
{
Tree *parentItem = static_cast<Tree*>(parent.internalPointer());
childItem = parentItem->get_subnode(row);
}
else
{
childItem = data_tree->get_subnode(row);
}

if (childItem == nullptr) {
return QModelIndex();
}
Expand All @@ -56,9 +76,9 @@ QModelIndex SkobkaTreeModel::index(int row, int column, const QModelIndex &paren
QModelIndex SkobkaTreeModel::parent(const QModelIndex &child) const
{
if (child.isValid()) {
tree *childItem = static_cast<tree*>(child.internalPointer());
tree *parentItem = childItem->get_parent();
if (parentItem != nullptr && parentItem != data_tree) {
Tree *childItem = static_cast<Tree*>(child.internalPointer());
Tree *parentItem = childItem->get_parent();
if (parentItem != nullptr && parentItem != data_tree.get()) {
int parent_index = index_of(parentItem->get_parent(), parentItem);
return createIndex(parent_index, 0, parentItem);
}
Expand Down Expand Up @@ -88,7 +108,7 @@ QVariant SkobkaTreeModel::data(const QModelIndex &index, int role) const
return QVariant();
}

tree *item = static_cast<tree*>(index.internalPointer());
Tree *item = static_cast<Tree*>(index.internalPointer());
if (role == Qt::DisplayRole
|| role == Qt::EditRole
|| role == Qt::ToolTipRole) {
Expand Down
4 changes: 2 additions & 2 deletions src/gtool1cd/models/skobka_tree_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class SkobkaTreeModel : public QAbstractItemModel
{
public:
explicit SkobkaTreeModel(tree *data_tree);
explicit SkobkaTreeModel(unique_ptr<Tree> data_tree);


virtual int rowCount(const QModelIndex &parent) const override;
Expand All @@ -23,7 +23,7 @@ class SkobkaTreeModel : public QAbstractItemModel
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

private:
tree* data_tree;
unique_ptr<Tree> data_tree;
};

#endif // SKOBKA_TREE_MODEL_H
5 changes: 2 additions & 3 deletions src/gtool1cd/table_data_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ void TableDataWindow::on_dataView_activated(const QModelIndex &index)
{
}

tree *try_parse_tree(const QVariant &data)
unique_ptr<Tree> try_parse_tree(const QVariant &data)
{
std::string string_data = data.toString().toStdString();
if (string_data.substr(0, 1) != "{") {
return nullptr;
}
try {
tree *data_tree = parse_1Ctext(string_data, "");
auto data_tree = parse_1Ctext(string_data, "");
return data_tree;
} catch (...) {
return nullptr;
Expand Down Expand Up @@ -158,7 +158,6 @@ void TableDataWindow::dataView_selection_changed(const QItemSelection &selection
}

ui->dataWidget->setText(data.toString());

}

void TableDataWindow::on_saveBlobButton_clicked()
Expand Down
5 changes: 2 additions & 3 deletions src/tests/tool1cd/test_fieldparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ using namespace std;

static Field *load_field(const string &description)
{
tree *field_tree = parse_1Ctext(description, "");
tree *first_entry = field_tree->get_first()->get_first();
auto field_tree = parse_1Ctext(description, "");
Tree *first_entry = field_tree->get_first()->get_first();
bool has_version = false;
Field *fld = Field::field_from_tree(first_entry, has_version, nullptr);
delete field_tree;
return fld;
}

Expand Down
6 changes: 2 additions & 4 deletions src/tests/tool1cd/test_treeparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ TEST_CASE( "Проверка Parse_tree", "[tool1cd][common][Parse_tree]" ) {
WHEN ("Парсим и выводим дерево через поток") {
std::string from_stream;
TBytesStream bs(TEncoding::UTF8->fromUtf8(test_tree_source));
tree *tree_from_stream = parse_1Cstream(&bs, "");
auto tree_from_stream = parse_1Cstream(&bs, "");
REQUIRE(tree_from_stream != nullptr);
tree_from_stream->outtext(from_stream);
delete tree_from_stream;

AND_WHEN("Парсим и выводим дерево через строку") {
std::string from_string;
tree *tree_from_string = parse_1Ctext(test_tree_source, "");
auto tree_from_string = parse_1Ctext(test_tree_source, "");
REQUIRE(tree_from_string != nullptr);
tree_from_string->outtext(from_string);
delete tree_from_string;

THEN("Получаем одинаковые значения") {
REQUIRE(from_stream == from_string);
Expand Down
26 changes: 11 additions & 15 deletions src/tool1cd/Class_1CD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,22 +1107,18 @@ bool T_1CD::recursive_test_stream_format(TStream *str, const string &path, bool
}
}
if (first_symbol == '{' && !EqualIC(sf.substr(i, 15), "{ХАРАКТЕРИСТИКИ")) {
tree* rt = parse_1Ctext(sf, path);
if(rt)
auto rt = parse_1Ctext(sf, path);
if(rt != nullptr)
{
result = true;
delete rt;
}
else result = false;
}
else result = true;

}
else result = true;


delete _sb;

}
else result = recursive_test_stream_format(cat, path);

Expand Down Expand Up @@ -1194,7 +1190,6 @@ bool T_1CD::create_table(const string &path)
V8Object* file_data;
V8Object* file_blob;
V8Object* file_index;
tree* t;

boost::filesystem::path dir(path);
if(!directory_exists(dir)) {
Expand Down Expand Up @@ -1230,8 +1225,11 @@ bool T_1CD::create_table(const string &path)
string descr_data = from_unicode_stream(*f);
delete f;

t = parse_1Ctext(descr_data, path_descr.string());
string table_name = (*t)[0][0].get_value();
string table_name;
{
auto t = parse_1Ctext(descr_data, path_descr.string());
table_name = (*t)[0][0].get_value();
}

for(j = 0; j < num_tables; j++) {
if (EqualIC(tables[j]->get_name(), table_name)) {
Expand Down Expand Up @@ -1389,8 +1387,8 @@ bool T_1CD::test_list_of_tables()
int32_t i, j, l, l2;
uint32_t k;
int32_t offset;
tree* t;
tree* firstt;
Tree* t;
Tree* firstt;

if(!table_params)
{
Expand Down Expand Up @@ -1515,8 +1513,8 @@ bool T_1CD::test_list_of_tables()
}
if(first_symbol == '{')
{
tree* rt = parse_1Ctext(sf, "PARAMS/DBNames");
if(rt)
auto rt = parse_1Ctext(sf, "PARAMS/DBNames");
if(rt != nullptr)
{
firstt = &((*rt)[0][1][1]);

Expand Down Expand Up @@ -1576,8 +1574,6 @@ bool T_1CD::test_list_of_tables()
.add_detail("Имя таблицы", _tabname);
}
}

delete rt;
}
else result = false;
}
Expand Down
Loading

0 comments on commit 5e23a33

Please sign in to comment.