vymview.cpp
author insilmaril
Tue, 18 Aug 2009 12:39:07 +0000
changeset 788 78ba80b54bc4
parent 777 8acac4fade1b
child 791 f1006de05c54
permissions -rw-r--r--
Fix for segfault when deleting MCO (invalid QModelIndex needs to be returned in index(TreeItem*) )
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "mainwindow.h"
     7 #include "mapeditor.h"
     8 #include "treeeditor.h"
     9 
    10 extern Main *mainWindow;
    11 
    12 
    13 VymView::VymView(VymModel *m)
    14 {
    15 	model=m;
    16 
    17 	// Create TreeView
    18 	treeEditor=new TreeEditor (model);
    19 	//treeEditor->setModel ((QAbstractItemModel*)model);
    20 	//treeEditor->setMinimumWidth (50);
    21 
    22 	treeEditor->setColumnWidth (0,150);
    23 	treeEditor->setAnimated (true);
    24 
    25 	
    26 	selModel=treeEditor->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=model->getMapEditor();
    34 	if (!mapEditor) mapEditor=new MapEditor (model);
    35 	connect (
    36 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    37 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    38 
    39 	connect (
    40 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    41 		model,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    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 	connect (
    53 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    54 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    55 		
    56 	connect (
    57 		model, SIGNAL (expandAll() ),
    58 		this, SLOT (expandAll () ) );
    59 		
    60 	connect (
    61 		model, SIGNAL (showSelection() ),
    62 		this, SLOT (showSelection() ) );
    63 		
    64 
    65 	mapEditor->setAntiAlias (mainWindow->isAliased());
    66 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    67 
    68 	addWidget (treeEditor);
    69 	addWidget (mapEditor);
    70 
    71 /*
    72 	tv=new QTreeView;
    73 	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    74 	proxyModel->setDynamicSortFilter (true);
    75 	proxyModel->setSourceModel(model);
    76 	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
    77 	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
    78 	proxyModel->setFilterKeyColumn(0);
    79 	tv->setModel (proxyModel);
    80 	addWidget (tv);
    81 */
    82 	// Set geometry
    83 	QList <int> widths;
    84 	widths<<200;
    85 	widths<<600;
    86 //	widths<<200;
    87 	setSizes(widths);
    88 }
    89 
    90 VymView::~VymView()
    91 {
    92 	//cout << "Destructor VymView\n";
    93 }
    94 
    95 VymModel* VymView::getModel()
    96 {
    97 	return model;
    98 }
    99 
   100 MapEditor* VymView::getMapEditor()
   101 {
   102 	return mapEditor;
   103 }
   104 
   105 void VymView::initFocus()
   106 {
   107 	mapEditor->setFocus();
   108 }
   109 
   110 QItemSelectionModel* VymView::selectionModel() 
   111 {
   112 	if (treeEditor) 
   113 		return selModel;
   114 	else 
   115 		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
   116 	return NULL;
   117 }
   118 
   119 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   120 {
   121 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   122 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   123 	// would require to also get current model in mainWindow
   124 
   125 	//showSelection();
   126 }
   127 
   128 void VymView::expandAll()
   129 {
   130 	treeEditor->expandAll();
   131 	//tv->expandAll();
   132 }
   133 
   134 void VymView::showSelection()
   135 {
   136 	QModelIndex ix=model->getSelectedIndex();
   137 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   138 	mapEditor->scrollTo ( ix);
   139 }
   140