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