aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/gatscon/filewidget.cpp
blob: 306dbf2b11c3a3ee3ef5552351c626218d329598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2007-2013 Xagasoft, All rights reserved.
 *
 * This file is part of the libgats library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "filewidget.h"

#include "gatstotree.h"
#include "treetogats.h"

#include <gats/types.h>
#include <gats/gatsstream.h>
#include <bu/file.h>

#include <QInputDialog>

using namespace Bu;

FileWidget::FileWidget( QWidget *pParent ) :
    QWidget( pParent )
{
    setupUi( this );
}

FileWidget::FileWidget( QWidget *pParent, QString sFile ) :
    QWidget( pParent )
{
    setupUi( this );

    File fIn( sFile.toAscii().constData(), File::Read );
    Gats::GatsStream gsIn( fIn );
    Gats::Object *pObj;
    while( (pObj = gsIn.readObject()) )
    {
        QTreeWidgetItem *pNew = new QTreeWidgetItem(
            twGats->invisibleRootItem()
            );
        pNew->setText( 0, "<root>" );
        gatsToTree( pNew, pObj );
        delete pObj;
    }
}

FileWidget::~FileWidget()
{
}

void FileWidget::saveTo( const QString &sFile )
{
    File fOut( sFile.toAscii().constData(), File::WriteNew );
    Gats::GatsStream gsOut( fOut );
    QTreeWidgetItem *pRoot = twGats->invisibleRootItem();
    for( int j = 0; j < pRoot->childCount(); j++ )
    {
        Gats::Object *pObj = treeToGats( pRoot->child( j ) );
        gsOut.writeObject( pObj );
        delete pObj;
    }
}

void FileWidget::addRootItem()
{
    QString sText = QInputDialog::getText( this, "Gats Console - Add Root Item",
            "Gats:");
    Gats::Object *pObj = Gats::Object::strToGats( sText.toAscii().constData() );
    QTreeWidgetItem *pNew = new QTreeWidgetItem(
        twGats->invisibleRootItem()
        );
    pNew->setText( 0, "<root>" );
    gatsToTree( pNew, pObj );
    delete pObj;
}

void FileWidget::delRootItem()
{
}