mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Loading and saving recent files have been fixed
This commit is contained in:
parent
1fcaa8121c
commit
355ae91fb1
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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<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()
|
||||
@ -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<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();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user