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