1.1 --- a/mapeditor.cpp Tue Mar 09 13:09:05 2010 +0000
1.2 +++ b/mapeditor.cpp Wed Mar 10 15:36:19 2010 +0000
1.3 @@ -1,7 +1,5 @@
1.4 #include "mapeditor.h"
1.5
1.6 -#include <iostream>
1.7 -
1.8 #include <QObject>
1.9
1.10 #include "branchitem.h"
1.11 @@ -31,7 +29,7 @@
1.12 ///////////////////////////////////////////////////////////////////////
1.13 MapEditor::MapEditor( VymModel *vm)
1.14 {
1.15 - //cout << "Constructor ME "<<this<<endl;
1.16 + //qDebug() << "Constructor ME "<<this;
1.17 mapScene= new QGraphicsScene(NULL);
1.18 mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
1.19
1.20 @@ -162,7 +160,7 @@
1.21
1.22 MapEditor::~MapEditor()
1.23 {
1.24 - //cout <<"Destructor MapEditor for "<<model->getMapName().toStdString()<<endl;
1.25 + //qDebug() <<"Destructor MapEditor for "<<model->getMapName();
1.26 model->unregisterEditor(this);
1.27 }
1.28
1.29 @@ -425,8 +423,8 @@
1.30
1.31 if (rt.isNull()) rt=r1;
1.32 rt=addBBox (r1, rt);
1.33 - //FIXME-2 cout <<"ME: r1="<<r1<<" "<<cur->getHeadingStd()<<endl;
1.34 - //cout <<" rt="<<rt<<endl;
1.35 + //qDebug() <<"ME: r1="<<r1<<" "<<cur->getHeadingStd();
1.36 + //qDebug() <<" rt="<<rt;
1.37 }
1.38 }
1.39 model->nextBranch(cur,prev);
1.40 @@ -472,7 +470,7 @@
1.41 mapCenter->calcBBoxSizeWithChilds();
1.42 QRectF totalBBox=mapCenter->getTotalBBox();
1.43 //QRectF mapRect=totalBBox;
1.44 - cout << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
1.45 + qDebug() << " map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
1.46
1.47 mapRect.setRect (totalBBox.x(), totalBBox.y(),
1.48 totalBBox.width(), totalBBox.height());
1.49 @@ -488,7 +486,7 @@
1.50 {
1.51 setHideTmpMode (HideNone);
1.52 }
1.53 - cout <<" hidemode="<<hidemode<<endl;
1.54 + qDebug() <<" hidemode="<<hidemode;
1.55 */
1.56 /*
1.57 // Toggle hidemode
1.58 @@ -499,106 +497,8 @@
1.59 */
1.60 }
1.61
1.62 -TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
1.63 +void MapEditor::autoLayout()
1.64 {
1.65 - // Start with mapcenter, no images allowed at rootItem
1.66 - int i=0;
1.67 - BranchItem *bi=model->getRootItem()->getFirstBranch();
1.68 - TreeItem *found=NULL;
1.69 - while (bi)
1.70 - {
1.71 - found=bi->findMapItem (p, exclude);
1.72 - if (found) return found;
1.73 - i++;
1.74 - bi=model->getRootItem()->getBranchNum(i);
1.75 - }
1.76 - return NULL;
1.77 -}
1.78 -
1.79 -AttributeTable* MapEditor::attributeTable()
1.80 -{
1.81 - return attrTable;
1.82 -}
1.83 -
1.84 -void MapEditor::testFunction1()
1.85 -{
1.86 - cout << "ME::test1 selected TI="<<model->getSelectedItem()<<endl;
1.87 - model->setExportMode (true);
1.88 -
1.89 - /*
1.90 - // Code copied from Qt sources
1.91 - QRectF rect=model->getSelectedBranchObj()->getBBox();
1.92 - int xmargin=50;
1.93 - int ymargin=50;
1.94 -
1.95 - qreal width = viewport()->width();
1.96 - qreal height = viewport()->height();
1.97 - QRectF viewRect = matrix().mapRect(rect);
1.98 -
1.99 - qreal left = horizontalScrollBar()->value();
1.100 - qreal right = left + width;
1.101 - qreal top = verticalScrollBar()->value();
1.102 - qreal bottom = top + height;
1.103 -
1.104 - if (viewRect.left() <= left + xmargin) {
1.105 - // need to scroll from the left
1.106 - // if (!d->leftIndent)
1.107 - horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
1.108 - }
1.109 - if (viewRect.right() >= right - xmargin) {
1.110 - // need to scroll from the right
1.111 -// if (!d->leftIndent)
1.112 - horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
1.113 - }
1.114 - if (viewRect.top() <= top + ymargin) {
1.115 - // need to scroll from the top
1.116 - // if (!d->topIndent)
1.117 - verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
1.118 - }
1.119 - if (viewRect.bottom() >= bottom - ymargin) {
1.120 - // need to scroll from the bottom
1.121 -// if (!d->topIndent)
1.122 - verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
1.123 - }
1.124 - cout << "test1: hor="<<horizontalScrollBar()->value()<<endl;
1.125 - cout << "test1: ver="<<verticalScrollBar()->value()<<endl;
1.126 -}
1.127 -
1.128 -*/
1.129 -/*
1.130 - QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
1.131 - animation->setDuration(5000);
1.132 - //animation->setEasingCurve ( QtEasingCurve::OutElastic);
1.133 - animation->setEasingCurve ( QtEasingCurve::OutQuint);
1.134 - animation->setStartValue(sceneRect() );
1.135 - animation->setEndValue(QRectF(50, 50, 1000, 1000));
1.136 -
1.137 - animation->start();
1.138 -*/
1.139 -/*
1.140 - QDialog *dia= new QDialog (this);
1.141 - dia->setGeometry (50,50,10,10);
1.142 -
1.143 - dia->show();
1.144 - dia ->raise();
1.145 -
1.146 - QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
1.147 - animation->setDuration(1000);
1.148 - //animation->setEasingCurve ( QtEasingCurve::OutElastic);
1.149 - animation->setEasingCurve ( QtEasingCurve::OutQuint);
1.150 - animation->setStartValue(QRect(50, 50, 10, 10));
1.151 - animation->setEndValue(QRect(250, 250, 100, 100));
1.152 -
1.153 - animation->start();
1.154 - */
1.155 -
1.156 -}
1.157 -
1.158 -void MapEditor::testFunction2()
1.159 -{
1.160 - model->setExportMode (false);
1.161 - return;
1.162 -
1.163 // Create list with all bounding polygons
1.164 QList <LinkableMapObj*> mapobjects;
1.165 QList <ConvexPolygon> polys;
1.166 @@ -659,19 +559,19 @@
1.167 if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect )
1.168 {
1.169 collisions++;
1.170 - //cout << "Collision: "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<endl;
1.171 + //qDebug() << "Collision: "<<headings[i]<<" - "<<headings[j];
1.172 v=polys.at(j).centroid()-polys.at(i).centroid();
1.173 // Move also away if centroids are identical
1.174 if (v.isNull())
1.175 {
1.176 - //cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<endl;
1.177 + //qDebug() << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v;
1.178 v.setX (rand()%200 -100);
1.179 v.setY (rand()%200 -100);
1.180 - //cout << v;
1.181 + //qDebug() << v;
1.182 }
1.183 v.normalize();
1.184 v.scale (2);
1.185 - //cout << " v="<<v<<endl;
1.186 + //qDebug() << " v="<<v;
1.187 vectors[j]=v;
1.188 vectors[i]=v;
1.189 vectors[i].invert();
1.190 @@ -680,10 +580,10 @@
1.191 }
1.192 for (int i=0;i<vectors.size();i++)
1.193 {
1.194 - //cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl;
1.195 + //qDebug() << " v="<<vectors[i]<<" "<<headings[i];
1.196 polys[i].translate (vectors[i]);
1.197 }
1.198 - cout << "Collisions: "<<collisions<<endl;
1.199 + if (debug) qDebug()<< "Collisions: "<<collisions;
1.200 //collisions=0;
1.201 }
1.202
1.203 @@ -693,9 +593,11 @@
1.204 {
1.205 Vector v=polys[i].at(0)-orgpos[i];
1.206 orients.append (mapobjects[i]->getOrientation());
1.207 - mapobjects[i]->moveBy(v.x(),v.y() );
1.208 - mapobjects[i]->setRelPos();
1.209 + // mapobjects[i]->moveBy(v.x(),v.y() );
1.210 + // mapobjects[i]->setRelPos();
1.211 + model->startAnimation ((BranchObj*)mapobjects[i], mapobjects[i]->getAbsPos(), mapobjects[i]->getAbsPos() + v);
1.212 }
1.213 + /*
1.214 model->reposition();
1.215 orientationChanged=false;
1.216 for (int i=0;i<polys.size();i++)
1.217 @@ -704,14 +606,116 @@
1.218 orientationChanged=true;
1.219 break;
1.220 }
1.221 - cout << "Final: orientChanged="<<orientationChanged<<endl;
1.222 + */
1.223 break;
1.224 +
1.225 +
1.226 //orientationChanged=false;
1.227 } // loop if orientation has changed
1.228
1.229 model->emitSelectionChanged();
1.230 }
1.231
1.232 +TreeItem* MapEditor::findMapItem (QPointF p,TreeItem *exclude)
1.233 +{
1.234 + // Start with mapcenter, no images allowed at rootItem
1.235 + int i=0;
1.236 + BranchItem *bi=model->getRootItem()->getFirstBranch();
1.237 + TreeItem *found=NULL;
1.238 + while (bi)
1.239 + {
1.240 + found=bi->findMapItem (p, exclude);
1.241 + if (found) return found;
1.242 + i++;
1.243 + bi=model->getRootItem()->getBranchNum(i);
1.244 + }
1.245 + return NULL;
1.246 +}
1.247 +
1.248 +AttributeTable* MapEditor::attributeTable()
1.249 +{
1.250 + return attrTable;
1.251 +}
1.252 +
1.253 +void MapEditor::testFunction1()
1.254 +{
1.255 + qDebug()<< "ME::test1 selected TI="<<model->getSelectedItem();
1.256 + model->setExportMode (true);
1.257 +
1.258 + /*
1.259 + // Code copied from Qt sources
1.260 + QRectF rect=model->getSelectedBranchObj()->getBBox();
1.261 + int xmargin=50;
1.262 + int ymargin=50;
1.263 +
1.264 + qreal width = viewport()->width();
1.265 + qreal height = viewport()->height();
1.266 + QRectF viewRect = matrix().mapRect(rect);
1.267 +
1.268 + qreal left = horizontalScrollBar()->value();
1.269 + qreal right = left + width;
1.270 + qreal top = verticalScrollBar()->value();
1.271 + qreal bottom = top + height;
1.272 +
1.273 + if (viewRect.left() <= left + xmargin) {
1.274 + // need to scroll from the left
1.275 + // if (!d->leftIndent)
1.276 + horizontalScrollBar()->setValue(int(viewRect.left() - xmargin - 0.5));
1.277 + }
1.278 + if (viewRect.right() >= right - xmargin) {
1.279 + // need to scroll from the right
1.280 +// if (!d->leftIndent)
1.281 + horizontalScrollBar()->setValue(int(viewRect.right() - width + xmargin + 0.5));
1.282 + }
1.283 + if (viewRect.top() <= top + ymargin) {
1.284 + // need to scroll from the top
1.285 + // if (!d->topIndent)
1.286 + verticalScrollBar()->setValue(int(viewRect.top() - ymargin - 0.5));
1.287 + }
1.288 + if (viewRect.bottom() >= bottom - ymargin) {
1.289 + // need to scroll from the bottom
1.290 +// if (!d->topIndent)
1.291 + verticalScrollBar()->setValue(int(viewRect.bottom() - height + ymargin + 0.5));
1.292 + }
1.293 + qDebug() << "test1: hor="<<horizontalScrollBar()->value();
1.294 + qDebug() << "test1: ver="<<verticalScrollBar()->value();
1.295 +}
1.296 +
1.297 +*/
1.298 +/*
1.299 + QtPropertyAnimation *animation=new QtPropertyAnimation(this, "sceneRect");
1.300 + animation->setDuration(5000);
1.301 + //animation->setEasingCurve ( QtEasingCurve::OutElastic);
1.302 + animation->setEasingCurve ( QtEasingCurve::OutQuint);
1.303 + animation->setStartValue(sceneRect() );
1.304 + animation->setEndValue(QRectF(50, 50, 1000, 1000));
1.305 +
1.306 + animation->start();
1.307 +*/
1.308 +/*
1.309 + QDialog *dia= new QDialog (this);
1.310 + dia->setGeometry (50,50,10,10);
1.311 +
1.312 + dia->show();
1.313 + dia ->raise();
1.314 +
1.315 + QtPropertyAnimation *animation=new QtPropertyAnimation(dia, "geometry");
1.316 + animation->setDuration(1000);
1.317 + //animation->setEasingCurve ( QtEasingCurve::OutElastic);
1.318 + animation->setEasingCurve ( QtEasingCurve::OutQuint);
1.319 + animation->setStartValue(QRect(50, 50, 10, 10));
1.320 + animation->setEndValue(QRect(250, 250, 100, 100));
1.321 +
1.322 + animation->start();
1.323 + */
1.324 +
1.325 +}
1.326 +
1.327 +void MapEditor::testFunction2()
1.328 +{
1.329 + autoLayout();
1.330 +}
1.331 +
1.332 BranchItem* MapEditor::getBranchDirectAbove (BranchItem *bi)
1.333 {
1.334 if (bi)
1.335 @@ -1021,11 +1025,11 @@
1.336
1.337 void MapEditor::mousePressEvent(QMouseEvent* e)
1.338 {
1.339 -//cout << "ME::mousePressed\n"; //FIXME-3
1.340 +//qDebug() << "ME::mousePressed\n"; //FIXME-3
1.341 // Ignore right clicks, these will go to context menus
1.342 if (e->button() == Qt::RightButton )
1.343 {
1.344 - //cout << " ME::ignoring right mouse event...\n";
1.345 + //qDebug() << " ME::ignoring right mouse event...\n";
1.346 e->ignore();
1.347 return;
1.348 }
1.349 @@ -1033,7 +1037,7 @@
1.350 //Ignore clicks while editing heading
1.351 if (model->isSelectionBlocked() )
1.352 {
1.353 - //cout << " ME::ignoring other mouse event...\n";
1.354 + //qDebug() << " ME::ignoring other mouse event...\n";
1.355 e->ignore();
1.356 return;
1.357 }
1.358 @@ -1136,9 +1140,9 @@
1.359 if (lmo)
1.360 {
1.361 /*
1.362 - cout << "ME::mouse pressed\n";
1.363 - cout << " lmo="<<lmo<<endl;
1.364 - cout << " ti="<<ti->getHeadingStd()<<endl;
1.365 + qDebug() << "ME::mouse pressed\n";
1.366 + qDebug() << " lmo="<<lmo;
1.367 + qDebug() << " ti="<<ti->getHeadingStd();
1.368 */
1.369 // Select the clicked object
1.370
1.371 @@ -1559,9 +1563,8 @@
1.372 {
1.373 if (debug)
1.374 {
1.375 - cout << "ME p="<<mapToScene (e->pos())<<" scrollBarPos="<<getScrollBarPos();
1.376 - cout << " min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
1.377 - cout << endl;
1.378 + qDebug()<< "ME p="<<mapToScene (e->pos())<<" scrollBarPos="<<getScrollBarPos() <<
1.379 + " min="<<QPointF(horizontalScrollBar()->minimum(),verticalScrollBar()->minimum());
1.380 }
1.381
1.382
1.383 @@ -1617,30 +1620,30 @@
1.384 if (debug)
1.385 {
1.386 foreach (QString format,event->mimeData()->formats())
1.387 - cout << "MapEditor: Dropped format: "<<qPrintable (format)<<endl;
1.388 + qDebug()<< "MapEditor: Dropped format: "<<qPrintable (format);
1.389 foreach (QString url,event->mimeData()->urls())
1.390 - cout << " URL:"<<url.toStdString()<<endl;
1.391 + qDebug()<< " URL:"<<url;
1.392 //foreach (QString plain,event->mimeData()->text())
1.393 - // cout << " PLAIN:"<<plain.toStdString()<<endl;
1.394 + // qDebug()<< " PLAIN:"<<plain;
1.395 QByteArray ba=event->mimeData()->data("STRING");
1.396
1.397 QString s;
1.398 s=ba;
1.399 - cout << " STRING:" <<s.toStdString()<<endl;
1.400 + qDebug() << " STRING:" <<s;
1.401
1.402 ba=event->mimeData()->data("TEXT");
1.403 s=ba;
1.404 - cout << " TEXT:" <<s.toStdString()<<endl;
1.405 + qDebug() << " TEXT:" <<s;
1.406
1.407 ba=event->mimeData()->data("COMPOUND_TEXT");
1.408 s=ba;
1.409 - cout << " CTEXT:" <<s.toStdString()<<endl;
1.410 + qDebug() << " CTEXT:" <<s;
1.411
1.412 ba=event->mimeData()->data("text/x-moz-url");
1.413 s=ba;
1.414 - cout << " x-moz-url:" <<s.toStdString()<<endl;
1.415 + qDebug() << " x-moz-url:" <<s;
1.416 foreach (char b,ba)
1.417 - if (b!=0) cout << "b="<<b<<endl;
1.418 + if (b!=0) qDebug() << "b="<<b;
1.419 }
1.420
1.421 if (event->mimeData()->hasImage())
1.422 @@ -1825,15 +1828,15 @@
1.423 TreeItem *ti= static_cast<TreeItem*>(sel.internalPointer());
1.424
1.425 /* testing
1.426 - cout << "ME::updateData\n";
1.427 + qDebug() << "ME::updateData\n";
1.428
1.429 - cout << " ti="<<ti<<endl;
1.430 - cout << " h="<<ti->getHeading().toStdString()<<endl;
1.431 + qDebug() << " ti="<<ti;
1.432 + qDebug() << " h="<<ti->getHeading();
1.433 */
1.434
1.435 if (ti->isBranchLikeType())
1.436 {
1.437 - // cout << " ->updating...\n";
1.438 + // qDebug() << " ->updating...\n";
1.439 BranchObj *bo=(BranchObj*) ( ((MapItem*)ti)->getLMO());
1.440 bo->updateData();
1.441 }