selection.cpp
author insilmaril
Wed, 04 Feb 2009 16:33:16 +0000
changeset 740 6dc0a20031f7
parent 735 84ae10f6e3a3
child 746 ee6b0f3a4c2f
permissions -rw-r--r--
started to rewrite first(), next()
     1 #include <typeinfo>
     2 #include <iostream>
     3 using namespace std;
     4 
     5 #include "selection.h"
     6 
     7 #include "mainwindow.h"
     8 #include "vymmodel.h"
     9 
    10 
    11 
    12 extern Main *mainWindow;
    13 
    14 Selection::Selection()
    15 {
    16 	blocked=false;
    17 	model=NULL;
    18 }
    19 
    20 Selection::~Selection()
    21 {
    22 }
    23 
    24 void Selection::setModel (VymModel *m)
    25 {
    26 	model=m;
    27 }
    28 
    29 void Selection::update() // FIXME VM emit signal in VM instead and get rid of this
    30 {
    31 /*
    32 	QRectF bbox;
    33 	//int w=0;
    34 	for (int i=0; i< selectList.count(); ++i) 
    35 	{
    36 		bbox=selectList.at(i)->getBBox();
    37 		selboxList.at(i)->setRect (
    38 			bbox.x()-w,bbox.y()-w, 
    39 			bbox.width()+2*w, bbox.height()+2*w);
    40 		selboxList.at(i)->setPen (color);	
    41 		selboxList.at(i)->setBrush (color);	
    42 	}	
    43 */
    44 }
    45 bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
    46 {
    47 	return model->select (lmo);
    48 	/*
    49 	if (!selectList.isEmpty()) unselect();
    50 	selectList.append (lmo);
    51 	lmo->select();
    52 	update();
    53 	mainWindow->updateSatellites (model);	
    54 	cout << "Sel::select lmo e\n";
    55 	return true;
    56 	*/
    57 }
    58 
    59 bool Selection::select (const QString &s)	// TODO no multiselections yet
    60 {
    61 	return model->select (s);
    62 	/*
    63 	cout << "Sel::select s=\n";
    64 	LinkableMapObj *lmo=model->findObjBySelect(s);
    65 
    66 	// Finally select the found object
    67 	if (lmo)
    68 	{
    69 		unselect();
    70 		select (lmo);
    71 		return true;
    72 	} 
    73 	return false;
    74 	*/
    75 }
    76 
    77 bool Selection::reselect ()	// TODO no multiselections yet
    78 {
    79 	if (!lastSelectList.isEmpty())
    80 	{
    81 		select (lastSelectList.first());
    82 		return true;
    83 	}
    84 	return false;
    85 
    86 }
    87 
    88 void Selection::unselect()
    89 {
    90 	model->unselect();
    91 	/*
    92 	cout << "Sel::unselect\n";
    93 	if (!selectList.isEmpty() )
    94 	{
    95 		for (int i=0; i< selectList.count(); ++i) 
    96 			selectList.at(i)->unselect();
    97 		lastSelectList=selectList;
    98 		selectList.clear();
    99 		// FIXME VM move to ME
   100 		//while (!selboxList.isEmpty() )	
   101 		//	delete selboxList.takeFirst();
   102 	}	
   103 		*/	
   104 }
   105 
   106 bool Selection::isBlocked()
   107 {
   108 	return blocked;
   109 }
   110 
   111 void Selection::block()
   112 {
   113 	blocked=true;
   114 }
   115 
   116 void Selection::unblock()
   117 {
   118 	blocked=false;
   119 }
   120 
   121 bool Selection::isEmpty()
   122 {
   123 	return selectList.isEmpty();
   124 }
   125 
   126 /*
   127 uint Selection::count()
   128 {
   129 	return selectList.count();
   130 }
   131 */
   132 
   133 /*
   134 Selection::Type Selection::type() // TODO no multiselections yet
   135 {
   136 	if (!selectList.isEmpty())
   137 	{
   138 		LinkableMapObj *sel=selectList.first();
   139 		if (typeid (*sel)==typeid (BranchObj)) return Branch;
   140 		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
   141 		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
   142 	}
   143 	return Undefined;
   144 }
   145 */
   146 
   147 /*
   148 LinkableMapObj* Selection::first()
   149 {
   150 	if (!selectList.isEmpty())
   151 		return selectList.first();
   152 	else	
   153 		return NULL;
   154 }
   155 
   156 LinkableMapObj* Selection::single()
   157 {
   158 	if (selectList.count() == 1)
   159 		return selectList.first();
   160 	else	
   161 		return NULL;
   162 }
   163 
   164 TreeItem* Selection::getBranchItem()
   165 {
   166 	BranchObj* bo=getBranch();
   167 	if (bo) return bo->getTreeItem(); // FIXME VM get directly from treemodl
   168 	return NULL;
   169 }
   170 
   171 QModelIndex Selection::getBranchIndex()
   172 {
   173 	return model->getSelectionModel()->selectedIndexes().first();	// TODO no multiselections yet
   174 
   175 }
   176 */
   177 
   178 FloatImageObj* Selection::getFloatImage()
   179 {
   180 	if (!selectList.isEmpty())
   181 	{
   182 		LinkableMapObj *sel=selectList.first();
   183 		if (typeid (*sel)==typeid (FloatImageObj)) 
   184 			return (FloatImageObj*)sel;
   185 	}
   186 		return NULL;
   187 }
   188 
   189 QString Selection::getSelectString() // FIXME VM this is also in VM ?! clean up here...
   190 // TODO no multiselections yet
   191 {
   192 	if (selectList.count()==1)
   193 	{
   194 		return model->getSelectString (selectList.first() );
   195 	}
   196 	else
   197 		return"";
   198 }
   199 
   200