vymview.cpp
author insilmaril
Thu, 23 Apr 2009 12:15:31 +0000
changeset 755 ed5b407975b3
parent 753 25a77484ec72
child 759 bf3ea1f1520b
permissions -rw-r--r--
more data in Tree, less in Map
     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 		/*
    35 	connect (
    36 		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
    37 		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
    38 		*/
    39 		/*
    40 */
    41 	connect (
    42 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    43 		me,SLOT (updateData(const QModelIndex &) ) );
    44 
    45 	// VymModel may want to update selection or other data, e.g. during animation
    46 	connect (
    47 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    48 		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    49 	connect (
    50 		model, SIGNAL (newChildObject(QModelIndex) ),
    51 		this,SLOT (updateChilds (QModelIndex) ) );
    52 	connect (
    53 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    54 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    55 		
    56 
    57 	//me->viewport()->setFocus();	//FIXME-3 needed?
    58 	me->setAntiAlias (mainWindow->isAliased());
    59 	me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    60 
    61 	addWidget (treeview);
    62 	addWidget (me);
    63 
    64 	// Set geometry
    65 	QList <int> sizes;
    66 	sizes.append (120);
    67 	sizes.append (600);
    68 	setSizes (sizes);
    69 }
    70 
    71 QItemSelectionModel* VymView::selectionModel() 
    72 {
    73 	if (treeview) 
    74 		return selModel;
    75 	else 
    76 		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
    77 	return NULL;
    78 }
    79 
    80 
    81 void VymView::updateChilds (QModelIndex ix)
    82 {
    83 	treeview->setExpanded (ix,true);
    84 }
    85 
    86 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
    87 {
    88 	/*
    89 	cout <<"VymView::changeSelection (";
    90 	if (!newsel.indexes().isEmpty() )
    91 		cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
    92 	cout << " <- ";
    93 	if (!oldsel.indexes().isEmpty() )
    94 		cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
    95 	cout << ")\n";
    96 	*/
    97 
    98 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
    99 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
   100 }
   101