~oluseyi-deactivatedaccount/pencil/trunk

« back to all changes in this revision

Viewing changes to src/structure/object.cpp

  • Committer: volute
  • Date: 2007-10-16 02:39:34 UTC
  • Revision ID: svn-v4:f509e8e7-a431-0410-8952-ba4f3f4fc37f:trunk:40
1) A test is done before opening a file (doesn't crash any more if it is not a Pencil document)
2) Vector graphics files (.vec) can be imported at specific frames
3) main.cpp was restored after wrong modification in the last revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        if( fileInfo.isDir() ) return false;
51
51
        
52
52
        QFile* file = new QFile(filePath);
53
 
        if (!file->open(QFile::ReadOnly)) {
54
 
                //QMessageBox::warning(this, "Warning", "Cannot read file");
55
 
                return false;
56
 
        }
 
53
        if (!file->open(QFile::ReadOnly)) return false;
57
54
        
58
 
        QDomDocument doc("MyObject");
 
55
        QDomDocument doc;
59
56
        doc.setContent(file);
60
57
        
61
58
        int layerNumber = -1;
62
59
        QDomElement docElem = doc.documentElement();
 
60
        if(docElem.isNull()) return false;
63
61
        QDomNode tag = docElem.firstChild();
 
62
        bool someRelevantData = false;
64
63
        while(!tag.isNull()) {
65
64
                QDomElement element = tag.toElement(); // try to convert the node to an element.
66
65
                if(!element.isNull()) {
67
66
                        if(element.tagName() == "layer") {
 
67
                                someRelevantData = true;
68
68
                                // --- bitmap layer ---
69
69
                                if(element.attribute("type").toInt() == Layer::BITMAP) {
70
70
                                        addNewBitmapLayer();
94
94
                }
95
95
                tag = tag.nextSibling();
96
96
        }
97
 
    return true;
 
97
        return someRelevantData;
98
98
        
99
99
        
100
100
        /*
114
114
        }
115
115
        QTextStream out(file);
116
116
        
117
 
        QDomDocument doc("MyObject");
118
 
        QDomElement root = doc.createElement("MyOject");
 
117
        QDomDocument doc("PencilDocument");
 
118
        QDomElement root = doc.createElement("object");
119
119
        doc.appendChild(root);
120
120
        
121
121
        for(int i=0; i < getLayerCount(); i++) {
262
262
        }
263
263
        QTextStream out(file);
264
264
        
265
 
        QDomDocument doc("MyPalette");
266
 
        QDomElement root = doc.createElement("MyPalette");
 
265
        QDomDocument doc("PencilPalette");
 
266
        QDomElement root = doc.createElement("palette");
267
267
        doc.appendChild(root);
268
268
        for(int i=0; i < myPalette.size(); i++) {
269
269
                QDomElement tag = doc.createElement("Colour");
293
293
                return false;
294
294
        }
295
295
        
296
 
        QDomDocument doc("MyPalette");
 
296
        QDomDocument doc;
297
297
        doc.setContent(file);
298
298
        
299
299
        myPalette.clear();