diff --git a/src/lrreportdesignwidget.cpp b/src/lrreportdesignwidget.cpp index e41fcaa..9e29e31 100644 --- a/src/lrreportdesignwidget.cpp +++ b/src/lrreportdesignwidget.cpp @@ -291,10 +291,11 @@ bool ReportDesignWidget::save() } } -void ReportDesignWidget::loadFromFile(const QString &fileName) +bool ReportDesignWidget::loadFromFile(const QString &fileName) { - m_report->loadFromFile(fileName); + if (!m_report->loadFromFile(fileName)) return false; setActivePage(m_report->pageAt(0)); + return true; } void ReportDesignWidget::scale(qreal sx, qreal sy) diff --git a/src/lrreportdesignwidget.h b/src/lrreportdesignwidget.h index 5829d30..185b956 100644 --- a/src/lrreportdesignwidget.h +++ b/src/lrreportdesignwidget.h @@ -105,7 +105,7 @@ public: public slots: void saveToFile(const QString&); bool save(); - void loadFromFile(const QString&); + bool loadFromFile(const QString&); void deleteSelectedItems(); void setActivePage(PageDesignIntf* page); void undo(); diff --git a/src/lrreportdesignwindow.cpp b/src/lrreportdesignwindow.cpp index d35ba86..b90c5f9 100644 --- a/src/lrreportdesignwindow.cpp +++ b/src/lrreportdesignwindow.cpp @@ -541,14 +541,58 @@ void ReportDesignWindow::createRecentFilesMenu() { if (m_recentFilesMenu){ m_recentFilesMenu->clear(); + removeNotExistedRecentFiles(); foreach(QString fileName, m_recentFiles.keys()){ QAction* tmpAction = new QAction(QIcon(":/report/images/newReport"),fileName,this); connect(tmpAction,SIGNAL(triggered()), m_recentFilesSignalMap, SLOT(map())); m_recentFilesSignalMap->setMapping(tmpAction,fileName); m_recentFilesMenu->addAction(tmpAction); } + m_recentFilesMenu->setDisabled(m_recentFiles.isEmpty()); } - m_recentFilesMenu->setDisabled(m_recentFiles.isEmpty()); +} + +void ReportDesignWindow::removeNotExistedRecentFiles() +{ + QMap::iterator it = m_recentFiles.begin(); + while (it!=m_recentFiles.end()){ + if (!QFile::exists(it.key())){ + it = m_recentFiles.erase(it); + } else { + ++it; + } + } +} + +void ReportDesignWindow::removeNotExistedRecentFilesFromMenu(const QString &fileName) +{ + if (m_recentFilesMenu){ + foreach(QAction* action, m_recentFilesMenu->actions()){ + if (action->text().compare(fileName)==0){ + m_recentFilesMenu->removeAction(action); + break; + } + } + } +} + +void ReportDesignWindow::addRecentFile(const QString &fileName) +{ + if (!m_recentFiles.contains(fileName)){ + if (m_recentFiles.count()==10){ + QMap::const_iterator it = m_recentFiles.constBegin(); + QDateTime minDate = QDateTime::currentDateTime(); + while (it != m_recentFiles.constEnd()) { + if (minDate>it.value()) minDate = it.value(); + ++it; + } + m_recentFiles.remove(m_recentFiles.key(minDate)); + } + m_recentFiles.insert(fileName,QDateTime::currentDateTime()); + } else { + m_recentFiles[fileName] = QDateTime::currentDateTime(); + } + createRecentFilesMenu(); } void ReportDesignWindow::restoreSetting() @@ -802,6 +846,7 @@ void ReportDesignWindow::slotSaveReport() { m_reportDesignWidget->save(); m_lblReportName->setText(m_reportDesignWidget->reportFileName()); + if (!m_reportDesignWidget->reportFileName().isEmpty()) addRecentFile(m_reportDesignWidget->reportFileName()); } void ReportDesignWindow::slotSaveReportAs() @@ -810,6 +855,7 @@ void ReportDesignWindow::slotSaveReportAs() if (!fileName.isEmpty()){ m_reportDesignWidget->saveToFile(fileName); m_lblReportName->setText(m_reportDesignWidget->reportFileName()); + addRecentFile(fileName); } } @@ -832,21 +878,7 @@ void ReportDesignWindow::slotLoadReport() updateRedoUndo(); unsetCursor(); setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); - if (!m_recentFiles.contains(fileName)){ - if (m_recentFiles.count()==10){ - QMap::const_iterator it = m_recentFiles.constBegin(); - QDateTime minDate = QDateTime::currentDateTime(); - while (it != m_recentFiles.constEnd()) { - if (minDate>it.value()) minDate = it.value(); - ++it; - } - m_recentFiles.remove(m_recentFiles.key(minDate)); - } - m_recentFiles.insert(fileName,QDateTime::currentDateTime()); - } else { - m_recentFiles[fileName] = QDateTime::currentDateTime(); - } - createRecentFilesMenu(); + addRecentFile(fileName); } } @@ -1054,15 +1086,21 @@ void ReportDesignWindow::slotLoadRecentFile(const QString fileName) { if (checkNeedToSave()){ QApplication::processEvents(); - setCursor(Qt::WaitCursor); - m_reportDesignWidget->clear(); - m_reportDesignWidget->loadFromFile(fileName); - m_lblReportName->setText(fileName); - m_propertyModel->setObject(0); - updateRedoUndo(); - unsetCursor(); - setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); - m_recentFiles[fileName] = QDateTime::currentDateTime(); + if (QFile::exists(fileName)){ + setCursor(Qt::WaitCursor); + m_reportDesignWidget->clear(); + m_reportDesignWidget->loadFromFile(fileName); + m_lblReportName->setText(fileName); + m_propertyModel->setObject(0); + updateRedoUndo(); + unsetCursor(); + setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); + m_recentFiles[fileName] = QDateTime::currentDateTime(); + } else { + m_recentFiles.remove(fileName); + removeNotExistedRecentFilesFromMenu(fileName); + QMessageBox::information(this,tr("Warning"),tr("File \"%1\" not found!").arg(fileName)); + } } } diff --git a/src/lrreportdesignwindow.h b/src/lrreportdesignwindow.h index b04ba90..d70f4a9 100644 --- a/src/lrreportdesignwindow.h +++ b/src/lrreportdesignwindow.h @@ -135,7 +135,9 @@ private: void writePosition(); void writeState(); void createRecentFilesMenu(); - + void removeNotExistedRecentFiles(); + void removeNotExistedRecentFilesFromMenu(const QString& fileName); + void addRecentFile(const QString& fileName); private: static ReportDesignWindow* m_instance; QStatusBar* m_statusBar; diff --git a/src/lrreportengine.cpp b/src/lrreportengine.cpp index b9a9a00..1985b16 100644 --- a/src/lrreportengine.cpp +++ b/src/lrreportengine.cpp @@ -403,6 +403,8 @@ QSettings*ReportEnginePrivate::settings() bool ReportEnginePrivate::loadFromFile(const QString &fileName) { + if (!QFile::exists(fileName)) return false; + clearReport(); ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);