Subversion Repositories OpenInventory

Rev

Rev 198 | Rev 200 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#include "fileform.h"
#include "ui_fileform.h"
#include "mainwindow.h"

FileForm::FileForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FileForm)
{
    ui->setupUi(this);
}

FileForm::~FileForm()
{
    delete ui;
}

void FileForm::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}



void FileForm::on_pushButton_clicked(){          // îáðàáîò÷èê íàæàòèÿ êíîïêè "Îòêðûòü ôàéë"
    QString  fileName;
    QFile file;
    QByteArray data_tmp;

        fileName = QFileDialog::getOpenFileName(this,
         tr("Open Image"), "", tr("All Files (*.*);;Image Files (*.png *.jpg *.bmp);;Text files (*.txt);;XML files (*.xml)")); //Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)

    if (fileName.isEmpty()) return;
    file.setFileName(fileName);
    if (!file.open(QIODevice::ReadOnly)) return;
    Data.clear();
    // Data = file.readAll();
    QDataStream out(&Data,QIODevice::ReadWrite);
    out << fileName;
    data_tmp = file.readAll();
    out << data_tmp;
    file.close();


}

void FileForm::on_pushButton_2_clicked(){          // îáðàáîò÷èê íàæàòèÿ êíîïêè "Óäàëèòü ôàéë"
Data.clear();

}

void FileForm::on_pushButton_3_clicked(){          // îáðàáîò÷èê íàæàòèÿ êíîïêè "Ñîõðàíèòü ôàéë"

    QByteArray data_tmp;
    QFile file;
    QDataStream out(&Data,QIODevice::ReadOnly);
    QString fileName;
    out >> fileName;
    fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
                                                     fileName,
                                                     tr("All Files (*.*);;Image Files (*.png *.jpg *.bmp);;Text files (*.txt);;XML files (*.xml)"));


    int i;
    i++;
    if (fileName.isEmpty()) return;
    if (Data.isEmpty()) return;

        file.setFileName(fileName);
        if (!file.open(QIODevice::WriteOnly)) return;


    // Data = file.readAll();

  //  out.device()->reset();



    data_tmp.clear();
    out >> data_tmp;
    int count;
    count = file.write(data_tmp);
    int size;
    size = file.size();
    file.close();



}