# HG changeset patch
# User insilmaril
# Date 1194535683 0
# Node ID 16d63fc9ae425e47697041af6ffb160d3a433aff
# Parent  497f19b3c1fec82c321547c48cff5be5c2110f28
1.11.2 split up of xml helper functions. started to work on attributes

diff -r 497f19b3c1fe -r 16d63fc9ae42 attribute.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/attribute.cpp	Thu Nov 08 15:28:03 2007 +0000
@@ -0,0 +1,101 @@
+#include "attribute.h"
+
+Attribute::Attribute()
+{
+	key="";
+	value="";
+}
+
+void Attribute::setKey (const QString &k)
+{
+	key=k;
+}
+
+QString Attribute::getKey ()
+{
+	return key;
+}
+
+void Attribute::setValue(const QString &v)
+{
+	value=v;
+}
+
+QString Attribute::getValue()
+{
+	return value;
+}
+
+QString Attribute::getDataXML()
+{
+	return valueElement ("attribute",key,value);
+}
+
+
+///////////////////////////////////////////////////////////////
+AttributeTable::AttributeTable()
+{
+	clear();
+}
+
+AttributeTable::~AttributeTable()
+{
+}
+
+void AttributeTable::clear ()
+{
+	keys.clear();
+	values.clear();
+}
+
+void AttributeTable::addKey (const QString &k)
+{
+	if (!keys.contains (k) )
+	{
+		keys.append (k);
+		values.append (QStringList() );
+	}
+}
+
+void AttributeTable::removeKey (const QString &k)
+{
+	int i=keys.indexOf (k);
+	if (i>=0)
+	{
+		keys.removeAt(i);
+		values.removeAt(i);
+	}
+}
+
+void AttributeTable::addValue (const QString &k, const QString &v)
+{
+	int i=keys.indexOf (k);
+	if (i<0)
+	{
+		keys.append (k);
+		values.append (QStringList (v));
+	} else
+	{
+		int j=values.at(i).indexOf(k);
+		if (j<0) values[i].append (QString(v));
+	}
+}
+
+QStringList AttributeTable::getKeys ()
+{
+	return keys;
+}
+
+QStringList AttributeTable::getValues(const QString &k)
+{
+	int i=keys.indexOf (k);
+	if (i>=0)
+		return values.at(i);
+	else
+		return QStringList();
+}
+
+QString AttributeTable::getDataXML()
+{
+	return valueElement ("attributeList","key","value");
+}
diff -r 497f19b3c1fe -r 16d63fc9ae42 attribute.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/attribute.h	Thu Nov 08 15:28:03 2007 +0000
@@ -0,0 +1,49 @@
+#ifndef ATTRIBUTE_H
+#define ATTRIBUTE_H
+
+#include <QStringList>
+
+#include "xmlobj.h"
+
+
+/*! \brief A key and a list of values
+*/
+
+class Attribute:public XMLObj {
+public:
+	Attribute();
+	virtual void setKey (const QString &k);
+	virtual QString getKey ();
+	virtual void setValue (const QString &v);
+	virtual QString getValue();
+	virtual QString getDataXML();
+protected:
+	QString key;
+	QString value;
+};
+
+/*! \brief A table containing a list of keys and each of these keys has
+   a list of default values. The keys and the values for each key are
+   unique.
+*/
+class AttributeTable:public XMLObj{
+public:
+	AttributeTable();
+	virtual ~AttributeTable();
+	virtual void clear();
+	virtual void addKey (const QString &k);		//!< Adds a key to the table
+	virtual void removeKey (const QString &k);	//!< Removes key and its default values
+	virtual void addValue (const QString &k, const QString &v);	//!< Adds key and value
+	virtual QStringList getKeys ();
+	virtual QStringList getValues(const QString &k);
+	virtual QString getDataXML();
+
+protected:
+	QStringList keys;
+	QList <QStringList> values;
+};
+
+
+
+#endif
+
diff -r 497f19b3c1fe -r 16d63fc9ae42 branchobj.cpp
--- a/branchobj.cpp	Tue Nov 06 13:54:41 2007 +0000
+++ b/branchobj.cpp	Thu Nov 08 15:28:03 2007 +0000
@@ -1,7 +1,11 @@
 #include "branchobj.h"
-#include "texteditor.h"
+
+// #include "texteditor.h"
 #include "mapeditor.h"
 #include "mainwindow.h"
+#include "misc.h"
+
+class TextEditor;
 
 extern TextEditor *textEditor;
 extern Main *mainWindow;
diff -r 497f19b3c1fe -r 16d63fc9ae42 linkablemapobj.h
--- a/linkablemapobj.h	Tue Nov 06 13:54:41 2007 +0000
+++ b/linkablemapobj.h	Thu Nov 08 15:28:03 2007 +0000
@@ -6,8 +6,10 @@
 #include "headingobj.h"
 #include "flagrowobj.h"
 
+#define MAX_DEPTH 999
 
-#define MAX_DEPTH 999
+class MapEditor;
+
 
 
 /*! \brief This class adds links to MapObj 
diff -r 497f19b3c1fe -r 16d63fc9ae42 mainwindow.cpp
--- a/mainwindow.cpp	Tue Nov 06 13:54:41 2007 +0000
+++ b/mainwindow.cpp	Thu Nov 08 15:28:03 2007 +0000
@@ -2773,6 +2773,88 @@
 	} // currentMapEditor()	
 }
 
+void Main::editAttributeFinished()
+{
+	// only called from editHeading(), so there is a currentME
+
+	/*
+	MapEditor *me=currentMapEditor();
+	if (me)
+	{
+		me->setStateEditHeading (false);
+		QPoint p;	//Not used here, only to find out pos of branch
+		bool ok;
+		QString s=me->getHeading(ok,p);
+
+#if defined(Q_OS_MACX)
+#else
+		if (ok && s!=lineedit->text())
+			me->setHeading(lineedit->text());
+			
+		lineedit->releaseKeyboard();
+		lineedit->hide();
+		setFocus();
+#endif	
+		if (!actionSettingsAutoSelectNewBranch->isOn() && 
+			!prevSelection.isEmpty()) 
+			me->select(prevSelection);
+		prevSelection="";
+	}
+	*/
+}
+
+void Main::editAttribute()
+{
+	/*
+	if (currentMapEditor())
+	{
+		MapEditor *me=currentMapEditor();
+		QString oldSel=me->getSelectString();
+
+		if (lineedit->isVisible())
+			editAttributeFinished();
+		else
+		{
+			bool ok;
+			QPoint p;
+			QString s=me->getHeading(ok,p);
+
+			if (ok)
+			{
+				me->setStateEditHeading (true);
+#if defined(Q_OS_MACX)
+				p=me->mapToGlobal (p);
+				QDialog *d =new QDialog(NULL);
+				QLineEdit *le=new QLineEdit (d);
+				d->setWindowFlags (Qt::FramelessWindowHint);
+				d->setGeometry(p.x(),p.y(),230,25);
+				le->resize (d->width()-10,d->height());
+				le->setText (s);
+				le->selectAll();
+				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
+				d->activateWindow();
+				d->exec();
+				me->setHeading (le->text());
+				delete (le);
+				delete (d);
+				editHeadingFinished();
+#else
+				p=me->mapTo (this,p);
+				lineedit->setGeometry(p.x(),p.y(),230,25);
+				lineedit->setText(s);
+				lineedit->setCursorPosition(1);
+				lineedit->selectAll();
+				lineedit->show();
+				lineedit->grabKeyboard();
+				lineedit->setFocus();
+#endif
+			}
+		} 
+	} // currentMapEditor()	
+
+	*/
+}
+
 void Main::openVymLinks(const QStringList &vl)
 {
 	for (int j=0; j<vl.size(); j++)
@@ -3646,7 +3728,8 @@
 void Main::testFunction1()
 {
 	if (!currentMapEditor()) return;
-	currentMapEditor()->testFunction1();
+	//currentMapEditor()->testFunction1();
+	editAttribute();
 }
 
 void Main::testFunction2()
diff -r 497f19b3c1fe -r 16d63fc9ae42 mainwindow.h
--- a/mainwindow.h	Tue Nov 06 13:54:41 2007 +0000
+++ b/mainwindow.h	Thu Nov 08 15:28:03 2007 +0000
@@ -117,8 +117,10 @@
 	void editVymLink();
 	void editOpenMultipleVymLinks();
     void editHeadingFinished();
+    void editAttributeFinished();
 public slots:
     void editHeading();
+    void editAttribute();
 	void editOpenVymLink();
 private slots:
 	void editDeleteVymLink();
diff -r 497f19b3c1fe -r 16d63fc9ae42 mapeditor.cpp
--- a/mapeditor.cpp	Tue Nov 06 13:54:41 2007 +0000
+++ b/mapeditor.cpp	Thu Nov 08 15:28:03 2007 +0000
@@ -301,7 +301,7 @@
 	}
 
 	// Save local settings
-	s+=settings.getXMLData (destPath);
+	s+=settings.getDataXML (destPath);
 
 	// Save selection
 	if (!xelection.isEmpty() && !saveSel ) 
diff -r 497f19b3c1fe -r 16d63fc9ae42 mapeditor.h
--- a/mapeditor.h	Tue Nov 06 13:54:41 2007 +0000
+++ b/mapeditor.h	Thu Nov 08 15:28:03 2007 +0000
@@ -4,8 +4,9 @@
 #include <QGraphicsView>
 #include <QtNetwork>
 
+#include "attribute.h"
+#include "file.h"
 #include "mapcenterobj.h"
-#include "file.h"
 #include "misc.h"
 #include "parser.h"
 #include "ornamentedobj.h"
@@ -15,7 +16,7 @@
 
 /*! \brief Main widget in vym to display and edit a map */
 
-class MapEditor : public QGraphicsView, public xmlObj {
+class MapEditor : public QGraphicsView, public XMLObj {
     Q_OBJECT
 
 public:
@@ -427,6 +428,10 @@
 	QPoint exportOffset;		// set before export, used in save
 	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
 
+	QList <Attribute> attributes;	// List with attributes
+
+
+	// Network connections **Experimental**
 	NetState netstate;			// offline, client, server
 	QTcpServer *tcpServer;		// Act as server in conference mode (experimental)
 	QList <QTcpSocket*> clientList;		// List of connected clients
@@ -438,6 +443,7 @@
 	void displayClientError(QAbstractSocket::SocketError socketError);
 
 
+	// Animation data **experimental**
 	int timerId;				// animation timer
 	QList <MapObj*> animObjList;// list with animated objects
 };
diff -r 497f19b3c1fe -r 16d63fc9ae42 mapobj.h
--- a/mapobj.h	Tue Nov 06 13:54:41 2007 +0000
+++ b/mapobj.h	Thu Nov 08 15:28:03 2007 +0000
@@ -5,7 +5,7 @@
 #include <QGraphicsItem>
 #include <iostream>
 
-#include "misc.h"
+#include "xmlobj.h"
 
 using namespace std;
 
@@ -21,7 +21,7 @@
 /*! \brief Base class for all objects visible on a map
 */
 
-class MapObj:public xmlObj {
+class MapObj:public XMLObj {
 public:
     MapObj ();
     MapObj (QGraphicsScene*);