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