aboutsummaryrefslogtreecommitdiff
path: root/src/gatscon/filewidget.cpp
blob: dbd70fd4a32721c3f42d5430fffef36f22994549 (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
#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()
{
}