selection.cpp
author insilmaril
Tue, 31 Mar 2009 15:36:10 +0000
changeset 748 edb78a44240b
parent 746 ee6b0f3a4c2f
child 757 c6908bc17d78
permissions -rw-r--r--
Removing branches and mapcenters works
insilmaril@611
     1
#include <typeinfo>
insilmaril@735
     2
#include <iostream>
insilmaril@735
     3
using namespace std;
insilmaril@611
     4
insilmaril@0
     5
#include "selection.h"
insilmaril@0
     6
insilmaril@440
     7
#include "mainwindow.h"
insilmaril@641
     8
#include "vymmodel.h"
insilmaril@440
     9
insilmaril@440
    10
insilmaril@440
    11
insilmaril@440
    12
extern Main *mainWindow;
insilmaril@0
    13
insilmaril@0
    14
Selection::Selection()
insilmaril@0
    15
{
insilmaril@721
    16
	blocked=false;
insilmaril@735
    17
	model=NULL;
insilmaril@0
    18
}
insilmaril@0
    19
insilmaril@0
    20
Selection::~Selection()
insilmaril@0
    21
{
insilmaril@0
    22
}
insilmaril@0
    23
insilmaril@641
    24
void Selection::setModel (VymModel *m)
insilmaril@0
    25
{
insilmaril@641
    26
	model=m;
insilmaril@0
    27
}
insilmaril@0
    28
insilmaril@746
    29
void Selection::update() // FIXME-2 VM emit signal in VM instead and get rid of this
insilmaril@440
    30
{
insilmaril@729
    31
/*
insilmaril@440
    32
	QRectF bbox;
insilmaril@728
    33
	//int w=0;
insilmaril@440
    34
	for (int i=0; i< selectList.count(); ++i) 
insilmaril@440
    35
	{
insilmaril@440
    36
		bbox=selectList.at(i)->getBBox();
insilmaril@440
    37
		selboxList.at(i)->setRect (
insilmaril@440
    38
			bbox.x()-w,bbox.y()-w, 
insilmaril@440
    39
			bbox.width()+2*w, bbox.height()+2*w);
insilmaril@440
    40
		selboxList.at(i)->setPen (color);	
insilmaril@440
    41
		selboxList.at(i)->setBrush (color);	
insilmaril@440
    42
	}	
insilmaril@729
    43
*/
insilmaril@440
    44
}
insilmaril@421
    45
bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
insilmaril@0
    46
{
insilmaril@735
    47
	return model->select (lmo);
insilmaril@735
    48
	/*
insilmaril@424
    49
	if (!selectList.isEmpty()) unselect();
insilmaril@16
    50
	selectList.append (lmo);
insilmaril@424
    51
	lmo->select();
insilmaril@460
    52
	update();
insilmaril@723
    53
	mainWindow->updateSatellites (model);	
insilmaril@735
    54
	cout << "Sel::select lmo e\n";
insilmaril@424
    55
	return true;
insilmaril@735
    56
	*/
insilmaril@0
    57
}
insilmaril@0
    58
insilmaril@421
    59
bool Selection::select (const QString &s)	// TODO no multiselections yet
insilmaril@0
    60
{
insilmaril@735
    61
	return model->select (s);
insilmaril@735
    62
	/*
insilmaril@735
    63
	cout << "Sel::select s=\n";
insilmaril@641
    64
	LinkableMapObj *lmo=model->findObjBySelect(s);
insilmaril@16
    65
insilmaril@16
    66
	// Finally select the found object
insilmaril@16
    67
	if (lmo)
insilmaril@16
    68
	{
insilmaril@424
    69
		unselect();
insilmaril@16
    70
		select (lmo);
insilmaril@16
    71
		return true;
insilmaril@16
    72
	} 
insilmaril@16
    73
	return false;
insilmaril@735
    74
	*/
insilmaril@16
    75
}
insilmaril@16
    76
insilmaril@421
    77
bool Selection::reselect ()	// TODO no multiselections yet
insilmaril@421
    78
{
insilmaril@421
    79
	if (!lastSelectList.isEmpty())
insilmaril@421
    80
	{
insilmaril@421
    81
		select (lastSelectList.first());
insilmaril@421
    82
		return true;
insilmaril@421
    83
	}
insilmaril@421
    84
	return false;
insilmaril@421
    85
insilmaril@421
    86
}
insilmaril@421
    87
insilmaril@16
    88
void Selection::unselect()
insilmaril@16
    89
{
insilmaril@735
    90
	model->unselect();
insilmaril@0
    91
}
insilmaril@0
    92
insilmaril@721
    93
bool Selection::isBlocked()
insilmaril@721
    94
{
insilmaril@721
    95
	return blocked;
insilmaril@721
    96
}
insilmaril@721
    97
insilmaril@721
    98
void Selection::block()
insilmaril@721
    99
{
insilmaril@721
   100
	blocked=true;
insilmaril@721
   101
}
insilmaril@721
   102
insilmaril@721
   103
void Selection::unblock()
insilmaril@721
   104
{
insilmaril@721
   105
	blocked=false;
insilmaril@721
   106
}
insilmaril@721
   107
insilmaril@0
   108
bool Selection::isEmpty()
insilmaril@0
   109
{
insilmaril@0
   110
	return selectList.isEmpty();
insilmaril@0
   111
}
insilmaril@0
   112
insilmaril@735
   113
/*
insilmaril@0
   114
uint Selection::count()
insilmaril@0
   115
{
insilmaril@0
   116
	return selectList.count();
insilmaril@0
   117
}
insilmaril@735
   118
*/
insilmaril@16
   119
insilmaril@735
   120
/*
insilmaril@492
   121
Selection::Type Selection::type() // TODO no multiselections yet
insilmaril@16
   122
{
insilmaril@421
   123
	if (!selectList.isEmpty())
insilmaril@421
   124
	{
insilmaril@421
   125
		LinkableMapObj *sel=selectList.first();
insilmaril@421
   126
		if (typeid (*sel)==typeid (BranchObj)) return Branch;
insilmaril@421
   127
		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
insilmaril@421
   128
		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
insilmaril@421
   129
	}
insilmaril@421
   130
	return Undefined;
insilmaril@421
   131
}
insilmaril@735
   132
*/
insilmaril@421
   133
insilmaril@735
   134
/*
insilmaril@424
   135
LinkableMapObj* Selection::first()
insilmaril@424
   136
{
insilmaril@424
   137
	if (!selectList.isEmpty())
insilmaril@424
   138
		return selectList.first();
insilmaril@424
   139
	else	
insilmaril@424
   140
		return NULL;
insilmaril@424
   141
}
insilmaril@424
   142
insilmaril@424
   143
LinkableMapObj* Selection::single()
insilmaril@424
   144
{
insilmaril@424
   145
	if (selectList.count() == 1)
insilmaril@424
   146
		return selectList.first();
insilmaril@424
   147
	else	
insilmaril@424
   148
		return NULL;
insilmaril@424
   149
}
insilmaril@424
   150
insilmaril@726
   151
TreeItem* Selection::getBranchItem()
insilmaril@726
   152
{
insilmaril@726
   153
	BranchObj* bo=getBranch();
insilmaril@746
   154
	if (bo) return bo->getTreeItem(); //  VM get directly from treemodl
insilmaril@726
   155
	return NULL;
insilmaril@726
   156
}
insilmaril@726
   157
insilmaril@728
   158
QModelIndex Selection::getBranchIndex()
insilmaril@728
   159
{
insilmaril@732
   160
	return model->getSelectionModel()->selectedIndexes().first();	// TODO no multiselections yet
insilmaril@728
   161
insilmaril@728
   162
}
insilmaril@735
   163
*/
insilmaril@728
   164
insilmaril@424
   165
FloatImageObj* Selection::getFloatImage()
insilmaril@424
   166
{
insilmaril@424
   167
	if (!selectList.isEmpty())
insilmaril@424
   168
	{
insilmaril@424
   169
		LinkableMapObj *sel=selectList.first();
insilmaril@424
   170
		if (typeid (*sel)==typeid (FloatImageObj)) 
insilmaril@424
   171
			return (FloatImageObj*)sel;
insilmaril@424
   172
	}
insilmaril@424
   173
		return NULL;
insilmaril@424
   174
}
insilmaril@424
   175
insilmaril@746
   176
QString Selection::getSelectString() // FIXME-2 VM this is also in VM ?! clean up here...
insilmaril@729
   177
// TODO no multiselections yet
insilmaril@421
   178
{
insilmaril@16
   179
	if (selectList.count()==1)
insilmaril@650
   180
	{
insilmaril@650
   181
		return model->getSelectString (selectList.first() );
insilmaril@650
   182
	}
insilmaril@16
   183
	else
insilmaril@16
   184
		return"";
insilmaril@16
   185
}
insilmaril@16
   186
insilmaril@16
   187