0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +03:00

Loading and saving recent files have been fixed

This commit is contained in:
Arin Alexander 2016-03-19 13:33:49 +03:00
parent 1fcaa8121c
commit 355ae91fb1
5 changed files with 72 additions and 29 deletions

View File

@ -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)); setActivePage(m_report->pageAt(0));
return true;
} }
void ReportDesignWidget::scale(qreal sx, qreal sy) void ReportDesignWidget::scale(qreal sx, qreal sy)

View File

@ -105,7 +105,7 @@ public:
public slots: public slots:
void saveToFile(const QString&); void saveToFile(const QString&);
bool save(); bool save();
void loadFromFile(const QString&); bool loadFromFile(const QString&);
void deleteSelectedItems(); void deleteSelectedItems();
void setActivePage(PageDesignIntf* page); void setActivePage(PageDesignIntf* page);
void undo(); void undo();

View File

@ -541,14 +541,58 @@ void ReportDesignWindow::createRecentFilesMenu()
{ {
if (m_recentFilesMenu){ if (m_recentFilesMenu){
m_recentFilesMenu->clear(); m_recentFilesMenu->clear();
removeNotExistedRecentFiles();
foreach(QString fileName, m_recentFiles.keys()){ foreach(QString fileName, m_recentFiles.keys()){
QAction* tmpAction = new QAction(QIcon(":/report/images/newReport"),fileName,this); QAction* tmpAction = new QAction(QIcon(":/report/images/newReport"),fileName,this);
connect(tmpAction,SIGNAL(triggered()), m_recentFilesSignalMap, SLOT(map())); connect(tmpAction,SIGNAL(triggered()), m_recentFilesSignalMap, SLOT(map()));
m_recentFilesSignalMap->setMapping(tmpAction,fileName); m_recentFilesSignalMap->setMapping(tmpAction,fileName);
m_recentFilesMenu->addAction(tmpAction); m_recentFilesMenu->addAction(tmpAction);
} }
m_recentFilesMenu->setDisabled(m_recentFiles.isEmpty());
} }
m_recentFilesMenu->setDisabled(m_recentFiles.isEmpty()); }
void ReportDesignWindow::removeNotExistedRecentFiles()
{
QMap<QString,QDateTime>::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<QString, QDateTime>::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() void ReportDesignWindow::restoreSetting()
@ -802,6 +846,7 @@ void ReportDesignWindow::slotSaveReport()
{ {
m_reportDesignWidget->save(); m_reportDesignWidget->save();
m_lblReportName->setText(m_reportDesignWidget->reportFileName()); m_lblReportName->setText(m_reportDesignWidget->reportFileName());
if (!m_reportDesignWidget->reportFileName().isEmpty()) addRecentFile(m_reportDesignWidget->reportFileName());
} }
void ReportDesignWindow::slotSaveReportAs() void ReportDesignWindow::slotSaveReportAs()
@ -810,6 +855,7 @@ void ReportDesignWindow::slotSaveReportAs()
if (!fileName.isEmpty()){ if (!fileName.isEmpty()){
m_reportDesignWidget->saveToFile(fileName); m_reportDesignWidget->saveToFile(fileName);
m_lblReportName->setText(m_reportDesignWidget->reportFileName()); m_lblReportName->setText(m_reportDesignWidget->reportFileName());
addRecentFile(fileName);
} }
} }
@ -832,21 +878,7 @@ void ReportDesignWindow::slotLoadReport()
updateRedoUndo(); updateRedoUndo();
unsetCursor(); unsetCursor();
setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer");
if (!m_recentFiles.contains(fileName)){ addRecentFile(fileName);
if (m_recentFiles.count()==10){
QMap<QString, QDateTime>::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();
} }
} }
@ -1054,15 +1086,21 @@ void ReportDesignWindow::slotLoadRecentFile(const QString fileName)
{ {
if (checkNeedToSave()){ if (checkNeedToSave()){
QApplication::processEvents(); QApplication::processEvents();
setCursor(Qt::WaitCursor); if (QFile::exists(fileName)){
m_reportDesignWidget->clear(); setCursor(Qt::WaitCursor);
m_reportDesignWidget->loadFromFile(fileName); m_reportDesignWidget->clear();
m_lblReportName->setText(fileName); m_reportDesignWidget->loadFromFile(fileName);
m_propertyModel->setObject(0); m_lblReportName->setText(fileName);
updateRedoUndo(); m_propertyModel->setObject(0);
unsetCursor(); updateRedoUndo();
setWindowTitle(m_reportDesignWidget->report()->reportName() + " - Lime Report Designer"); unsetCursor();
m_recentFiles[fileName] = QDateTime::currentDateTime(); 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));
}
} }
} }

View File

@ -135,7 +135,9 @@ private:
void writePosition(); void writePosition();
void writeState(); void writeState();
void createRecentFilesMenu(); void createRecentFilesMenu();
void removeNotExistedRecentFiles();
void removeNotExistedRecentFilesFromMenu(const QString& fileName);
void addRecentFile(const QString& fileName);
private: private:
static ReportDesignWindow* m_instance; static ReportDesignWindow* m_instance;
QStatusBar* m_statusBar; QStatusBar* m_statusBar;

View File

@ -403,6 +403,8 @@ QSettings*ReportEnginePrivate::settings()
bool ReportEnginePrivate::loadFromFile(const QString &fileName) bool ReportEnginePrivate::loadFromFile(const QString &fileName)
{ {
if (!QFile::exists(fileName)) return false;
clearReport(); clearReport();
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);