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