vymview.cpp
author insilmaril
Fri, 02 Oct 2009 09:40:57 +0000
changeset 801 16a8ef1d82b2
parent 800 959bd133cd1a
child 802 f076fdec767d
permissions -rw-r--r--
using QSortFilterProxy now to enable filtering in TreeEditor
     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 	proxySelModel=treeEditor->selectionModel();
    26 	selModel=new QItemSelectionModel (model);
    27 
    28 	//model->setSelectionModel (proxySelModel);
    29 	model->setSelectionModel (selModel);
    30 
    31 	// Create good old MapEditor
    32 	mapEditor=model->getMapEditor();
    33 	if (!mapEditor) mapEditor=new MapEditor (model);
    34 
    35 	// Connect selections
    36 
    37 		// Proxymodel changed
    38 		connect (
    39 			proxySelModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    40 			this,SLOT (changeProxySelection(const QItemSelection &,const QItemSelection &)));
    41 
    42 		// Model changed	
    43 		connect (
    44 			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    45 			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    46 
    47 		connect (
    48 			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)),
    49 			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    50 			//FIXME-3 above and below necessary???
    51 		connect (
    52 			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    53 			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    54 
    55 	// Connect data changed signals	
    56 	connect (
    57 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    58 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    59 
    60 	connect (
    61 		model, SIGNAL (sortFilterChanged (const QString &)),
    62 		treeEditor, SLOT (setSortFilter (const QString &) ) );
    63 
    64 	connect (
    65 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    66 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    67 		
    68 	connect (
    69 		model, SIGNAL (expandAll() ),
    70 		this, SLOT (expandAll () ) );
    71 		
    72 	connect (
    73 		model, SIGNAL (showSelection() ),
    74 		this, SLOT (showSelection() ) );
    75 		
    76 
    77 	mapEditor->setAntiAlias (mainWindow->isAliased());
    78 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    79 
    80 	addWidget (treeEditor);
    81 	addWidget (mapEditor);
    82 
    83 	// Set geometry
    84 	QList <int> widths;
    85 	widths<<200;
    86 	widths<<600;
    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 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   111 {
   112 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   113 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   114 	// would require to also get current model in mainWindow
   115 	proxySelModel->select (
   116 		treeEditor->getProxyModel()->mapSelectionFromSource (newsel),
   117 		QItemSelectionModel::ClearAndSelect );
   118 	showSelection();
   119 }
   120 
   121 void VymView::changeProxySelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   122 {
   123 	// Notify mainwindow to update satellites, but map selection to 
   124 	// original model first
   125 
   126 	// Re-emit but map selection first
   127 	model->emitSelectionChanged (treeEditor->getProxyModel()->mapSelectionToSource (newsel));
   128 }
   129 
   130 void VymView::expandAll()
   131 {
   132 	treeEditor->expandAll();
   133 }
   134 
   135 void VymView::showSelection()
   136 {
   137 	QModelIndex ix=model->getSelectedIndex();
   138 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   139 	mapEditor->scrollTo ( ix);
   140 }
   141