Moved the creation of the data plan point to the model.

Moved the creation of the data plan point to the model,
this way when the user creates a data point on the
graphical planner, or when the user creates the point
on the QWidget based view, both of them will be updated.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-08-26 14:17:39 -03:00
parent 024dd80664
commit bc71f9a916
2 changed files with 56 additions and 27 deletions

View file

@ -142,9 +142,35 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
gasListView->hide(); gasListView->hide();
connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex))); connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex)));
connect(DivePlannerPointsModel::instance(), SIGNAL(rowsInserted(const QModelIndex&,int,int)),
this, SLOT(pointInserted(const QModelIndex&, int, int)));
setRenderHint(QPainter::Antialiasing); setRenderHint(QPainter::Antialiasing);
} }
void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end)
{
qDebug() << "Adicionou";
divedatapoint point = DivePlannerPointsModel::instance()->at(start);
DiveHandler *item = new DiveHandler ();
double xpos = timeLine->posAtValue(point.time);
double ypos = depthLine->posAtValue(point.depth);
item->sec = point.time * 60;
item->mm = point.depth * 1000;
item->setPos(QPointF(xpos, ypos));
qDebug() << xpos << ypos;
scene()->addItem(item);
handles << item;
Button *gasChooseBtn = new Button();
gasChooseBtn ->setText(tr("Air"));
scene()->addItem(gasChooseBtn);
gasChooseBtn->setZValue(10);
connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
gases << gasChooseBtn;
createDecoStops();
}
void DivePlannerGraphics::keyDownAction() void DivePlannerGraphics::keyDownAction()
{ {
if(scene()->selectedItems().count()){ if(scene()->selectedItems().count()){
@ -341,32 +367,31 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
int minutes = rint(timeLine->valueAt(mappedPos)); int minutes = rint(timeLine->valueAt(mappedPos));
int meters = rint(depthLine->valueAt(mappedPos)); int meters = rint(depthLine->valueAt(mappedPos));
double xpos = timeLine->posAtValue(minutes);
double ypos = depthLine->posAtValue(meters); // Q_FOREACH(DiveHandler* handler, handles){
Q_FOREACH(DiveHandler* handler, handles){ // if (xpos == handler->pos().x()){
if (xpos == handler->pos().x()){ // qDebug() << "There's already an point at that place.";
qDebug() << "There's already an point at that place."; // //TODO: Move this later to a KMessageWidget.
//TODO: Move this later to a KMessageWidget. // return;
return; // }
} // }
}
DivePlannerPointsModel::instance()->addStop(meters, minutes, tr("Air"), 0); DivePlannerPointsModel::instance()->addStop(meters, minutes, tr("Air"), 0);
DiveHandler *item = new DiveHandler (); // DiveHandler *item = new DiveHandler ();
item->sec = minutes * 60; // item->sec = minutes * 60;
item->mm = meters * 1000; // item->mm = meters * 1000;
item->setPos(QPointF(xpos, ypos)); // item->setPos(QPointF(xpos, ypos));
scene()->addItem(item); // scene()->addItem(item);
handles << item; // handles << item;
//
Button *gasChooseBtn = new Button(); // Button *gasChooseBtn = new Button();
gasChooseBtn ->setText(tr("Air")); // gasChooseBtn ->setText(tr("Air"));
scene()->addItem(gasChooseBtn); // scene()->addItem(gasChooseBtn);
gasChooseBtn->setZValue(10); // gasChooseBtn->setZValue(10);
connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas())); // connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
//
gases << gasChooseBtn; // gases << gasChooseBtn;
createDecoStops(); // createDecoStops();
} }
void DivePlannerGraphics::prepareSelectGas() void DivePlannerGraphics::prepareSelectGas()
@ -751,7 +776,7 @@ void Ruler::setColor(const QColor& color)
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem() Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
{ {
icon = new QGraphicsPixmapItem(this); icon = new QGraphicsPixmapItem(this);
text = new QGraphicsSimpleTextItem(this); text = new QGraphicsSimpleTextItem(this);
icon->setPos(0,0); icon->setPos(0,0);
text->setPos(0,0); text->setPos(0,0);
@ -939,3 +964,7 @@ int DivePlannerPointsModel::addStop(int meters, int minutes, const QString& gas,
return row; return row;
} }
divedatapoint DivePlannerPointsModel::at(int row)
{
return divepoints.at(row);
}

View file

@ -31,7 +31,7 @@ public:
* @return the row number. * @return the row number.
*/ */
int addStop(int meters, int minutes,const QString& gas, int ccpoint ); int addStop(int meters, int minutes,const QString& gas, int ccpoint );
divedatapoint at(int row);
public slots: public slots:
void setGFHigh(short gfhigh); void setGFHigh(short gfhigh);
void setGFLow(short ghflow); void setGFLow(short ghflow);
@ -131,7 +131,7 @@ private slots:
void cancelPlan(); void cancelPlan();
void prepareSelectGas(); void prepareSelectGas();
void selectGas(const QModelIndex& index); void selectGas(const QModelIndex& index);
void pointInserted(const QModelIndex&, int start, int end);
private: private:
void moveActiveHandler(const QPointF& pos); void moveActiveHandler(const QPointF& pos);