-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.cpp | 38 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/mainwindow.h | 5 |
2 files changed, 20 insertions, 23 deletions
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index efbcc20..09ee68b 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp @@ -52,8 +52,9 @@ MainWindow::MainWindow() // initialize variables documentModified=FALSE; // construct objects + currentDoc=0; fileSelector=new FileSelector("application/sheet-qt", this, QString::null); connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); @@ -70,16 +71,17 @@ MainWindow::MainWindow() // set window title setCaption(tr("Opie Sheet")); // create sheets - selectorFileNew(currentDoc); + selectorFileNew(DocLnk()); } MainWindow::~MainWindow() { + if (currentDoc) delete currentDoc; } -void MainWindow::documentSave(DocLnk &lnkDoc) +void MainWindow::documentSave(DocLnk *lnkDoc) { FileManager fm; QByteArray streamBuffer; QDataStream stream(streamBuffer, IO_WriteOnly); @@ -99,10 +101,10 @@ void MainWindow::documentSave(DocLnk &lnkDoc) for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; } - lnkDoc.setType("application/sheet-qt"); - if (!fm.saveFile(lnkDoc, streamBuffer)) + lnkDoc->setType("application/sheet-qt"); + if (!fm.saveFile(*lnkDoc, streamBuffer)) { QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); return; } @@ -171,36 +173,29 @@ int MainWindow::saveCurrentFile(bool ask=TRUE) int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); if (result!=QMessageBox::Yes) return result; } - if (currentDoc.name().isEmpty() || !currentDoc.isValid()) + if (!currentDoc->isValid()) { TextDialog dialogText(this); if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; - currentDoc.setName(dialogText.getValue()); + currentDoc->setName(dialogText.getValue()); + currentDoc->setFile(QString::null); + currentDoc->setLinkFile(QString::null); } documentSave(currentDoc); return QMessageBox::Yes; } -void MainWindow::copyDocLnk(const DocLnk &source, DocLnk &target) -{ - target.setName(source.name()); - target.setFile(source.file()); - target.setLinkFile(source.linkFile()); - target.setComment(source.comment()); - target.setType(source.type()); - target.setCategories(source.categories()); -} - void MainWindow::selectorFileNew(const DocLnk &lnkDoc) { selectorHide(); if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; - copyDocLnk(lnkDoc, currentDoc); + if (currentDoc) delete currentDoc; + currentDoc = new DocLnk(lnkDoc); listSheets.clear(); comboSheets->clear(); typeSheet *newSheet=createNewSheet(); @@ -222,9 +217,10 @@ void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) { selectorHide(); if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; - copyDocLnk(lnkDoc, currentDoc); + if (currentDoc) delete currentDoc; + currentDoc = new DocLnk(lnkDoc); listSheets.clear(); comboSheets->clear(); documentOpen(lnkDoc); @@ -753,11 +749,13 @@ void MainWindow::slotColumnHide() void MainWindow::slotFileSaveAs() { TextDialog dialogText(this); - if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc.name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; + if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; - currentDoc.setName(dialogText.getValue()); + currentDoc->setName(dialogText.getValue()); + currentDoc->setFile(QString::null); + currentDoc->setLinkFile(QString::null); documentSave(currentDoc); } void MainWindow::slotSheetRename() diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h index 554e6f6..d68e25c 100644 --- a/noncore/apps/opie-sheet/mainwindow.h +++ b/noncore/apps/opie-sheet/mainwindow.h @@ -38,9 +38,9 @@ class MainWindow: public QMainWindow { Q_OBJECT // QPE objects - DocLnk currentDoc; + DocLnk* currentDoc; QPEMenuBar *menu; QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; FileSelector *fileSelector; @@ -75,10 +75,9 @@ class MainWindow: public QMainWindow void initSheet(); void addToData(const QString &data); int saveCurrentFile(bool ask=TRUE); void documentOpen(const DocLnk &lnkDoc); - void copyDocLnk(const DocLnk &source, DocLnk &target); - void documentSave(DocLnk &lnkDoc); + void documentSave(DocLnk *lnkDoc); void closeEvent(QCloseEvent *e); void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); typeSheet *createNewSheet(); typeSheet *findSheet(const QString &name); |