1.11.2 split up of xml helper functions. started to work on attributes
authorinsilmaril
Thu Nov 08 15:28:03 2007 +0000 (2007-11-08)
changeset 61616d63fc9ae42
parent 615 497f19b3c1fe
child 617 7ee5bf3647d3
1.11.2 split up of xml helper functions. started to work on attributes
attribute.cpp
attribute.h
branchobj.cpp
linkablemapobj.h
mainwindow.cpp
mainwindow.h
mapeditor.cpp
mapeditor.h
mapobj.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/attribute.cpp	Thu Nov 08 15:28:03 2007 +0000
     1.3 @@ -0,0 +1,101 @@
     1.4 +#include "attribute.h"
     1.5 +
     1.6 +Attribute::Attribute()
     1.7 +{
     1.8 +	key="";
     1.9 +	value="";
    1.10 +}
    1.11 +
    1.12 +void Attribute::setKey (const QString &k)
    1.13 +{
    1.14 +	key=k;
    1.15 +}
    1.16 +
    1.17 +QString Attribute::getKey ()
    1.18 +{
    1.19 +	return key;
    1.20 +}
    1.21 +
    1.22 +void Attribute::setValue(const QString &v)
    1.23 +{
    1.24 +	value=v;
    1.25 +}
    1.26 +
    1.27 +QString Attribute::getValue()
    1.28 +{
    1.29 +	return value;
    1.30 +}
    1.31 +
    1.32 +QString Attribute::getDataXML()
    1.33 +{
    1.34 +	return valueElement ("attribute",key,value);
    1.35 +}
    1.36 +
    1.37 +
    1.38 +///////////////////////////////////////////////////////////////
    1.39 +AttributeTable::AttributeTable()
    1.40 +{
    1.41 +	clear();
    1.42 +}
    1.43 +
    1.44 +AttributeTable::~AttributeTable()
    1.45 +{
    1.46 +}
    1.47 +
    1.48 +void AttributeTable::clear ()
    1.49 +{
    1.50 +	keys.clear();
    1.51 +	values.clear();
    1.52 +}
    1.53 +
    1.54 +void AttributeTable::addKey (const QString &k)
    1.55 +{
    1.56 +	if (!keys.contains (k) )
    1.57 +	{
    1.58 +		keys.append (k);
    1.59 +		values.append (QStringList() );
    1.60 +	}
    1.61 +}
    1.62 +
    1.63 +void AttributeTable::removeKey (const QString &k)
    1.64 +{
    1.65 +	int i=keys.indexOf (k);
    1.66 +	if (i>=0)
    1.67 +	{
    1.68 +		keys.removeAt(i);
    1.69 +		values.removeAt(i);
    1.70 +	}
    1.71 +}
    1.72 +
    1.73 +void AttributeTable::addValue (const QString &k, const QString &v)
    1.74 +{
    1.75 +	int i=keys.indexOf (k);
    1.76 +	if (i<0)
    1.77 +	{
    1.78 +		keys.append (k);
    1.79 +		values.append (QStringList (v));
    1.80 +	} else
    1.81 +	{
    1.82 +		int j=values.at(i).indexOf(k);
    1.83 +		if (j<0) values[i].append (QString(v));
    1.84 +	}
    1.85 +}
    1.86 +
    1.87 +QStringList AttributeTable::getKeys ()
    1.88 +{
    1.89 +	return keys;
    1.90 +}
    1.91 +
    1.92 +QStringList AttributeTable::getValues(const QString &k)
    1.93 +{
    1.94 +	int i=keys.indexOf (k);
    1.95 +	if (i>=0)
    1.96 +		return values.at(i);
    1.97 +	else
    1.98 +		return QStringList();
    1.99 +}
   1.100 +
   1.101 +QString AttributeTable::getDataXML()
   1.102 +{
   1.103 +	return valueElement ("attributeList","key","value");
   1.104 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/attribute.h	Thu Nov 08 15:28:03 2007 +0000
     2.3 @@ -0,0 +1,49 @@
     2.4 +#ifndef ATTRIBUTE_H
     2.5 +#define ATTRIBUTE_H
     2.6 +
     2.7 +#include <QStringList>
     2.8 +
     2.9 +#include "xmlobj.h"
    2.10 +
    2.11 +
    2.12 +/*! \brief A key and a list of values
    2.13 +*/
    2.14 +
    2.15 +class Attribute:public XMLObj {
    2.16 +public:
    2.17 +	Attribute();
    2.18 +	virtual void setKey (const QString &k);
    2.19 +	virtual QString getKey ();
    2.20 +	virtual void setValue (const QString &v);
    2.21 +	virtual QString getValue();
    2.22 +	virtual QString getDataXML();
    2.23 +protected:
    2.24 +	QString key;
    2.25 +	QString value;
    2.26 +};
    2.27 +
    2.28 +/*! \brief A table containing a list of keys and each of these keys has
    2.29 +   a list of default values. The keys and the values for each key are
    2.30 +   unique.
    2.31 +*/
    2.32 +class AttributeTable:public XMLObj{
    2.33 +public:
    2.34 +	AttributeTable();
    2.35 +	virtual ~AttributeTable();
    2.36 +	virtual void clear();
    2.37 +	virtual void addKey (const QString &k);		//!< Adds a key to the table
    2.38 +	virtual void removeKey (const QString &k);	//!< Removes key and its default values
    2.39 +	virtual void addValue (const QString &k, const QString &v);	//!< Adds key and value
    2.40 +	virtual QStringList getKeys ();
    2.41 +	virtual QStringList getValues(const QString &k);
    2.42 +	virtual QString getDataXML();
    2.43 +
    2.44 +protected:
    2.45 +	QStringList keys;
    2.46 +	QList <QStringList> values;
    2.47 +};
    2.48 +
    2.49 +
    2.50 +
    2.51 +#endif
    2.52 +
     3.1 --- a/branchobj.cpp	Tue Nov 06 13:54:41 2007 +0000
     3.2 +++ b/branchobj.cpp	Thu Nov 08 15:28:03 2007 +0000
     3.3 @@ -1,7 +1,11 @@
     3.4  #include "branchobj.h"
     3.5 -#include "texteditor.h"
     3.6 +
     3.7 +// #include "texteditor.h"
     3.8  #include "mapeditor.h"
     3.9  #include "mainwindow.h"
    3.10 +#include "misc.h"
    3.11 +
    3.12 +class TextEditor;
    3.13  
    3.14  extern TextEditor *textEditor;
    3.15  extern Main *mainWindow;
     4.1 --- a/linkablemapobj.h	Tue Nov 06 13:54:41 2007 +0000
     4.2 +++ b/linkablemapobj.h	Thu Nov 08 15:28:03 2007 +0000
     4.3 @@ -6,8 +6,10 @@
     4.4  #include "headingobj.h"
     4.5  #include "flagrowobj.h"
     4.6  
     4.7 +#define MAX_DEPTH 999
     4.8  
     4.9 -#define MAX_DEPTH 999
    4.10 +class MapEditor;
    4.11 +
    4.12  
    4.13  
    4.14  /*! \brief This class adds links to MapObj 
     5.1 --- a/mainwindow.cpp	Tue Nov 06 13:54:41 2007 +0000
     5.2 +++ b/mainwindow.cpp	Thu Nov 08 15:28:03 2007 +0000
     5.3 @@ -2773,6 +2773,88 @@
     5.4  	} // currentMapEditor()	
     5.5  }
     5.6  
     5.7 +void Main::editAttributeFinished()
     5.8 +{
     5.9 +	// only called from editHeading(), so there is a currentME
    5.10 +
    5.11 +	/*
    5.12 +	MapEditor *me=currentMapEditor();
    5.13 +	if (me)
    5.14 +	{
    5.15 +		me->setStateEditHeading (false);
    5.16 +		QPoint p;	//Not used here, only to find out pos of branch
    5.17 +		bool ok;
    5.18 +		QString s=me->getHeading(ok,p);
    5.19 +
    5.20 +#if defined(Q_OS_MACX)
    5.21 +#else
    5.22 +		if (ok && s!=lineedit->text())
    5.23 +			me->setHeading(lineedit->text());
    5.24 +			
    5.25 +		lineedit->releaseKeyboard();
    5.26 +		lineedit->hide();
    5.27 +		setFocus();
    5.28 +#endif	
    5.29 +		if (!actionSettingsAutoSelectNewBranch->isOn() && 
    5.30 +			!prevSelection.isEmpty()) 
    5.31 +			me->select(prevSelection);
    5.32 +		prevSelection="";
    5.33 +	}
    5.34 +	*/
    5.35 +}
    5.36 +
    5.37 +void Main::editAttribute()
    5.38 +{
    5.39 +	/*
    5.40 +	if (currentMapEditor())
    5.41 +	{
    5.42 +		MapEditor *me=currentMapEditor();
    5.43 +		QString oldSel=me->getSelectString();
    5.44 +
    5.45 +		if (lineedit->isVisible())
    5.46 +			editAttributeFinished();
    5.47 +		else
    5.48 +		{
    5.49 +			bool ok;
    5.50 +			QPoint p;
    5.51 +			QString s=me->getHeading(ok,p);
    5.52 +
    5.53 +			if (ok)
    5.54 +			{
    5.55 +				me->setStateEditHeading (true);
    5.56 +#if defined(Q_OS_MACX)
    5.57 +				p=me->mapToGlobal (p);
    5.58 +				QDialog *d =new QDialog(NULL);
    5.59 +				QLineEdit *le=new QLineEdit (d);
    5.60 +				d->setWindowFlags (Qt::FramelessWindowHint);
    5.61 +				d->setGeometry(p.x(),p.y(),230,25);
    5.62 +				le->resize (d->width()-10,d->height());
    5.63 +				le->setText (s);
    5.64 +				le->selectAll();
    5.65 +				connect (le, SIGNAL (returnPressed()), d, SLOT (accept()));
    5.66 +				d->activateWindow();
    5.67 +				d->exec();
    5.68 +				me->setHeading (le->text());
    5.69 +				delete (le);
    5.70 +				delete (d);
    5.71 +				editHeadingFinished();
    5.72 +#else
    5.73 +				p=me->mapTo (this,p);
    5.74 +				lineedit->setGeometry(p.x(),p.y(),230,25);
    5.75 +				lineedit->setText(s);
    5.76 +				lineedit->setCursorPosition(1);
    5.77 +				lineedit->selectAll();
    5.78 +				lineedit->show();
    5.79 +				lineedit->grabKeyboard();
    5.80 +				lineedit->setFocus();
    5.81 +#endif
    5.82 +			}
    5.83 +		} 
    5.84 +	} // currentMapEditor()	
    5.85 +
    5.86 +	*/
    5.87 +}
    5.88 +
    5.89  void Main::openVymLinks(const QStringList &vl)
    5.90  {
    5.91  	for (int j=0; j<vl.size(); j++)
    5.92 @@ -3646,7 +3728,8 @@
    5.93  void Main::testFunction1()
    5.94  {
    5.95  	if (!currentMapEditor()) return;
    5.96 -	currentMapEditor()->testFunction1();
    5.97 +	//currentMapEditor()->testFunction1();
    5.98 +	editAttribute();
    5.99  }
   5.100  
   5.101  void Main::testFunction2()
     6.1 --- a/mainwindow.h	Tue Nov 06 13:54:41 2007 +0000
     6.2 +++ b/mainwindow.h	Thu Nov 08 15:28:03 2007 +0000
     6.3 @@ -117,8 +117,10 @@
     6.4  	void editVymLink();
     6.5  	void editOpenMultipleVymLinks();
     6.6      void editHeadingFinished();
     6.7 +    void editAttributeFinished();
     6.8  public slots:
     6.9      void editHeading();
    6.10 +    void editAttribute();
    6.11  	void editOpenVymLink();
    6.12  private slots:
    6.13  	void editDeleteVymLink();
     7.1 --- a/mapeditor.cpp	Tue Nov 06 13:54:41 2007 +0000
     7.2 +++ b/mapeditor.cpp	Thu Nov 08 15:28:03 2007 +0000
     7.3 @@ -301,7 +301,7 @@
     7.4  	}
     7.5  
     7.6  	// Save local settings
     7.7 -	s+=settings.getXMLData (destPath);
     7.8 +	s+=settings.getDataXML (destPath);
     7.9  
    7.10  	// Save selection
    7.11  	if (!xelection.isEmpty() && !saveSel ) 
     8.1 --- a/mapeditor.h	Tue Nov 06 13:54:41 2007 +0000
     8.2 +++ b/mapeditor.h	Thu Nov 08 15:28:03 2007 +0000
     8.3 @@ -4,8 +4,9 @@
     8.4  #include <QGraphicsView>
     8.5  #include <QtNetwork>
     8.6  
     8.7 +#include "attribute.h"
     8.8 +#include "file.h"
     8.9  #include "mapcenterobj.h"
    8.10 -#include "file.h"
    8.11  #include "misc.h"
    8.12  #include "parser.h"
    8.13  #include "ornamentedobj.h"
    8.14 @@ -15,7 +16,7 @@
    8.15  
    8.16  /*! \brief Main widget in vym to display and edit a map */
    8.17  
    8.18 -class MapEditor : public QGraphicsView, public xmlObj {
    8.19 +class MapEditor : public QGraphicsView, public XMLObj {
    8.20      Q_OBJECT
    8.21  
    8.22  public:
    8.23 @@ -427,6 +428,10 @@
    8.24  	QPoint exportOffset;		// set before export, used in save
    8.25  	BranchObj::HideTmpMode hidemode;	// true while exporting to hide some stuff
    8.26  
    8.27 +	QList <Attribute> attributes;	// List with attributes
    8.28 +
    8.29 +
    8.30 +	// Network connections **Experimental**
    8.31  	NetState netstate;			// offline, client, server
    8.32  	QTcpServer *tcpServer;		// Act as server in conference mode (experimental)
    8.33  	QList <QTcpSocket*> clientList;		// List of connected clients
    8.34 @@ -438,6 +443,7 @@
    8.35  	void displayClientError(QAbstractSocket::SocketError socketError);
    8.36  
    8.37  
    8.38 +	// Animation data **experimental**
    8.39  	int timerId;				// animation timer
    8.40  	QList <MapObj*> animObjList;// list with animated objects
    8.41  };
     9.1 --- a/mapobj.h	Tue Nov 06 13:54:41 2007 +0000
     9.2 +++ b/mapobj.h	Thu Nov 08 15:28:03 2007 +0000
     9.3 @@ -5,7 +5,7 @@
     9.4  #include <QGraphicsItem>
     9.5  #include <iostream>
     9.6  
     9.7 -#include "misc.h"
     9.8 +#include "xmlobj.h"
     9.9  
    9.10  using namespace std;
    9.11  
    9.12 @@ -21,7 +21,7 @@
    9.13  /*! \brief Base class for all objects visible on a map
    9.14  */
    9.15  
    9.16 -class MapObj:public xmlObj {
    9.17 +class MapObj:public XMLObj {
    9.18  public:
    9.19      MapObj ();
    9.20      MapObj (QGraphicsScene*);