selection.cpp
author insilmaril
Wed Mar 21 11:51:38 2007 +0000 (2007-03-21)
changeset 438 eae9abe70d7c
parent 421 5522d1da7e37
child 440 c6a8651e6bbc
permissions -rw-r--r--
Slightly improved scripting abilities
     1 #include "selection.h"
     2 
     3 
     4 Selection::Selection()
     5 {
     6 }
     7 
     8 Selection::~Selection()
     9 {
    10 }
    11 
    12 void Selection::setMapCenter(MapCenterObj *mco)
    13 {
    14 	mapCenter=mco;
    15 }
    16 
    17 void Selection::copy(const Selection &other)
    18 {
    19 	mapCenter=other.mapCenter;
    20 	selectList=other.selectList;
    21 	lastSelectList=other.lastSelectList;
    22 }
    23 
    24 void Selection::clear()
    25 {
    26 	unselect();
    27 	lastSelectList.clear();
    28 }
    29 
    30 bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
    31 {
    32 	if (!selectList.isEmpty()) unselect();
    33 	selectList.append (lmo);
    34 	lmo->select();
    35 	return true;
    36 }
    37 
    38 bool Selection::select (const QString &s)	// TODO no multiselections yet
    39 {
    40 	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
    41 
    42 	// Finally select the found object
    43 	if (lmo)
    44 	{
    45 		unselect();
    46 		select (lmo);
    47 		return true;
    48 	} 
    49 	return false;
    50 
    51 }
    52 
    53 bool Selection::reselect ()	// TODO no multiselections yet
    54 {
    55 	if (!lastSelectList.isEmpty())
    56 	{
    57 		select (lastSelectList.first());
    58 		return true;
    59 	}
    60 	return false;
    61 
    62 }
    63 
    64 void Selection::unselect()
    65 {
    66 	if (!selectList.isEmpty() )
    67 	{
    68 		for (int i=0; i< selectList.count(); ++i) 
    69 			selectList.at(i)->unselect();
    70 		lastSelectList=selectList;
    71 		selectList.clear();
    72 	}	
    73 }
    74 
    75 bool Selection::isEmpty()
    76 {
    77 	return selectList.isEmpty();
    78 }
    79 
    80 uint Selection::count()
    81 {
    82 	return selectList.count();
    83 }
    84 
    85 SelectionType Selection::type() // TODO no multiselections yet
    86 {
    87 	if (!selectList.isEmpty())
    88 	{
    89 		LinkableMapObj *sel=selectList.first();
    90 		if (typeid (*sel)==typeid (BranchObj)) return Branch;
    91 		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
    92 		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
    93 	}
    94 	return Undefined;
    95 }
    96 
    97 LinkableMapObj* Selection::first()
    98 {
    99 	if (!selectList.isEmpty())
   100 		return selectList.first();
   101 	else	
   102 		return NULL;
   103 }
   104 
   105 LinkableMapObj* Selection::single()
   106 {
   107 	if (selectList.count() == 1)
   108 		return selectList.first();
   109 	else	
   110 		return NULL;
   111 }
   112 
   113 BranchObj* Selection::getBranch()
   114 {
   115 	if (!selectList.isEmpty())
   116 	{
   117 		LinkableMapObj *sel=selectList.first();
   118 		if (typeid (*sel)==typeid (BranchObj) ||
   119 		    typeid (*sel)==typeid (MapCenterObj)) 
   120 			return (BranchObj*)sel;
   121 	}
   122 		return NULL;
   123 }
   124 
   125 FloatImageObj* Selection::getFloatImage()
   126 {
   127 	if (!selectList.isEmpty())
   128 	{
   129 		LinkableMapObj *sel=selectList.first();
   130 		if (typeid (*sel)==typeid (FloatImageObj)) 
   131 			return (FloatImageObj*)sel;
   132 	}
   133 		return NULL;
   134 }
   135 
   136 QString Selection::getSelectString()// TODO no multiselections yet
   137 {
   138 	if (selectList.count()==1)
   139 		return selectList.first()->getSelectString();
   140 	else
   141 		return"";
   142 }
   143 
   144