MCPcopy Create free account
hub / github.com/KDE/labplot / save

Method save

src/frontend/MainWin.cpp:1764–1882  ·  view source on GitHub ↗

! * auxiliary function that does the actual saving of the project */

Source from the content-addressed store, hash-verified

1762 * auxiliary function that does the actual saving of the project
1763 */
1764bool MainWin::save(const QString& fileName) {
1765 DEBUG(Q_FUNC_INFO << ", file name = " << fileName.toStdString())
1766 QTemporaryFile tempFile(QDir::tempPath() + QLatin1Char('/') + QLatin1String("labplot_save_XXXXXX"));
1767 if (!tempFile.open()) {
1768 KMessageBox::error(this, i18n("Couldn't open the temporary file for writing."));
1769 return false;
1770 }
1771
1772 WAIT_CURSOR;
1773 const QString& tempFileName = tempFile.fileName();
1774 DEBUG("Using temporary file " << STDSTRING(tempFileName))
1775 tempFile.close();
1776
1777 QIODevice* file;
1778 // if file ending is .lml, do xz compression or gzip compression in compatibility mode
1779 const KConfigGroup group = Settings::group(QStringLiteral("Settings_General"));
1780 if (fileName.endsWith(QLatin1String(".lml"))) {
1781 if (group.readEntry("CompatibleSave", false))
1782 file = new KCompressionDevice(tempFileName, KCompressionDevice::GZip);
1783 else
1784 file = new KCompressionDevice(tempFileName, KCompressionDevice::Xz);
1785 } else // use file ending to find out how to compress file
1786 file = new KCompressionDevice(tempFileName);
1787 if (!file)
1788 file = new QFile(tempFileName);
1789
1790 bool ok;
1791 if (file->open(QIODevice::WriteOnly)) {
1792 m_project->setFileName(fileName);
1793
1794 // thumbnail, used for the project preview
1795 QPixmap thumbnail = centralWidget()->grab(centralWidget()->childrenRect());
1796
1797 // instead of doing a screenshot of the whole application window including also the special docks (project explorer, etc.) above,
1798 // we can also implement the following two cases:
1799 // 1. if the states of the dock widgets are saved in the project file, do the screenshot of the whole window
1800 // 2. if the states are not saved, determine the area of dock widgets without the special docks.
1801 // The logic below is an attempt to achieve this but it doesn't produce the desired results in all cases,
1802 // for example not if some of dock widgets are placed above the special docks.
1803 // TODO: decide what to do with this logic.
1804 /*
1805 if (m_project->saveDockStates())
1806 thumbnail = centralWidget()->grab(centralWidget()->childrenRect());
1807 else {
1808 // determine the bounding rectangle of the content (area without the special docks like project explorer, etc.)
1809 const auto& docks = m_dockManagerContent->dockWidgetsMap();
1810 QRect rect;
1811 for (auto* dock : docks) {
1812 auto dockRect = QRect(dock->mapToGlobal(dock->geometry().topLeft()), dock->geometry().size());
1813 rect = rect.united(dockRect);
1814 }
1815
1816 if (!rect.isEmpty())
1817 thumbnail = centralWidget()->grab(QRect(centralWidget()->mapFromGlobal(rect.topLeft()), rect.size()));
1818 }
1819 */
1820
1821 // set the state of the content dock widgets

Calls 15

groupFunction · 0.85
toStdStringMethod · 0.80
showMessageMethod · 0.80
currentWidgetMethod · 0.80
isActiveMethod · 0.80
openMethod · 0.45
fileNameMethod · 0.45
closeMethod · 0.45
setFileNameMethod · 0.45
saveStateMethod · 0.45
dataMethod · 0.45
setChangedMethod · 0.45