vymview.cpp
author insilmaril
Thu, 01 Oct 2009 11:28:50 +0000
changeset 798 d251c7b2de54
parent 791 f1006de05c54
child 799 2c42ad499ac3
permissions -rw-r--r--
Various fixes for relinking and selecting
     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 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    41 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    42 
    43 	// VymModel may want to update selection or other data, e.g. during animation
    44 	connect (
    45 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    46 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    47 
    48 	connect (
    49 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    50 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    51 		
    52 	connect (
    53 		model, SIGNAL (expandAll() ),
    54 		this, SLOT (expandAll () ) );
    55 		
    56 	connect (
    57 		model, SIGNAL (showSelection() ),
    58 		this, SLOT (showSelection() ) );
    59 		
    60 
    61 	mapEditor->setAntiAlias (mainWindow->isAliased());
    62 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    63 
    64 	addWidget (treeEditor);
    65 	addWidget (mapEditor);
    66 
    67 /*
    68 	tv=new QTreeView;
    69 	QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel (this);
    70 	proxyModel->setDynamicSortFilter (true);
    71 	proxyModel->setSourceModel(model);
    72 	//proxyModel->setFilterFixedString ("a",Qt::CaseInsensitive,QRegExp::FixedString);
    73 	proxyModel->setFilterRegExp(QRegExp("e", Qt::CaseInsensitive));
    74 	proxyModel->setFilterKeyColumn(0);
    75 	tv->setModel (proxyModel);
    76 	addWidget (tv);
    77 */
    78 	// Set geometry
    79 	QList <int> widths;
    80 	widths<<200;
    81 	widths<<600;
    82 //	widths<<200;
    83 	setSizes(widths);
    84 }
    85 
    86 VymView::~VymView()
    87 {
    88 	//cout << "Destructor VymView\n";
    89 }
    90 
    91 VymModel* VymView::getModel()
    92 {
    93 	return model;
    94 }
    95 
    96 MapEditor* VymView::getMapEditor()
    97 {
    98 	return mapEditor;
    99 }
   100 
   101 void VymView::initFocus()
   102 {
   103 	mapEditor->setFocus();
   104 }
   105 
   106 QItemSelectionModel* VymView::selectionModel() 
   107 {
   108 	if (treeEditor) 
   109 		return selModel;
   110 	else 
   111 		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
   112 	return NULL;
   113 }
   114 
   115 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   116 {
   117 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   118 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   119 	// would require to also get current model in mainWindow
   120 
   121 	//showSelection();	// if called here, no tmpParObj can be set...
   122 }
   123 
   124 void VymView::expandAll()
   125 {
   126 	treeEditor->expandAll();
   127 	//tv->expandAll();
   128 }
   129 
   130 void VymView::showSelection()
   131 {
   132 	QModelIndex ix=model->getSelectedIndex();
   133 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   134 	mapEditor->scrollTo ( ix);
   135 }
   136