diff options
| author | Stijn Buys <ingar@osirion.org> | 2012-02-21 20:06:17 +0000 | 
|---|---|---|
| committer | Stijn Buys <ingar@osirion.org> | 2012-02-21 20:06:17 +0000 | 
| commit | 4460f43972bd52c498161c64d4ddcc4da4c45d20 (patch) | |
| tree | bf9f56c6d0e04bc249986e4bfc2fd1fa30e1c60f /src | |
| parent | 43c292e1dda7c789a31cdb679065c75d8f8cebba (diff) | |
Add support for zone properties, added framework to save files.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 3 | ||||
| -rw-r--r-- | src/editorwindow.cc | 22 | ||||
| -rw-r--r-- | src/editorwindow.h | 4 | ||||
| -rw-r--r-- | src/entityproperties.cc | 45 | ||||
| -rw-r--r-- | src/entityproperties.h | 7 | ||||
| -rw-r--r-- | src/mainwindow.cc | 28 | ||||
| -rw-r--r-- | src/mainwindow.h | 5 | ||||
| -rw-r--r-- | src/mapwidget.cc | 9 | ||||
| -rw-r--r-- | src/mapwidget.h | 2 | ||||
| -rw-r--r-- | src/zoneproperties.cc | 50 | ||||
| -rw-r--r-- | src/zoneproperties.h | 35 | 
11 files changed, 204 insertions, 6 deletions
| diff --git a/src/Makefile.am b/src/Makefile.am index 08b3859..3614a61 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,8 @@ editor_SOURCES = \  	mapwidget.cc \  	properties.cc \  	sidebar.cc \ -	vector3f.cc +	vector3f.cc \ +	zoneproperties.cc  # You have one .h file, it's called editor.h. Therefore, here I list  # its mocced name, moc_editor.cpp. diff --git a/src/editorwindow.cc b/src/editorwindow.cc index 759263f..208c309 100644 --- a/src/editorwindow.cc +++ b/src/editorwindow.cc @@ -152,7 +152,14 @@ bool EditorWindow::loadFile(const QString &filename)  			} else if (ini.in_section("zone")) {  				if (ini.got_key_string("name", str)) { +					editorwindow_zoneproperties.set_name(str);  					editorwindow_sidebar->setZoneName(str); +				 +				} else if (ini.got_key_string("info", str)) { +					editorwindow_zoneproperties.add_info(str); + +				} else if (ini.got_key()) { +					editorwindow_zoneproperties.add_value(ini.key(), ini.value());  				}  			} @@ -169,8 +176,21 @@ bool EditorWindow::loadFile(const QString &filename)  bool EditorWindow::saveFile(const QString &filename)  { - +	QString buffer; +	QTextStream textstream(&buffer); +		 +	editorwindow_zoneproperties.save(textstream); +	editorwindow_mapwidget->save(textstream); +	 +	// debug output +	QTextStream out(&buffer);	 +	QString line; +	while (!out.atEnd()) { +		line = out.readLine(1024); +		qDebug() << line; +	}  } +  } diff --git a/src/editorwindow.h b/src/editorwindow.h index 4305aea..ddd0f57 100644 --- a/src/editorwindow.h +++ b/src/editorwindow.h @@ -8,6 +8,8 @@  #ifndef __INCLUDED_EDITOR_EDITORWINDOW__  #define __INCLUDED_EDITOR_EDITORWINDOW__ +#include "zoneproperties.h" +  #include <QWidget>  class QSplitter; @@ -39,6 +41,8 @@ private:  	MapWidget	*editorwindow_mapwidget;  	SideBar		*editorwindow_sidebar;  	QSplitter	*editorwindow_splitter; +	 +	ZoneProperties	editorwindow_zoneproperties;  };  } diff --git a/src/entityproperties.cc b/src/entityproperties.cc index 371746f..84a6bc4 100644 --- a/src/entityproperties.cc +++ b/src/entityproperties.cc @@ -39,4 +39,49 @@ void EntityProperties::add_subsection_value(const QString &key, const QString &v  	properties_subsections += '\n';  } +void EntityProperties::save(QTextStream &textstream) +{ +	textstream << "[" << type() << "]" << '\n'; +	if (label().size()) +		textstream << "label=" << label() << '\n'; +	if (name().size()) +		textstream << "name=" << name() << '\n'; +	 +	// other values +	if (values().size()) { +		textstream << values(); +	} +	 +	// info string +	if (info().size()) { +		textstream << '\n'; +		 +		// QTextStream operates on QString, not on QString const +		QString infobuffer = info(); +		QTextStream infostream(&infobuffer); +		QString line; +		while (!infostream.atEnd()) { +			line = infostream.readLine(1024); +			textstream << "info=" << line << '\n'; +		} +	} + +	if (subsections().size()) { +		textstream << '\n'; +		 +		QString subsectionbuffer = subsections(); +		QTextStream subsectionstream(&subsectionbuffer); +		QString line; +		while (!subsectionstream.atEnd()) { +			line = subsectionstream.readLine(1024); +			if (line.size()) +				textstream << '\t' << line << '\n'; +			else +				textstream << '\n'; +		} +		 +	} +	 +	textstream << '\n'; +}  } // namespace editor diff --git a/src/entityproperties.h b/src/entityproperties.h index 6189309..f91be1a 100644 --- a/src/entityproperties.h +++ b/src/entityproperties.h @@ -10,6 +10,8 @@  #include "properties.h" +#include <QTextStream> +  namespace editor  { @@ -22,6 +24,11 @@ public:  	EntityProperties();  	virtual ~EntityProperties(); +	/** +	 * @brief save ini formatted entity properties to a textstream +	 * */ +	virtual void save(QTextStream &textstream); +	  	/* ---- inspectors ---- */  	/** diff --git a/src/mainwindow.cc b/src/mainwindow.cc index f80f0ab..d1069d7 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -48,6 +48,11 @@ void MainWindow::init_actions()  	action_open->setStatusTip(tr("Open an existing zone"));  	connect(action_open, SIGNAL(triggered()), this, SLOT(slot_open())); +	action_save  = new QAction( tr("&Save..."), this); +	action_save->setShortcuts(QKeySequence::Save); +	action_save->setStatusTip(tr("Save File")); +	connect(action_save, SIGNAL(triggered()), this, SLOT(slot_save())); +	  	// File -> Quit  	action_quit = new QAction(tr("&Quit"), this);  	action_quit->setShortcuts(QKeySequence::Quit); @@ -60,13 +65,22 @@ void MainWindow::init_menu()  	mainwindow_filemenu = menuBar()->addMenu(tr("&File"));  	mainwindow_filemenu->addAction(action_new);  	mainwindow_filemenu->addAction(action_open); +	mainwindow_filemenu->addAction(action_save);  	mainwindow_filemenu->addSeparator();  	mainwindow_filemenu->addAction(action_quit);  	mainwindow_editmenu = menuBar()->addMenu(tr("&Edit"));  } -EditorWindow *MainWindow::addEditorWindow() + +EditorWindow *MainWindow::active_child() +{ +	if (QMdiSubWindow *active_subwindow = mainwindow_mdiarea->activeSubWindow()) +		return qobject_cast<EditorWindow *>(active_subwindow->widget()); +	return 0; +} + +EditorWindow *MainWindow::add_child()  {  	// create a child widget  	EditorWindow *child_widget = new EditorWindow(); @@ -85,7 +99,7 @@ EditorWindow *MainWindow::addEditorWindow()  void MainWindow::slot_new()  { -	addEditorWindow(); +	add_child();  }  void MainWindow::slot_open() @@ -93,10 +107,18 @@ void MainWindow::slot_open()  	QString filename = QFileDialog::getOpenFileName(this, tr("Open file"));  	if (!filename.isEmpty()) { -		EditorWindow *editorwindow = addEditorWindow(); +		EditorWindow *editorwindow = add_child();  		editorwindow->loadFile(filename);  	}  } +void MainWindow::slot_save() +{ +	QString filename; +	 +	if (active_child()) { +		active_child()->saveFile(filename); +	} +}  } diff --git a/src/mainwindow.h b/src/mainwindow.h index 82a14db..48e8927 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,12 +31,14 @@ public:  private slots:  	void slot_new();  	void slot_open(); +	void slot_save();  private:  	void init_actions();  	void init_menu(); -	EditorWindow *addEditorWindow(); +	EditorWindow *add_child(); +	EditorWindow *active_child();  	QMdiArea	*mainwindow_mdiarea;  	QMenu		*mainwindow_filemenu; @@ -44,6 +46,7 @@ private:  	QAction		*action_new;  	QAction		*action_open; +	QAction		*action_save;  	QAction		*action_quit;  }; diff --git a/src/mapwidget.cc b/src/mapwidget.cc index d9ec735..f2fe7e7 100644 --- a/src/mapwidget.cc +++ b/src/mapwidget.cc @@ -249,4 +249,13 @@ EntityWidget *MapWidget::addEntity()  	return entitywidget;  } +void MapWidget::save(QTextStream &textstream) +{ +	for (int i = 0; i < mapwidget_enties.size(); ++i) { +		 +		EntityWidget *entitywidget = mapwidget_enties.at(i); +		entitywidget->properties()->save(textstream); +	} +} +  } diff --git a/src/mapwidget.h b/src/mapwidget.h index 0afcaff..c68d127 100644 --- a/src/mapwidget.h +++ b/src/mapwidget.h @@ -32,6 +32,8 @@ public:  	 * @brief add an entity to the map  	 * */  	EntityWidget *addEntity(); +	 +	void save(QTextStream &textstream);  protected: diff --git a/src/zoneproperties.cc b/src/zoneproperties.cc index e69de29..35d994a 100644 --- a/src/zoneproperties.cc +++ b/src/zoneproperties.cc @@ -0,0 +1,50 @@ +/* +   zonecc +   This file is part of the Project::OSiRiON world editor  +   and is distributed under the terms and conditions of  +   the GNU General Public License version 2 +*/ + +#include "zoneproperties.h" + +namespace editor +{ + +ZoneProperties::ZoneProperties() : Properties() +{ +} + +ZoneProperties::~ZoneProperties() +{ +} + +void ZoneProperties::save(QTextStream & textstream) +{ +	textstream << "[zone]" << '\n'; +	 +	if (name().size()) +		textstream << "name=" << name() << '\n'; +	 +	// other values +	if (values().size()) { +		textstream << values(); +	} +	 +	// info string +	if (info().size()) { +		textstream << '\n'; +		 +		// QTextStream operates on QString, not on QString const +		QString infobuffer = info(); +		QTextStream infostream(&infobuffer); +		QString line; +		while (!infostream.atEnd()) { +			line = infostream.readLine(1024); +			textstream << "info=" << line << '\n'; +		} +	} + +	textstream << '\n'; +} + +} // namespace editor diff --git a/src/zoneproperties.h b/src/zoneproperties.h index e69de29..9b79569 100644 --- a/src/zoneproperties.h +++ b/src/zoneproperties.h @@ -0,0 +1,35 @@ +/* +   zoneproperties.h +   This file is part of the Project::OSiRiON world editor  +   and is distributed under the terms and conditions of  +   the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_EDITOR_ZONEPROPERTIES__ +#define __INCLUDED_EDITOR_ZONEPROPERTIES__ + +#include "properties.h" + +#include <QTextStream> + +namespace editor +{ + +/** + * @brief contains the game properties for a zone + * */ +class ZoneProperties : public Properties +{ +public: +	ZoneProperties(); +	virtual ~ZoneProperties(); +	 +	/** +	 * @brief save ini formatted zone properties to a textstream +	 * */ +	virtual void save(QTextStream &textstream); +}; + +} // namespace editor + +#endif // __INCLUDED_EDITOR_ZONEPROPERTIES__ | 
