Skip to content

Commit

Permalink
Modificando header
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark1024 committed Sep 17, 2013
1 parent 47ff860 commit 5cf30c2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 127 deletions.
2 changes: 0 additions & 2 deletions Proyecto_OA.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ SOURCES += main.cpp\
adtfile.cpp \
adtfilerecord.cpp \
field.cpp \
fileheader.cpp \
newfieldwindow.cpp \
modifyfieldwindow.cpp \
record.cpp \
Expand All @@ -28,7 +27,6 @@ HEADERS += mainwindow.h \
adtfile.h \
adtfilerecord.h \
field.h \
fileheader.h \
newfieldwindow.h \
modifyfieldwindow.h \
record.h \
Expand Down
2 changes: 1 addition & 1 deletion Proyecto_OA.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 2.7.2, 2013-09-16T14:10:37. -->
<!-- Written by QtCreator 2.7.2, 2013-09-17T08:07:29. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down
71 changes: 65 additions & 6 deletions adtfilerecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

ADTFileRecord::ADTFileRecord():ADTFile()
{
this->header = new FileHeader();
}

ADTFileRecord::ADTFileRecord(string Name,int recordLength):ADTFile()
{
this->fileName = Name;
this->recordLength = recordLength;

this->header = new FileHeader();
}

ADTFileRecord::~ADTFileRecord()
{
this->FS.flush();
this->FS.close();

delete header;
}

void ADTFileRecord::seekgRecord(int recordNumber)
Expand Down Expand Up @@ -112,7 +107,7 @@ void ADTFileRecord::readHeader(char* header)

Field* newField = new Field(name, Type, key, length, decimal);

this->header->addField(newField);
this->addField(newField);
}
}

Expand All @@ -125,3 +120,67 @@ int ADTFileRecord::getDataStart()
{
return this->dataStart;
}

void ADTFileRecord::addField(Field* field)
{
this->fields.push_back(field);
}

void ADTFileRecord::modifyField(int n, Field* field)
{
this->fields.at(n).setName(field->getName());
if(field->isKey()){
for(int i = 0; i < this->fields.size(); i++){
if(this->fields.at(i)->isKey()){
this->fields.at(i)->setKey(0);
i = this->fields.size();
}
}
this->fields.at(n)->setKey(1);
}
delete field;
}

void ADTFileRecord::removeField(int n)
{
this->fields.erase(this->fields.begin() + n);
}

string ADTFileRecord::toStringHeader() const
{
stringstream ss;
ss<<'$';
for(size_t i = 0; i < this->fields.size(); i++){
ss<<this->fields.at(i)->getName()<<','
<<this->fields.at(i)->getType()<<',';

if(this->fields.at(i)->isKey()){
ss<<'1';
}else{
ss<<'0';
}

ss<<this->fields.at(i)->getLength()<<','
<<this->fields.at(i)->getDecimalPlaces();

if(i < fields.size() -1){
ss<<'/';
}
}
ss<<'$';
}

vector<Field*> ADTFileRecord::getFields()
{
return this->fields;
}

int ADTFileRecord::fieldsSize()
{
return this->fields.size();
}

Field* ADTFileRecord::getField(int n)
{
return this->fields.at(n);
}
17 changes: 12 additions & 5 deletions adtfilerecord.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ADTFILERECORD_H
#define ADTFILERECORD_H

#include <vector>
#include <fstream>
#include <iostream>
#include <string>
Expand All @@ -27,20 +28,26 @@ class ADTFileRecord:public ADTFile
virtual bool updateRecord(int, string);
virtual bool deleteRecord(int);
//virtual void compact();
void setDataStart(int);
void setRecordLength(int);
void readHeader(char*);
FileHeader* getFileHeader();
virtual void setDataStart(int);
virtual void setRecordLength(int);
virtual void readHeader(char*);
virtual int getDataStart();
virtual void addField(Field*);
virtual void modifyField(int, Field*);
virtual void removeField(int);
virtual Field* getField(int);
virtual string toStringHeader() const;
virtual int fieldsSize() const;
vector<Field*> getFields();

private:
int recordLength;
int dataStart;

FileHeader* header;
string fileName;
fstream FS;
QStack<int> AvailList;
vector<Field*> fields;
};

#endif // ADTFILERECORD_H
72 changes: 0 additions & 72 deletions fileheader.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions fileheader.h

This file was deleted.

22 changes: 11 additions & 11 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void MainWindow::on_NewFile_triggered()
this->fileRecord.close();
}

while(this->fileRecord.getFileHeader()->fieldsSize() != 0){
this->fileRecord.getFileHeader()->removeField(0);
while(this->fileRecord.fieldsSize() != 0){
this->fileRecord.removeField(0);
}

QString directory = QFileDialog::getExistingDirectory(this,"New File","");
Expand Down Expand Up @@ -96,22 +96,22 @@ void MainWindow::on_createField_triggered()
Field* newField = createField->getField();

if(newField != NULL){
for(int i = 0; i < this->fileRecord.getFileHeader()->fieldsSize(); i++){
if(this->fileRecord.getFileHeader()->getField(i)->isKey()){
for(int i = 0; i < this->fileRecord.fieldsSize(); i++){
if(this->fileRecord.getField(i)->isKey()){
newField->setKey(0);
i = this->fileRecord.getFileHeader()->fieldsSize();
i = this->fileRecord.fieldsSize();
}
}

this->fileRecord.getFileHeader()->addField(newField);
this->fileRecord.addField(newField);
}else{
cout<<"Campo NULL"<<endl;
}

this->fileRecord.seekp(0,ios_base::beg);
this->fileRecord.seekg(0,ios_base::beg);

string header = this->fileRecord.getFileHeader()->toString();
string header = this->fileRecord.toStringHeader();
cout<<header<<endl;
this->fileRecord.setDataStart(header.size());

Expand All @@ -126,15 +126,15 @@ void MainWindow::on_modifyField_triggered()
if(this->fileRecord.isOpen()){
ModifyFieldWindow* modifyField = new ModifyFieldWindow();
cout<<"Marca1"<<endl;
modifyField->setFields(this->fileRecord.getFileHeader()->getFields());
modifyField->setFields(this->fileRecord.getFields());
modifyField->exec();

cout<<"Marca2"<<endl;
Field* newField = modifyField->getField();

if(newField != NULL){
int index = modifyField->getIndex();
this->fileRecord.getFileHeader()->modifyField(index, newField);
this->fileRecord.modifyField(index,newField);
}else{
cout<<"Campo NULL"<<endl;
}
Expand All @@ -154,7 +154,7 @@ void MainWindow::on_listField_triggered()
return;
}

if(this->fileRecord.getFileHeader()->fieldsSize() <= 0){
if(this->fileRecord.fieldsSize() <= 0){
QMessageBox::warning(this,"Error","El archivo abierto no contiene campos");
return;
}
Expand All @@ -168,7 +168,7 @@ void MainWindow::on_listField_triggered()
model->setHorizontalHeaderItem(4,new QStandardItem(QString("Decimales")));

QString tmp;
vector<Field*> fields = this->fileRecord.getFileHeader()->getFields();
vector<Field*> fields = this->fileRecord.getFields();
stringstream ss;

for(int i = 0; i < fields.size(); i++){
Expand Down
1 change: 0 additions & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define MAINWINDOW_H

#include "adtfilerecord.h"
#include "fileheader.h"
#include "field.h"
#include "newfieldwindow.h"
#include "modifyfieldwindow.h"
Expand Down

0 comments on commit 5cf30c2

Please sign in to comment.