Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as C++ by user2828747 ( 11 years ago )
~~~~~~~storage.h~~~~~~~~~
class storage
{
public:
    storage();
    ~storage();
    void set_point(QPointF);
    QPointF getValue();

private:
    QPointF _p;
};

~~~~~~storage.cpp~~~~~~~~

#include "storage.h"

storage::storage(){}
storage::~storage(){}

void storage::set_point(QPointF p)
{_p = p;}

QPointF storage::getValue()
{return _p;}

~~~~~~~point.cpp~~~~~~~~~
#include "point.h"
#include "storage.h"
QVector<storage> point_vector;

point::point(){}

void point:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
           p1.setX(x1);
           p1.setY(y1);
          // paint code here      
    }

void point::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
    if(e->button()==Qt::LeftButton) {
            x1 = e->pos().x();
            y1 = e->pos().y();
            storage store_point;
            store_point.set_point(p1);
            point_vector.push_back(store_point);    
            update();
    }
}

~~~~~~~~~mainwindow.h~~~~~~~~~~

#include "storage.h"
#include "point.h"

class MainWindow : public QMainWindow, public Ui::MainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QVector<storage>::iterator it;

private:
    point *item;  

private slots:
    void drawPoint();
    void on_actionSave_triggered();
};

~~~~~~~~~mainwindow.cpp~~~~~~~~~~~~~
#include "mainwindow.h

void MainWindow::drawPoint(){
    item = new point;
    scene->addItem(item);
    qDebug() << "Point Created";
}

void MainWindow::on_actionSave_triggered()
{
    QString fname = QFileDialog::getSaveFileName();
    if (fname.isEmpty())
        return;

    QFile f(fname);
    f.open(QFile::WriteOnly);
    QTextStream ds(&f);

    for(it = item->point_vector.begin(); it != item->point_vector.end(); it++)
    {
        qDebug() << "size" << item->point_vector.size() << "\n";
    }
}

 

Revise this Paste

Your Name: Code Language: