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