vymview.cpp
author insilmaril
Mon, 23 Mar 2009 09:06:51 +0000
changeset 745 2d4cc445a86a
parent 742 54d44ecd6097
child 746 ee6b0f3a4c2f
permissions -rw-r--r--
still working on insert/remove of rows
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "mainwindow.h"
     7 #include "mapeditor.h"
     8 
     9 extern Main *mainWindow;
    10 
    11 
    12 VymView::VymView(VymModel *m)
    13 {
    14 	model=m;
    15 
    16 	// Create TreeView
    17 	treeview=new QTreeView;
    18 	treeview->setModel ((QAbstractItemModel*)model);
    19 	treeview->setMinimumWidth (350);
    20 	treeview->setColumnWidth (0,350);
    21 
    22 	selModel=treeview->selectionModel();
    23 	model->setSelectionModel (selModel);
    24 	connect (
    25 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    26 		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    27 
    28 	// Create good old MapEditor
    29 	MapEditor* me=model->getMapEditor();
    30 	if (!me) me=new MapEditor (model);
    31 	connect (
    32 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    33 		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    34 	connect (
    35 		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
    36 		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
    37 
    38 	// VymModel may want to update selection, e.g. during animation
    39 	connect (
    40 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    41 		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    42 	connect (
    43 		model, SIGNAL (newChildObject(QModelIndex) ),
    44 		this,SLOT (updateChilds (QModelIndex) ) );
    45 
    46 	//me->viewport()->setFocus();	//FIXME needed?
    47 	me->setAntiAlias (mainWindow->isAliased());
    48 	me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    49 
    50 	addWidget (treeview);
    51 	addWidget (me);
    52 
    53 	// Set geometry
    54 	QList <int> sizes;
    55 	sizes.append (120);
    56 	sizes.append (600);
    57 	setSizes (sizes);
    58 }
    59 
    60 QItemSelectionModel* VymView::selectionModel() 
    61 {
    62 	if (treeview) 
    63 		return selModel;
    64 	else 
    65 		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
    66 	return NULL;
    67 }
    68 
    69 
    70 void VymView::updateChilds (QModelIndex ix)
    71 {
    72 	treeview->setExpanded (ix,true);
    73 }
    74 
    75 void VymView::changeSelection (const QItemSelection &, const QItemSelection &)
    76 {
    77 	cout << "VymView::changeSelection (newsel,delsel)\n";
    78 	//treeview->expandAll();	//FIXME only for testing
    79 
    80 	// Show URL and link in statusbar
    81 	QString status;
    82 	QString s=model->getURL();
    83 	if (!s.isEmpty() ) status+="URL: "+s+"  ";
    84 	s=model->getVymLink();
    85 	if (!s.isEmpty() ) status+="Link: "+s;
    86 	if (!status.isEmpty() ) mainWindow->statusMessage (status);
    87 
    88 	// Update Toolbar // FIXME, was so far in BranchObj
    89 	//updateFlagsToolbar();
    90 
    91 	// Update actions
    92 	mainWindow->updateActions();
    93 }
    94