selection.cpp
author insilmaril
Wed, 01 Apr 2009 15:06:57 +0000
changeset 749 9ff332964015
parent 746 ee6b0f3a4c2f
child 757 c6908bc17d78
permissions -rw-r--r--
moved scroll functions from BranchObj to BranchItem
     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)	// 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 
    93 bool Selection::isBlocked()
    94 {
    95 	return blocked;
    96 }
    97 
    98 void Selection::block()
    99 {
   100 	blocked=true;
   101 }
   102 
   103 void Selection::unblock()
   104 {
   105 	blocked=false;
   106 }
   107 
   108 bool Selection::isEmpty()
   109 {
   110 	return selectList.isEmpty();
   111 }
   112 
   113 /*
   114 uint Selection::count()
   115 {
   116 	return selectList.count();
   117 }
   118 */
   119 
   120 /*
   121 Selection::Type Selection::type() // TODO no multiselections yet
   122 {
   123 	if (!selectList.isEmpty())
   124 	{
   125 		LinkableMapObj *sel=selectList.first();
   126 		if (typeid (*sel)==typeid (BranchObj)) return Branch;
   127 		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
   128 		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
   129 	}
   130 	return Undefined;
   131 }
   132 */
   133 
   134 /*
   135 LinkableMapObj* Selection::first()
   136 {
   137 	if (!selectList.isEmpty())
   138 		return selectList.first();
   139 	else	
   140 		return NULL;
   141 }
   142 
   143 LinkableMapObj* Selection::single()
   144 {
   145 	if (selectList.count() == 1)
   146 		return selectList.first();
   147 	else	
   148 		return NULL;
   149 }
   150 
   151 TreeItem* Selection::getBranchItem()
   152 {
   153 	BranchObj* bo=getBranch();
   154 	if (bo) return bo->getTreeItem(); //  VM get directly from treemodl
   155 	return NULL;
   156 }
   157 
   158 QModelIndex Selection::getBranchIndex()
   159 {
   160 	return model->getSelectionModel()->selectedIndexes().first();	// TODO no multiselections yet
   161 
   162 }
   163 */
   164 
   165 FloatImageObj* Selection::getFloatImage()
   166 {
   167 	if (!selectList.isEmpty())
   168 	{
   169 		LinkableMapObj *sel=selectList.first();
   170 		if (typeid (*sel)==typeid (FloatImageObj)) 
   171 			return (FloatImageObj*)sel;
   172 	}
   173 		return NULL;
   174 }
   175 
   176 QString Selection::getSelectString() // FIXME-2 VM this is also in VM ?! clean up here...
   177 // TODO no multiselections yet
   178 {
   179 	if (selectList.count()==1)
   180 	{
   181 		return model->getSelectString (selectList.first() );
   182 	}
   183 	else
   184 		return"";
   185 }
   186 
   187