Subversion Repositories OpenInventory

Rev

Rev 197 | Rev 199 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
197 pingvin 1
#include "fileform.h"
2
#include "ui_fileform.h"
198 pingvin 3
#include "mainwindow.h"
197 pingvin 4
 
5
FileForm::FileForm(QWidget *parent) :
6
    QWidget(parent),
7
    ui(new Ui::FileForm)
8
{
9
    ui->setupUi(this);
10
}
11
 
12
FileForm::~FileForm()
13
{
14
    delete ui;
15
}
16
 
17
void FileForm::changeEvent(QEvent *e)
18
{
19
    QWidget::changeEvent(e);
20
    switch (e->type()) {
21
    case QEvent::LanguageChange:
22
        ui->retranslateUi(this);
23
        break;
24
    default:
25
        break;
26
    }
27
}
28
 
29
 
30
 
198 pingvin 31
void FileForm::on_pushButton_clicked(){          //    " "
32
    QString  fileName;
33
    QFile file;
34
    QByteArray data_tmp;
197 pingvin 35
 
198 pingvin 36
        fileName = QFileDialog::getOpenFileName(this,
37
         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)
197 pingvin 38
 
198 pingvin 39
    if (fileName.isEmpty()) return;
40
    file.setFileName(fileName);
41
    if (!file.open(QIODevice::ReadOnly)) return;
42
    Data.clear();
43
    // Data = file.readAll();
44
    QDataStream out(&Data,QIODevice::ReadWrite);
45
    out << fileName;
46
    data_tmp = file.readAll();
47
    out << data_tmp;
48
    file.close();
49
 
50
 
197 pingvin 51
}
52
 
198 pingvin 53
void FileForm::on_pushButton_2_clicked(){          //    " "
54
Data.clear();
197 pingvin 55
 
198 pingvin 56
}
197 pingvin 57
 
198 pingvin 58
void FileForm::on_pushButton_3_clicked(){          //    " "
59
 
60
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
61
                                                     "",
62
                                                     tr("All Files (*.*);;Image Files (*.png *.jpg *.bmp);;Text files (*.txt);;XML files (*.xml)"));
63
 
64
    QByteArray data_tmp;
65
    QFile file;
66
    int i;
67
    i++;
68
    if (fileName.isEmpty()) return;
69
    if (Data.isEmpty()) return;
70
 
71
        file.setFileName(fileName);
72
        if (!file.open(QIODevice::WriteOnly)) return;
73
 
74
 
75
    // Data = file.readAll();
76
    QDataStream out(&Data,QIODevice::ReadOnly);
77
  //  out.device()->reset();
78
    out >> fileName;
79
 
80
    file.setFileName(fileName);
81
    if (!file.open(QIODevice::ReadWrite)) return;
82
    data_tmp.clear();
83
    out >> data_tmp;
84
    int count;
85
    count = file.write(data_tmp);
86
 
87
    file.close();
88
 
89
 
90
 
197 pingvin 91
}