Preview: Added QTreeView to mainwindow (not yet functional)
authorinsilmaril
Tue, 05 Aug 2008 07:36:53 +0000
changeset 7257ea31701156e
parent 724 cf14046909cd
child 726 7f43b93242aa
Preview: Added QTreeView to mainwindow (not yet functional)
mainwindow.cpp
mainwindow.h
treeitem.cpp
treeitem.h
treemodel.cpp
treemodel.h
version.h
vym.pro
vymmodel.cpp
vymmodel.h
     1.1 --- a/mainwindow.cpp	Mon Aug 04 13:35:54 2008 +0000
     1.2 +++ b/mainwindow.cpp	Tue Aug 05 07:36:53 2008 +0000
     1.3 @@ -74,6 +74,7 @@
     1.4  extern QString iconPath;
     1.5  extern QString flagsPath;
     1.6  
     1.7 +
     1.8  Main::Main(QWidget* parent, const char* name, Qt::WFlags f) :
     1.9      QMainWindow(parent,name,f)
    1.10  {
    1.11 @@ -201,9 +202,6 @@
    1.12  	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
    1.13  		this, SLOT( editorChanged( QWidget * ) ) );
    1.14  
    1.15 -	lineedit=new QLineEdit (this);
    1.16 -	lineedit->hide();
    1.17 -
    1.18  	setCentralWidget(tabWidget);	
    1.19  
    1.20      setupFileActions();
    1.21 @@ -1691,22 +1689,16 @@
    1.22  
    1.23  MapEditor* Main::currentMapEditor() const
    1.24  {
    1.25 -	// FIXME currentMapEditor should return the latest used editor for a model, or NULL if no editor is open
    1.26 -    if ( tabWidget->currentPage() &&
    1.27 -	 tabWidget->currentPage()->inherits( "MapEditor" ) )
    1.28 -		return (MapEditor*)tabWidget->currentPage();
    1.29 +    if ( tabWidget->currentPage())
    1.30 +		return tabModel.at(tabWidget->currentIndex())->getMapEditor();
    1.31      return NULL;	
    1.32  }
    1.33  
    1.34  VymModel* Main::currentModel() const
    1.35  {
    1.36 -	// FIXME better get currentModel from a maintained list,
    1.37 -	// just in case we allow other views in tabs later
    1.38 -	MapEditor *me=currentMapEditor();
    1.39 -	if (me) 
    1.40 -		return me->getModel();
    1.41 -	else
    1.42 -		return NULL;
    1.43 +    if ( tabWidget->currentPage())
    1.44 +		return tabModel.at(tabWidget->currentIndex());
    1.45 +    return NULL;	
    1.46  }
    1.47  
    1.48  
    1.49 @@ -1714,12 +1706,9 @@
    1.50  {
    1.51  	// Unselect all possibly selected objects
    1.52  	// (Important to update note editor)
    1.53 -	MapEditor *me;
    1.54  	for (int i=0;i<=tabWidget->count() -1;i++)
    1.55  	{
    1.56 -		
    1.57 -		me=(MapEditor*)tabWidget->page(i);
    1.58 -		me->getModel()->unselect();
    1.59 +		tabModel.at(i)->unselect();
    1.60  	}	
    1.61  	VymModel *m=currentModel();
    1.62  	if (m) m->reselect();
    1.63 @@ -1728,18 +1717,43 @@
    1.64  	updateActions();
    1.65  }
    1.66  
    1.67 +VymView *Main::createView (VymModel *model)
    1.68 +{
    1.69 +	VymView *vm=new VymView;
    1.70 +
    1.71 +	// Create TreeView
    1.72 +	QTreeView *tv=new QTreeView;
    1.73 +	tv->setModel (model->getTreeModel() );
    1.74 +
    1.75 +	// Create good old MapEditor
    1.76 +	MapEditor* me=model->getMapEditor();
    1.77 +	if (!me) me=new MapEditor (model);
    1.78 +	//me->viewport()->setFocus();
    1.79 +	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
    1.80 +	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
    1.81 +
    1.82 +	vm->addWidget (tv);
    1.83 +	vm->addWidget (me);
    1.84 +
    1.85 +	// Set geometry
    1.86 +	QList <int> sizes;
    1.87 +	sizes.append (150);
    1.88 +	sizes.append (600);
    1.89 +	vm->setSizes (sizes);
    1.90 +
    1.91 +	return vm;
    1.92 +}
    1.93 +
    1.94  void Main::fileNew()
    1.95  {
    1.96  	VymModel *m=new VymModel;
    1.97 -	models.append (m);
    1.98 +	tabModel.append (m);
    1.99  	MapEditor* me = new MapEditor (m);
   1.100  	me->setObjectName ("MapEditor");
   1.101 -	QString fn="unnamed";
   1.102 -	tabWidget->addTab (me,fn);
   1.103 -	tabWidget->showPage(me);
   1.104 -	me->viewport()->setFocus();
   1.105 -	me->setAntiAlias (actionViewToggleAntiAlias->isOn());
   1.106 -	me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
   1.107 +
   1.108 +	VymView *view=createView (m);
   1.109 +	tabWidget->addTab (view,tr("unnamed","MainWindow: name for new and empty file"));
   1.110 +	tabWidget->setCurrentIndex (tabModel.count() );
   1.111  	
   1.112  	// For the very first map we do not have flagrows yet...
   1.113  	m->select("mc:");
   1.114 @@ -1748,25 +1762,14 @@
   1.115  void Main::fileNewCopy()
   1.116  {
   1.117  	QString fn="unnamed";
   1.118 -	MapEditor* oldME =currentMapEditor();
   1.119 -	if (oldME)
   1.120 +	VymModel *srcModel=currentModel();
   1.121 +	if (srcModel)
   1.122  	{
   1.123 -		oldME->getModel()->copy();
   1.124 -		VymModel *m=new VymModel;
   1.125 -		models.append (m);
   1.126 -		MapEditor* newME = new MapEditor ( m);
   1.127 -		if (newME)
   1.128 -		{
   1.129 -			tabWidget->addTab (newME,fn);
   1.130 -			tabWidget->showPage(newME);
   1.131 -			newME->viewport()->setFocus();
   1.132 -			newME->setAntiAlias (actionViewToggleAntiAlias->isOn());
   1.133 -			newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
   1.134 -			// For the very first map we do not have flagrows yet...
   1.135 -			m->select("mc:");
   1.136 -			m->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
   1.137 -		}
   1.138 -
   1.139 +		srcModel->copy();
   1.140 +		fileNew();
   1.141 +		VymModel *dstModel=tabModel.last ();
   1.142 +		dstModel->select("mc:");
   1.143 +		dstModel->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap);
   1.144  	}
   1.145  }
   1.146  
   1.147 @@ -1788,8 +1791,7 @@
   1.148  		int i=0;
   1.149  		while (i<=tabWidget->count() -1)
   1.150  		{
   1.151 -			me=(MapEditor*)tabWidget->page(i);
   1.152 -			if (me->getModel()->getFilePath() == fn)
   1.153 +			if (tabModel.at(i)->getFilePath() == fn)
   1.154  			{
   1.155  				// Already there, ask for confirmation
   1.156  				QMessageBox mb( vymName,
   1.157 @@ -1806,7 +1808,7 @@
   1.158  				switch( mb.exec() ) 
   1.159  				{
   1.160  					case QMessageBox::Yes:
   1.161 -						// load anyway
   1.162 +						// end loop and load anyway
   1.163  						i=tabWidget->count();
   1.164  						break;
   1.165  					case QMessageBox::Cancel:
   1.166 @@ -1818,26 +1820,24 @@
   1.167  			i++;
   1.168  		}
   1.169  	}
   1.170 -
   1.171 +	
   1.172 +	int tabIndex=tabWidget->currentPageIndex();
   1.173  
   1.174  	// Try to load map
   1.175      if ( !fn.isEmpty() )
   1.176  	{
   1.177  		me = currentMapEditor();
   1.178 -		int tabIndex=tabWidget->currentPageIndex();
   1.179  		// Check first, if mapeditor exists
   1.180  		// If it is not default AND we want a new map, 
   1.181  		// create a new mapeditor in a new tab
   1.182  		if ( lmode==NewMap && (!me || !me->getModel()->isDefault() )  )
   1.183  		{
   1.184  			VymModel *m=new VymModel;
   1.185 -			models.append (m);
   1.186 -			me= new MapEditor ( m);
   1.187 -			tabWidget->addTab (me,fn);
   1.188 -			tabIndex=tabWidget->indexOf (me);
   1.189 +			tabModel.append (m);
   1.190 +			VymView *view=createView (m);
   1.191 +			tabWidget->addTab (view,fn);
   1.192 +			tabIndex=tabWidget->count()-1;
   1.193  			tabWidget->setCurrentPage (tabIndex);
   1.194 -			me->setAntiAlias (actionViewToggleAntiAlias->isOn());
   1.195 -			me->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn());
   1.196  		}
   1.197  		
   1.198  		// Check, if file exists (important for creating new files
   1.199 @@ -1858,7 +1858,7 @@
   1.200  				case QMessageBox::Yes:
   1.201  					// Create new map
   1.202  					currentMapEditor()->getModel()->setFilePath(fn);
   1.203 -					tabWidget->setTabLabel (currentMapEditor(),
   1.204 +					tabWidget->setTabText (tabIndex,
   1.205  						currentMapEditor()->getModel()->getFileName() );
   1.206  					statusBar()->message( "Created " + fn , statusbarTime );
   1.207  					return success;
   1.208 @@ -1873,7 +1873,7 @@
   1.209  
   1.210  
   1.211  		//tabWidget->currentPage() won't be NULL here, because of above...
   1.212 -		tabWidget->showPage(me);
   1.213 +		tabWidget->setCurrentIndex (tabIndex);
   1.214  		me->viewport()->setFocus();
   1.215  
   1.216  		if (err!=aborted)
   1.217 @@ -1900,7 +1900,7 @@
   1.218  			if (lmode==NewMap)
   1.219  			{
   1.220  				me->getModel()->setFilePath (fn);
   1.221 -				tabWidget->changeTab(tabWidget->page(tabIndex), me->getModel()->getFileName());
   1.222 +				tabWidget->setTabText (tabIndex, me->getModel()->getFileName());
   1.223  				if (!isInTmpDir (fn))
   1.224  				{
   1.225  					// Only append to lastMaps if not loaded from a tmpDir
   1.226 @@ -1990,7 +1990,7 @@
   1.227  		// call fileSaveAs() now, this will call fileSave() 
   1.228  		// again.
   1.229  		// First switch to editor
   1.230 -		tabWidget->setCurrentWidget (m->getMapEditor());
   1.231 +		//FIXME needed???  tabWidget->setCurrentWidget (m->getMapEditor());
   1.232  		fileSaveAs(savemode);
   1.233  	}
   1.234  
   1.235 @@ -2068,13 +2068,13 @@
   1.236  
   1.237  
   1.238  			// Save now
   1.239 -			currentModel()->setFilePath(fn);
   1.240 -			fileSave(currentModel(), savemode);
   1.241 -
   1.242 -			// Set name of tab
   1.243 +			VymModel *m=currentModel();
   1.244 +			m->setFilePath(fn);
   1.245 +			fileSave(m, savemode);
   1.246 +
   1.247 +			// Set name of tab, assuming current tab is the one we just saved
   1.248  			if (savemode==CompleteMap)
   1.249 -				tabWidget->setTabLabel (currentMapEditor(),
   1.250 -					currentModel()->getFileName() );
   1.251 +				tabWidget->setTabText (tabWidget->currentIndex(), m->getFileName() );
   1.252  			return;
   1.253  		} 
   1.254  	}
   1.255 @@ -2342,7 +2342,8 @@
   1.256  			}
   1.257  		} 
   1.258  		me->close();
   1.259 -		tabWidget->removePage(me);
   1.260 +		tabModel.removeAt (tabWidget->currentIndex() );
   1.261 +		tabWidget->removeTab (tabWidget->currentIndex() );
   1.262          delete me;	// FIXME if event was triggered _in_ ME this causes warning message
   1.263  		updateActions();
   1.264  	}
   1.265 @@ -2357,15 +2358,11 @@
   1.266  void Main::fileExitVYM()
   1.267  {
   1.268  	// Check if one or more editors have changed
   1.269 -	MapEditor *me;
   1.270  	int i;
   1.271 -	for (i=0;i<=tabWidget->count() -1;i++)
   1.272 +	for (i=0;i<=tabModel.count() -1;i++)
   1.273  	{
   1.274 -		
   1.275 -		me=(MapEditor*)tabWidget->page(i);
   1.276 -
   1.277  		// If something changed, ask what to do
   1.278 -		if (me->getModel()->hasChanged())
   1.279 +		if (tabModel.at(i)->hasChanged())
   1.280  		{
   1.281  			tabWidget->setCurrentPage(i);
   1.282  			QMessageBox mb( vymName,
   1.283 @@ -2740,11 +2737,9 @@
   1.284  		// compare path with already loaded maps
   1.285  		int index=-1;
   1.286  		int i;
   1.287 -		MapEditor *me;
   1.288 -		for (i=0;i<=tabWidget->count() -1;i++)
   1.289 +		for (i=0;i<=tabModel.count() -1;i++)
   1.290  		{
   1.291 -			me=(MapEditor*)tabWidget->page(i);
   1.292 -			if (vl.at(j)==me->getModel()->getFilePath() )
   1.293 +			if (vl.at(j)==tabModel.at(i)->getFilePath() )
   1.294  			{
   1.295  				index=i;
   1.296  				break;
   1.297 @@ -2759,11 +2754,11 @@
   1.298  			else
   1.299  			{
   1.300  				fileLoad (vl.at(j), NewMap);
   1.301 -				tabWidget->setCurrentPage (tabWidget->count()-1);	
   1.302 +				tabWidget->setCurrentIndex (tabWidget->count()-1);	
   1.303  			}
   1.304  		} else
   1.305  			// Go to tab containing the map
   1.306 -			tabWidget->setCurrentPage (index);	
   1.307 +			tabWidget->setCurrentIndex (index);	
   1.308  	}
   1.309  }
   1.310  
   1.311 @@ -2884,7 +2879,7 @@
   1.312  void Main::editAddMapCenter()
   1.313  {
   1.314  	VymModel *m=currentModel();
   1.315 -	if (!lineedit->isVisible() && m)
   1.316 +	if (m)
   1.317  	{
   1.318  		m->addMapCenter ();
   1.319  	}	
   1.320 @@ -2893,7 +2888,7 @@
   1.321  void Main::editNewBranch()
   1.322  {
   1.323  	VymModel *m=currentModel();
   1.324 -	if (!lineedit->isVisible() && m)
   1.325 +	if (m)
   1.326  	{
   1.327  		BranchObj *bo=(BranchObj*)m->getSelection();
   1.328  		BranchObj *newbo=m->addNewBranch(0);
   1.329 @@ -2920,7 +2915,7 @@
   1.330  void Main::editNewBranchBefore()
   1.331  {
   1.332  	VymModel *m=currentModel();
   1.333 -	if (!lineedit->isVisible() &&  m)
   1.334 +	if (m)
   1.335  	{
   1.336  		BranchObj *bo=(BranchObj*)m->getSelection();
   1.337  		BranchObj *newbo=m->addNewBranchBefore();
   1.338 @@ -2942,7 +2937,7 @@
   1.339  void Main::editNewBranchAbove()
   1.340  {
   1.341  	VymModel *m=currentModel();
   1.342 -	if (!lineedit->isVisible() &&  m)
   1.343 +	if ( m)
   1.344  	{
   1.345  		BranchObj *bo=(BranchObj*)m->getSelection();
   1.346  		BranchObj *newbo=m->addNewBranch (-1);
   1.347 @@ -2964,7 +2959,7 @@
   1.348  void Main::editNewBranchBelow()
   1.349  {
   1.350  	VymModel *m=currentModel();
   1.351 -	if (!lineedit->isVisible() &&  m)
   1.352 +	if (m)
   1.353  	{
   1.354  		BranchObj *bo=(BranchObj*)m->getSelection();
   1.355  		BranchObj *newbo=m->addNewBranch (1);
   1.356 @@ -3372,10 +3367,10 @@
   1.357  {
   1.358  	bool b=actionViewToggleAntiAlias->isOn();
   1.359  	MapEditor *me;
   1.360 -	for (int i=0;i<tabWidget->count();i++)
   1.361 +	for (int i=0;i<tabModel.count();i++)
   1.362  	{
   1.363 -		me=(MapEditor*)tabWidget->page(i);
   1.364 -		me->setAntiAlias(b);
   1.365 +		me=tabModel.at(i)->getMapEditor();
   1.366 +		if (me) me->setAntiAlias(b);
   1.367  	}	
   1.368  
   1.369  }
   1.370 @@ -3384,11 +3379,11 @@
   1.371  {
   1.372  	bool b=actionViewToggleSmoothPixmapTransform->isOn();
   1.373  	MapEditor *me;
   1.374 -	for (int i=0;i<tabWidget->count();i++)
   1.375 +	for (int i=0;i<tabModel.count();i++)
   1.376  	{
   1.377  		
   1.378 -		me=(MapEditor*)tabWidget->page(i);
   1.379 -		me->setSmoothPixmap(b);
   1.380 +		me=tabModel.at(i)->getMapEditor();
   1.381 +		if (me) me->setSmoothPixmap(b);
   1.382  	}	
   1.383  }
   1.384  
   1.385 @@ -3679,14 +3674,14 @@
   1.386  
   1.387  void Main::windowNextEditor()
   1.388  {
   1.389 -	if (tabWidget->currentPageIndex() < tabWidget->count())
   1.390 -		tabWidget->setCurrentPage (tabWidget->currentPageIndex() +1);
   1.391 +	if (tabWidget->currentIndex() < tabWidget->count())
   1.392 +		tabWidget->setCurrentIndex (tabWidget->currentIndex() +1);
   1.393  }
   1.394  
   1.395  void Main::windowPreviousEditor()
   1.396  {
   1.397 -	if (tabWidget->currentPageIndex() >0)
   1.398 -		tabWidget->setCurrentPage (tabWidget->currentPageIndex() -1);
   1.399 +	if (tabWidget->currentIndex() >0)
   1.400 +		tabWidget->setCurrentIndex (tabWidget->currentIndex() -1);
   1.401  }
   1.402  
   1.403  void Main::standardFlagChanged()
     2.1 --- a/mainwindow.h	Mon Aug 04 13:35:54 2008 +0000
     2.2 +++ b/mainwindow.h	Tue Aug 05 07:36:53 2008 +0000
     2.3 @@ -12,6 +12,9 @@
     2.4  #include "simplescripteditor.h"
     2.5  #include "texteditor.h"
     2.6  
     2.7 +class VymView : public QSplitter 
     2.8 +{
     2.9 +};
    2.10  
    2.11  class Main : public QMainWindow 
    2.12  {
    2.13 @@ -31,6 +34,9 @@
    2.14  	void loadCmdLine();
    2.15  	void statusMessage (const QString &);
    2.16  
    2.17 +private:
    2.18 +	VymView* createView (VymModel*);
    2.19 +
    2.20  public slots:
    2.21      void fileNew();
    2.22      void fileNewCopy();
    2.23 @@ -232,9 +238,8 @@
    2.24  
    2.25  	QStringList imageTypes;
    2.26  
    2.27 -	QList <VymModel*> models;
    2.28 +	QList <VymModel*> tabModel;		//!< the corresponding model to a tab
    2.29  
    2.30 -	QLineEdit *lineedit;	// to enter headings of branches
    2.31  	QString prevSelection;
    2.32  
    2.33  	HistoryWindow *historyWindow;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/treeitem.cpp	Tue Aug 05 07:36:53 2008 +0000
     3.3 @@ -0,0 +1,52 @@
     3.4 +#include <QStringList>
     3.5 +
     3.6 +#include "treeitem.h"
     3.7 +
     3.8 +TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
     3.9 +{
    3.10 +    parentItem = parent;
    3.11 +    itemData = data;
    3.12 +}
    3.13 +
    3.14 +TreeItem::~TreeItem()
    3.15 +{
    3.16 +    qDeleteAll(childItems);
    3.17 +}
    3.18 +
    3.19 +void TreeItem::appendChild(TreeItem *item)
    3.20 +{
    3.21 +    childItems.append(item);
    3.22 +}
    3.23 +
    3.24 +TreeItem *TreeItem::child(int row)
    3.25 +{
    3.26 +    return childItems.value(row);
    3.27 +}
    3.28 +
    3.29 +int TreeItem::childCount() const
    3.30 +{
    3.31 +    return childItems.count();
    3.32 +}
    3.33 +
    3.34 +int TreeItem::columnCount() const
    3.35 +{
    3.36 +    return itemData.count();
    3.37 +}
    3.38 +
    3.39 +QVariant TreeItem::data(int column) const
    3.40 +{
    3.41 +    return itemData.value(column);
    3.42 +}
    3.43 +
    3.44 +TreeItem *TreeItem::parent()
    3.45 +{
    3.46 +    return parentItem;
    3.47 +}
    3.48 +
    3.49 +int TreeItem::row() const
    3.50 +{
    3.51 +    if (parentItem)
    3.52 +        return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
    3.53 +
    3.54 +    return 0;
    3.55 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/treeitem.h	Tue Aug 05 07:36:53 2008 +0000
     4.3 @@ -0,0 +1,28 @@
     4.4 +#ifndef TREEITEM_H
     4.5 +#define TREEITEM_H
     4.6 +
     4.7 +#include <QList>
     4.8 +#include <QVariant>
     4.9 +
    4.10 +class TreeItem
    4.11 +{
    4.12 +public:
    4.13 +    TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
    4.14 +    ~TreeItem();
    4.15 +
    4.16 +    void appendChild(TreeItem *child);
    4.17 +
    4.18 +    TreeItem *child(int row);
    4.19 +    int childCount() const;
    4.20 +    int columnCount() const;
    4.21 +    QVariant data(int column) const;
    4.22 +    int row() const;
    4.23 +    TreeItem *parent();
    4.24 +
    4.25 +private:
    4.26 +    QList<TreeItem*> childItems;
    4.27 +    QList<QVariant> itemData;
    4.28 +    TreeItem *parentItem;
    4.29 +};
    4.30 +
    4.31 +#endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/treemodel.cpp	Tue Aug 05 07:36:53 2008 +0000
     5.3 @@ -0,0 +1,130 @@
     5.4 +#include <QtGui>
     5.5 +
     5.6 +#include "treeitem.h"
     5.7 +#include "treemodel.h"
     5.8 +
     5.9 +TreeModel::TreeModel(QObject *parent)
    5.10 +    : QAbstractItemModel(parent)
    5.11 +{
    5.12 +    QList<QVariant> rootData;
    5.13 +    rootData << "Heading" << "Type" <<"Note";
    5.14 +    rootItem = new TreeItem(rootData);
    5.15 +    setupModelData(rootItem);
    5.16 +}
    5.17 +
    5.18 +TreeModel::~TreeModel()
    5.19 +{
    5.20 +    delete rootItem;
    5.21 +}
    5.22 +
    5.23 +int TreeModel::columnCount(const QModelIndex &parent) const
    5.24 +{
    5.25 +    if (parent.isValid())
    5.26 +        return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
    5.27 +    else
    5.28 +        return rootItem->columnCount();
    5.29 +}
    5.30 +
    5.31 +QVariant TreeModel::data(const QModelIndex &index, int role) const
    5.32 +{
    5.33 +    if (!index.isValid())
    5.34 +        return QVariant();
    5.35 +
    5.36 +    if (role != Qt::DisplayRole)
    5.37 +        return QVariant();
    5.38 +
    5.39 +    TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
    5.40 +
    5.41 +    return item->data(index.column());
    5.42 +}
    5.43 +
    5.44 +Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
    5.45 +{
    5.46 +    if (!index.isValid())
    5.47 +        return Qt::ItemIsEnabled;
    5.48 +
    5.49 +    return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    5.50 +}
    5.51 +
    5.52 +QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
    5.53 +                               int role) const
    5.54 +{
    5.55 +    if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
    5.56 +        return rootItem->data(section);
    5.57 +
    5.58 +    return QVariant();
    5.59 +}
    5.60 +
    5.61 +QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
    5.62 +            const
    5.63 +{
    5.64 +    TreeItem *parentItem;
    5.65 +
    5.66 +    if (!parent.isValid())
    5.67 +        parentItem = rootItem;
    5.68 +    else
    5.69 +        parentItem = static_cast<TreeItem*>(parent.internalPointer());
    5.70 +
    5.71 +    TreeItem *childItem = parentItem->child(row);
    5.72 +    if (childItem)
    5.73 +        return createIndex(row, column, childItem);
    5.74 +    else
    5.75 +        return QModelIndex();
    5.76 +}
    5.77 +
    5.78 +QModelIndex TreeModel::parent(const QModelIndex &index) const
    5.79 +{
    5.80 +    if (!index.isValid())
    5.81 +        return QModelIndex();
    5.82 +
    5.83 +    TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
    5.84 +    TreeItem *parentItem = childItem->parent();
    5.85 +
    5.86 +    if (parentItem == rootItem)
    5.87 +        return QModelIndex();
    5.88 +
    5.89 +    return createIndex(parentItem->row(), 0, parentItem);
    5.90 +}
    5.91 +
    5.92 +int TreeModel::rowCount(const QModelIndex &parent) const
    5.93 +{
    5.94 +    TreeItem *parentItem;
    5.95 +
    5.96 +    if (!parent.isValid())
    5.97 +        parentItem = rootItem;
    5.98 +    else
    5.99 +        parentItem = static_cast<TreeItem*>(parent.internalPointer());
   5.100 +
   5.101 +    return parentItem->childCount();
   5.102 +}
   5.103 +
   5.104 +void TreeModel::setupModelData(TreeItem *root)
   5.105 +{
   5.106 +	QList<QVariant> cData;
   5.107 +
   5.108 +	cData << "Center of map" << "MapCenter"<<"Data 1";
   5.109 +	TreeItem *mco=new TreeItem (cData,root);
   5.110 +	root->appendChild (mco);
   5.111 +
   5.112 +	cData.clear();
   5.113 +	cData << "Main A" << "Branch"<<"Data 2";
   5.114 +	TreeItem *bo=new TreeItem (cData,mco);
   5.115 +	mco->appendChild (bo);
   5.116 +	TreeItem *mainA=bo;
   5.117 +
   5.118 +	cData.clear();
   5.119 +	cData << "Sub a" << "Branch"<<"Data";
   5.120 +	bo=new TreeItem (cData,mainA);
   5.121 +	mainA->appendChild (bo);
   5.122 +
   5.123 +	cData.clear();
   5.124 +	cData << "Sub b" << "Branch"<<"Data";
   5.125 +	bo=new TreeItem (cData,mainA);
   5.126 +	mainA->appendChild (bo);
   5.127 +
   5.128 +	cData.clear();
   5.129 +	cData << "Main B"<<"Branch" <<"Data 3";
   5.130 +	mco->appendChild(new TreeItem(cData, mco));
   5.131 +
   5.132 +	//QModelIndex ix=index (0,0,QModelIndex() );
   5.133 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/treemodel.h	Tue Aug 05 07:36:53 2008 +0000
     6.3 @@ -0,0 +1,34 @@
     6.4 +#ifndef TREEMODEL_H
     6.5 +#define TREEMODEL_H
     6.6 +
     6.7 +#include <QAbstractItemModel>
     6.8 +#include <QModelIndex>
     6.9 +#include <QVariant>
    6.10 +
    6.11 +class TreeItem;
    6.12 +
    6.13 +class TreeModel : public QAbstractItemModel
    6.14 +{
    6.15 +    Q_OBJECT
    6.16 +
    6.17 +public:
    6.18 +    TreeModel(QObject *parent = 0);
    6.19 +    ~TreeModel();
    6.20 +
    6.21 +    QVariant data(const QModelIndex &index, int role) const;
    6.22 +    Qt::ItemFlags flags(const QModelIndex &index) const;
    6.23 +    QVariant headerData(int section, Qt::Orientation orientation,
    6.24 +                        int role = Qt::DisplayRole) const;
    6.25 +    QModelIndex index(int row, int column,
    6.26 +                      const QModelIndex &parent = QModelIndex()) const;
    6.27 +    QModelIndex parent(const QModelIndex &index) const;
    6.28 +    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    6.29 +    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    6.30 +
    6.31 +private:
    6.32 +    void setupModelData(TreeItem *parent);
    6.33 +
    6.34 +    TreeItem *rootItem;
    6.35 +};
    6.36 +
    6.37 +#endif
     7.1 --- a/version.h	Mon Aug 04 13:35:54 2008 +0000
     7.2 +++ b/version.h	Tue Aug 05 07:36:53 2008 +0000
     7.3 @@ -7,7 +7,7 @@
     7.4  #define __VYM_VERSION "1.13.0"
     7.5  //#define __VYM_CODENAME "Codename: RC-1"
     7.6  #define __VYM_CODENAME "Codename: development version"
     7.7 -#define __VYM_BUILD_DATE "2008-07-18"
     7.8 +#define __VYM_BUILD_DATE "2008-08-05"
     7.9  
    7.10  
    7.11  bool checkVersion(const QString &);
     8.1 --- a/vym.pro	Mon Aug 04 13:35:54 2008 +0000
     8.2 +++ b/vym.pro	Tue Aug 05 07:36:53 2008 +0000
     8.3 @@ -74,6 +74,8 @@
     8.4  	xmlobj.h\
     8.5  	xsltproc.h \
     8.6  	settings.h \
     8.7 +	treeitem.h \
     8.8 +	treemodel.h \
     8.9  	warningdialog.h
    8.10  
    8.11  SOURCES	+= \
    8.12 @@ -119,6 +121,8 @@
    8.13  	showtextdialog.cpp \
    8.14  	simplescripteditor.cpp \
    8.15  	texteditor.cpp \
    8.16 +	treeitem.cpp \
    8.17 +	treemodel.cpp \
    8.18  	version.cpp \
    8.19  	vymmodel.cpp \
    8.20  	xlinkobj.cpp \
     9.1 --- a/vymmodel.cpp	Mon Aug 04 13:35:54 2008 +0000
     9.2 +++ b/vymmodel.cpp	Tue Aug 05 07:36:53 2008 +0000
     9.3 @@ -118,6 +118,9 @@
     9.4  	itFind=NULL;				
     9.5  	EOFind=false;
     9.6  
     9.7 +	// TreeModel
     9.8 +	treeModel=new TreeModel;
     9.9 +
    9.10  	// animations
    9.11  	animationUse=settings.readBoolEntry("/animation/use",false);
    9.12  	animationTicks=settings.readNumEntry("/animation/ticks",10);
    9.13 @@ -161,6 +164,11 @@
    9.14  	return mapEditor;
    9.15  }
    9.16  
    9.17 +TreeModel* VymModel::getTreeModel()
    9.18 +{
    9.19 +	return treeModel;
    9.20 +}
    9.21 +
    9.22  bool VymModel::isRepositionBlocked()
    9.23  {
    9.24  	return blockReposition;
    9.25 @@ -1486,6 +1494,7 @@
    9.26  	}
    9.27  }
    9.28  
    9.29 +/* FIXME delete this
    9.30  QString VymModel::getHeading(bool &ok, QPoint &p)
    9.31  {
    9.32  	BranchObj *bo=selection.getBranch();
    9.33 @@ -1498,7 +1507,7 @@
    9.34  	ok=false;
    9.35  	return QString();
    9.36  }
    9.37 -
    9.38 +*/
    9.39  
    9.40  void VymModel::setHeadingInt(const QString &s)
    9.41  {
    10.1 --- a/vymmodel.h	Mon Aug 04 13:35:54 2008 +0000
    10.2 +++ b/vymmodel.h	Tue Aug 05 07:36:53 2008 +0000
    10.3 @@ -9,6 +9,7 @@
    10.4  #include "mapeditor.h"
    10.5  #include "parser.h"
    10.6  #include "selection.h"
    10.7 +#include "treemodel.h"
    10.8  #include "xmlobj.h"
    10.9  
   10.10  
   10.11 @@ -38,6 +39,11 @@
   10.12  
   10.13  	MapEditor* getMapEditor();			// FIXME not necessary
   10.14  
   10.15 +private:
   10.16 +	TreeModel* treeModel;
   10.17 +public:	
   10.18 +	TreeModel* getTreeModel();
   10.19 +
   10.20  	bool isRepositionBlocked();		//!< While load or undo there is no need to update graphicsview
   10.21  
   10.22  	void updateActions();			//!< Update buttons in mainwindow
   10.23 @@ -238,7 +244,7 @@
   10.24  
   10.25  public:	
   10.26  	void setHeading(const QString &);		//!< Set heading of branch	
   10.27 -	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
   10.28 +//	QString getHeading (bool &ok,QPoint &p); //!< Get heading, ok if selection is branch
   10.29  private:
   10.30  	void setHeadingInt(const QString &);
   10.31