vymview.cpp
author insilmaril
Thu, 07 May 2009 08:48:53 +0000
changeset 766 7a71a914afdb
parent 763 8c028a5d9083
child 767 6d2b32f305f9
permissions -rw-r--r--
Started to reanimate flags
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "linkablemapobj.h"
     7 #include "mainwindow.h"
     8 #include "mapeditor.h"
     9 
    10 extern Main *mainWindow;
    11 
    12 
    13 VymView::VymView(VymModel *m)
    14 {
    15 	model=m;
    16 
    17 	// Create TreeView
    18 	treeview=new QTreeView;
    19 	treeview->setModel ((QAbstractItemModel*)model);
    20 	//treeview->setMinimumWidth (50);
    21 
    22 	treeview->setColumnWidth (0,350);
    23 
    24 	selModel=treeview->selectionModel();
    25 	model->setSelectionModel (selModel);
    26 	connect (
    27 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    28 		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    29 
    30 	// Create good old MapEditor
    31 	mapEditor=model->getMapEditor();
    32 	if (!mapEditor) mapEditor=new MapEditor (model);
    33 	connect (
    34 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    35 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    36 		/*
    37 	connect (
    38 		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
    39 		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
    40 		*/
    41 		/*
    42 */
    43 	connect (
    44 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    45 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    46 
    47 	// VymModel may want to update selection or other data, e.g. during animation
    48 	connect (
    49 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    50 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    51 
    52 		/*
    53 	connect (
    54 		model, SIGNAL (newChildObject(QModelIndex) ),
    55 		this,SLOT (updateChilds (QModelIndex) ) );
    56 */
    57 
    58 	connect (
    59 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    60 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    61 		
    62 	connect (
    63 		model, SIGNAL (expandAll() ),
    64 		this, SLOT (expandAll () ) );
    65 		
    66 	connect (
    67 		model, SIGNAL (showSelection() ),
    68 		this, SLOT (showSelection() ) );
    69 		
    70 
    71 	//mapEditor->viewport()->setFocus();	//FIXmapEditor-3 needed?
    72 	mapEditor->setAntiAlias (mainWindow->isAliased());
    73 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    74 
    75 	addWidget (treeview);
    76 	addWidget (mapEditor);
    77 
    78 	// Set geometry
    79 	QList <int> widths;
    80 	widths<<120;
    81 	widths<<600;
    82 	setSizes(widths);
    83 }
    84 
    85 QItemSelectionModel* VymView::selectionModel() 
    86 {
    87 	if (treeview) 
    88 		return selModel;
    89 	else 
    90 		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
    91 	return NULL;
    92 }
    93 
    94 
    95 void VymView::updateChilds (QModelIndex ix)		//FIXME-4 not needed?
    96 {
    97 	cout << "VV::updateChilds \n";
    98 	//treeview->setExpanded (ix,true);	// This is expensive...
    99 }
   100 
   101 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   102 {
   103 	/*
   104 	cout <<"VymView::changeSelection (";
   105 	if (!newsel.indexes().isEmpty() )
   106 		cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
   107 	cout << " <- ";
   108 	if (!oldsel.indexes().isEmpty() )
   109 		cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
   110 	cout << ")\n";
   111 	*/
   112 
   113 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   114 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
   115 }
   116 
   117 void VymView::expandAll()
   118 {
   119 	treeview->expandAll();
   120 }
   121 
   122 void VymView::showSelection()
   123 {
   124 	treeview->scrollTo(
   125 		model->getSelectedIndex(), 
   126 		//QAbstractItemView::PositionAtCenter   
   127 		QAbstractItemView::EnsureVisible
   128 	);
   129 
   130 	LinkableMapObj* lmo=model->getSelectedLMO();
   131 	if (lmo)
   132 		mapEditor->ensureVisible(lmo->getBBox() );
   133 }
   134