vymview.cpp
author insilmaril
Thu, 18 Mar 2010 11:38:14 +0000
changeset 838 e4a44912646c
parent 837 5ecd0462f76b
child 842 bec082472471
permissions -rw-r--r--
Added missing return values
     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 	connect (
    89 		model, SIGNAL (updateLayout() ),
    90 		mapEditor, SLOT (autoLayout() ) );
    91 		
    92 	mapEditor->setAntiAlias (mainWindow->isAliased());
    93 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    94 
    95 	splitter->addWidget (treeEditor);
    96 	splitter->addWidget (mapEditor);
    97 
    98 	// Set geometry
    99 	QList <int> widths;
   100 	widths<<200;
   101 	widths<<600;
   102 	splitter->setSizes(widths);
   103 }
   104 
   105 VymView::~VymView()
   106 {
   107 	//cout << "Destructor VymView\n";
   108 }
   109 
   110 VymModel* VymView::getModel()
   111 {
   112 	return model;
   113 }
   114 
   115 MapEditor* VymView::getMapEditor()
   116 {
   117 	return mapEditor;
   118 }
   119 
   120 void VymView::initFocus()
   121 {
   122 	mapEditor->setFocus();
   123 }
   124 
   125 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)	
   126 {
   127 	//cout << "VV::changeSelection   newsel.count="<<newsel.indexes().count()<<endl;
   128 
   129 	mainWindow->changeSelection (model,newsel,oldsel);	
   130 	mapEditor->updateSelection (newsel,oldsel);
   131 
   132 	if (newsel.indexes().count()>0)
   133 	{
   134 
   135 		
   136 		QModelIndex ix=newsel.indexes().first();
   137 		selModel->setCurrentIndex (ix,QItemSelectionModel::ClearAndSelect  );
   138 		treeEditor->setCurrentIndex (ix);
   139 		showSelection();
   140 		
   141 	}
   142 }
   143 
   144 void VymView::expandAll()
   145 {
   146 	treeEditor->expandAll();
   147 }
   148 
   149 void VymView::expandOneLevel()
   150 {
   151 	int level=999999;
   152 	int d;
   153 	BranchItem *cur=NULL;
   154 	BranchItem *prev=NULL;
   155 	QModelIndex pix;
   156 
   157 	// Find level to expand
   158 	model->nextBranch(cur,prev);
   159 	while (cur) 
   160 	{
   161 		pix=model->index (cur);
   162 		d=cur->depth();
   163 		if (!treeEditor->isExpanded(pix) && d < level)
   164 			level=d;
   165 		model->nextBranch(cur,prev);	
   166 	}
   167 
   168 	// Expand all to level
   169 	cur=NULL;
   170 	prev=NULL;
   171 	model->nextBranch(cur,prev);
   172 	while (cur) 
   173 	{
   174 		pix=model->index (cur);
   175 		d=cur->depth();
   176 		if (!treeEditor->isExpanded(pix) && d <= level && cur->branchCount()>0)
   177 			treeEditor->setExpanded(pix,true);
   178 		model->nextBranch(cur,prev);	
   179 	}
   180 	/* FIXME-3 optimize expanding by using flat version of next
   181 	model->nextBranch(cur,prev,false);
   182 	while (cur) 
   183 	{
   184 		cout << "ok: "<<cur->getHeadingStd()<<endl./re/videochristinaprison1_wmvl.wmv
   185 ;
   186 		model->nextBranch(cur,prev,false);	
   187 	}
   188 	*/
   189 }
   190 
   191 void VymView::collapseOneLevel()
   192 {
   193 	int level=-1;
   194 	int d;
   195 	BranchItem *cur=NULL;
   196 	BranchItem *prev=NULL;
   197 	QModelIndex pix;
   198 
   199 	// Find level to collapse
   200 	model->nextBranch(cur,prev);
   201 	while (cur) 
   202 	{
   203 		pix=model->index (cur);
   204 		d=cur->depth();
   205 		if (treeEditor->isExpanded(pix) && d > level)
   206 			level=d;
   207 		model->nextBranch(cur,prev);	
   208 	}
   209 
   210 	// collapse all to level
   211 	cur=NULL;
   212 	prev=NULL;
   213 	model->nextBranch(cur,prev);
   214 	while (cur) 
   215 	{
   216 		pix=model->index (cur);
   217 		d=cur->depth();
   218 		if (treeEditor->isExpanded(pix) && d >= level)
   219 			treeEditor->setExpanded(pix,false);
   220 		model->nextBranch(cur,prev);	
   221 	}
   222 }
   223 
   224 void VymView::showSelection()
   225 {
   226 	QModelIndex ix=model->getSelectedIndex();
   227 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   228 	mapEditor->scrollTo ( ix);	// FIXME-3 also called from MapEditor::updateSelection...
   229 }
   230 
   231 void VymView::toggleTreeEditor()
   232 {
   233 	if (treeEditor->isVisible() )
   234 		treeEditor->hide();
   235 	else
   236 		treeEditor->show();
   237 }
   238 
   239