selection.cpp
author insilmaril
Fri, 15 May 2009 15:22:15 +0000
changeset 769 a6931cd6309a
parent 757 c6908bc17d78
permissions -rw-r--r--
more changes on views
     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-2 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)// FIXME-2 VM emit signal in VM instead and get rid of this
    46 
    47 {
    48 	return model->select (lmo);
    49 	/*
    50 	if (!selectList.isEmpty()) unselect();
    51 	selectList.append (lmo);
    52 	lmo->select();
    53 	update();
    54 	mainWindow->updateSatellites (model);	
    55 	cout << "Sel::select lmo e\n";
    56 	return true;
    57 	*/
    58 }
    59 
    60 bool Selection::select (const QString &s)// FIXME-2 VM emit signal in VM instead and get rid of this
    61 
    62 {
    63 	return model->select (s);
    64 	/*
    65 	cout << "Sel::select s=\n";
    66 	LinkableMapObj *lmo=model->findObjBySelect(s);
    67 
    68 	// Finally select the found object
    69 	if (lmo)
    70 	{
    71 		unselect();
    72 		select (lmo);
    73 		return true;
    74 	} 
    75 	return false;
    76 	*/
    77 }
    78 
    79 bool Selection::reselect ()	// TODO no multiselections yet
    80 {
    81 	if (!lastSelectList.isEmpty())
    82 	{
    83 		select (lastSelectList.first());
    84 		return true;
    85 	}
    86 	return false;
    87 
    88 }
    89 
    90 void Selection::unselect()
    91 {
    92 	model->unselect();
    93 }
    94 
    95 bool Selection::isBlocked()
    96 {
    97 	return blocked;
    98 }
    99 
   100 void Selection::block()
   101 {
   102 	blocked=true;
   103 }
   104 
   105 void Selection::unblock()
   106 {
   107 	blocked=false;
   108 }
   109 
   110 bool Selection::isEmpty()
   111 {
   112 	return selectList.isEmpty();
   113 }
   114 
   115 /*
   116 uint Selection::count()
   117 {
   118 	return selectList.count();
   119 }
   120 */
   121 
   122 /*
   123 Selection::Type Selection::type() // TODO no multiselections yet
   124 {
   125 	if (!selectList.isEmpty())
   126 	{
   127 		LinkableMapObj *sel=selectList.first();
   128 		if (typeid (*sel)==typeid (BranchObj)) return Branch;
   129 		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
   130 		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
   131 	}
   132 	return Undefined;
   133 }
   134 */
   135 
   136 /*
   137 LinkableMapObj* Selection::first()
   138 {
   139 	if (!selectList.isEmpty())
   140 		return selectList.first();
   141 	else	
   142 		return NULL;
   143 }
   144 
   145 LinkableMapObj* Selection::single()
   146 {
   147 	if (selectList.count() == 1)
   148 		return selectList.first();
   149 	else	
   150 		return NULL;
   151 }
   152 
   153 TreeItem* Selection::getBranchItem()
   154 {
   155 	BranchObj* bo=getBranch();
   156 	if (bo) return bo->getTreeItem(); //  VM get directly from treemodl
   157 	return NULL;
   158 }
   159 
   160 QModelIndex Selection::getBranchIndex()
   161 {
   162 	return model->getSelectionModel()->selectedIndexes().first();	// TODO no multiselections yet
   163 
   164 }
   165 */
   166 
   167 FloatImageObj* Selection::getFloatImage()
   168 {
   169 	if (!selectList.isEmpty())
   170 	{
   171 		LinkableMapObj *sel=selectList.first();
   172 		if (typeid (*sel)==typeid (FloatImageObj)) 
   173 			return (FloatImageObj*)sel;
   174 	}
   175 		return NULL;
   176 }
   177 
   178 QString Selection::getSelectString() // FIXME-2 VM this is also in VM ?! clean up here...
   179 // TODO no multiselections yet
   180 {
   181 	if (selectList.count()==1)
   182 	{
   183 		return model->getSelectString (selectList.first() );
   184 	}
   185 	else
   186 		return"";
   187 }
   188 
   189