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