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