vymview.cpp
author insilmaril
Mon, 08 Mar 2010 12:24:26 +0000
changeset 829 832e96c9abb6
parent 825 1ad892c1a709
child 837 5ecd0462f76b
permissions -rw-r--r--
Introduce dockwidget to display all search results at once
     1 #include "vymview.h"
     2 
     3 #include "branchitem.h"
     4 #include "mainwindow.h"
     5 #include "mapeditor.h"
     6 #include "treeeditor.h"
     7 
     8 extern Main *mainWindow;
     9 
    10 
    11 VymView::VymView(VymModel *m)
    12 {
    13 	model=m;
    14 
    15 	// Create TreeView
    16 	treeEditor=new TreeEditor (model);
    17 	//treeEditor->setModel ((QAbstractItemModel*)model);
    18 	//treeEditor->setMinimumWidth (50);
    19 
    20 	treeEditor->setColumnWidth (0,150);
    21 	treeEditor->setAnimated (true);
    22 
    23 	selModel=new QItemSelectionModel (model);
    24 
    25 	model->setSelectionModel (selModel);
    26 	treeEditor->setSelectionModel (selModel);
    27 
    28 	// Create good old MapEditor
    29 	mapEditor=model->getMapEditor();
    30 	if (!mapEditor) mapEditor=new MapEditor (model);
    31 
    32 	// Create Layout 
    33 	QVBoxLayout* mainLayout = new QVBoxLayout (this); //FIXME-4 not needed
    34 	QSplitter *splitter= new QSplitter (this);
    35 
    36 	QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    37     splitter->setSizePolicy(sizePolicy);
    38 	mainLayout->addWidget (splitter);
    39 
    40 	// Connect selections
    41 
    42 		// Selection in Model changed	
    43 		connect (
    44 			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    45 			this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    46 
    47 		// Tell MapEditor to update selection
    48 		/* FIXME-3 done implicit here in VymView
    49 		connect (
    50 			selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    51 			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    52 			*/
    53 
    54 		// Needed to update selbox during animation
    55 		connect (
    56 			model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    57 			mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    58 
    59 	// Connect data changed signals	
    60 	connect (
    61 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    62 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    63 
    64 	connect (
    65 		model, SIGNAL (sortFilterChanged (const QString &)),
    66 		treeEditor, SLOT (setSortFilter (const QString &) ) );
    67 
    68 	connect (
    69 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    70 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    71 		
    72 	connect (
    73 		model, SIGNAL (expandAll() ),
    74 		this, SLOT (expandAll () ) );
    75 		
    76 	connect (
    77 		model, SIGNAL (expandOneLevel() ),
    78 		this, SLOT (expandOneLevel() ) );
    79 		
    80 	connect (
    81 		model, SIGNAL (collapseOneLevel() ),
    82 		this, SLOT (collapseOneLevel() ) );
    83 		
    84 	connect (
    85 		model, SIGNAL (showSelection() ),
    86 		this, SLOT (showSelection() ) );
    87 		
    88 	mapEditor->setAntiAlias (mainWindow->isAliased());
    89 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    90 
    91 	splitter->addWidget (treeEditor);
    92 	splitter->addWidget (mapEditor);
    93 
    94 	// Set geometry
    95 	QList <int> widths;
    96 	widths<<200;
    97 	widths<<600;
    98 	splitter->setSizes(widths);
    99 }
   100 
   101 VymView::~VymView()
   102 {
   103 	//cout << "Destructor VymView\n";
   104 }
   105 
   106 VymModel* VymView::getModel()
   107 {
   108 	return model;
   109 }
   110 
   111 MapEditor* VymView::getMapEditor()
   112 {
   113 	return mapEditor;
   114 }
   115 
   116 void VymView::initFocus()
   117 {
   118 	mapEditor->setFocus();
   119 }
   120 
   121 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)	
   122 {
   123 	//cout << "VV::changeSelection   newsel.count="<<newsel.indexes().count()<<endl;
   124 
   125 	mainWindow->changeSelection (model,newsel,oldsel);	
   126 	mapEditor->updateSelection (newsel,oldsel);
   127 
   128 	if (newsel.indexes().count()>0)
   129 	{
   130 
   131 		
   132 		QModelIndex ix=newsel.indexes().first();
   133 		selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect  );
   134 		treeEditor->setCurrentIndex (ix);
   135 		showSelection();
   136 		
   137 	}
   138 }
   139 
   140 void VymView::expandAll()
   141 {
   142 	treeEditor->expandAll();
   143 }
   144 
   145 void VymView::expandOneLevel()
   146 {
   147 	int level=999999;
   148 	int d;
   149 	BranchItem *cur=NULL;
   150 	BranchItem *prev=NULL;
   151 	QModelIndex pix;
   152 
   153 	// Find level to expand
   154 	model->nextBranch(cur,prev);
   155 	while (cur) 
   156 	{
   157 		pix=model->index (cur);
   158 		d=cur->depth();
   159 		if (!treeEditor->isExpanded(pix) && d < level)
   160 			level=d;
   161 		model->nextBranch(cur,prev);	
   162 	}
   163 
   164 	// Expand all to level
   165 	cur=NULL;
   166 	prev=NULL;
   167 	model->nextBranch(cur,prev);
   168 	while (cur) 
   169 	{
   170 		pix=model->index (cur);
   171 		d=cur->depth();
   172 		if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
   173 			treeEditor->setExpanded(pix,true);
   174 		model->nextBranch(cur,prev);	
   175 	}
   176 	/* FIXME-3 optimize expanding by using flat version of next
   177 	model->nextBranch(cur,prev,false);
   178 	while (cur) 
   179 	{
   180 		cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
   181 ;
   182 		model->nextBranch(cur,prev,false);	
   183 	}
   184 	*/
   185 }
   186 
   187 void VymView::collapseOneLevel()
   188 {
   189 	int level=-1;
   190 	int d;
   191 	BranchItem *cur=NULL;
   192 	BranchItem *prev=NULL;
   193 	QModelIndex pix;
   194 
   195 	// Find level to collapse
   196 	model->nextBranch(cur,prev);
   197 	while (cur) 
   198 	{
   199 		pix=model->index (cur);
   200 		d=cur->depth();
   201 		if (treeEditor->isExpanded(pix) && d > level)
   202 			level=d;
   203 		model->nextBranch(cur,prev);	
   204 	}
   205 
   206 	// collapse all to level
   207 	cur=NULL;
   208 	prev=NULL;
   209 	model->nextBranch(cur,prev);
   210 	while (cur) 
   211 	{
   212 		pix=model->index (cur);
   213 		d=cur->depth();
   214 		if (treeEditor->isExpanded(pix) && d >= level)
   215 			treeEditor->setExpanded(pix,false);
   216 		model->nextBranch(cur,prev);	
   217 	}
   218 }
   219 
   220 void VymView::showSelection()
   221 {
   222 	QModelIndex ix=model->getSelectedIndex();
   223 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   224 	mapEditor->scrollTo ( ix);	// FIXME-3 also called from MapEditor::updateSelection...
   225 }
   226 
   227 void VymView::toggleTreeEditor()
   228 {
   229 	if (treeEditor->isVisible() )
   230 		treeEditor->hide();
   231 	else
   232 		treeEditor->show();
   233 }
   234 
   235