[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/calligra/2.9] krita/ui: Remove duplicated queryClose() methods
From:       Dmitry Kazakov <dimula73 () gmail ! com>
Date:       2015-01-28 10:00:59
Message-ID: E1YGPQh-0005nU-S0 () scm ! kde ! org
[Download RAW message or body]

Git commit beec34411aca1d139c09af34343f85cac6e45605 by Dmitry Kazakov.
Committed on 28/01/2015 at 09:59.
Pushed by dkazakov into branch 'calligra/2.9'.

Remove duplicated queryClose() methods

It resulted in the necessity to press Cancel button
multiple times when closing Krita window.

BUG:343070

M  +7    -85   krita/ui/KisDocument.cpp
M  +0    -3    krita/ui/KisDocument.h
M  +4    -48   krita/ui/KisMainWindow.cpp
M  +0    -5    krita/ui/KisMainWindow.h
M  +1    -2    krita/ui/KisView.h

http://commits.kde.org/calligra/beec34411aca1d139c09af34343f85cac6e45605

diff --git a/krita/ui/KisDocument.cpp b/krita/ui/KisDocument.cpp
index a5a8556..dbd98d1 100644
--- a/krita/ui/KisDocument.cpp
+++ b/krita/ui/KisDocument.cpp
@@ -1795,40 +1795,6 @@ void KisDocument::setModified(bool mod)
     emit modified(mod);
 }
 
-int KisDocument::queryCloseDia()
-{
-    //kDebug(30003);
-
-    QString name;
-    if (documentInfo()) {
-        name = documentInfo()->aboutInfo("title");
-    }
-    if (name.isEmpty())
-        name = url().fileName();
-
-    if (name.isEmpty())
-        name = i18n("Untitled");
-
-    int res = QMessageBox::warning(0,
-                                   i18nc("@title:window", "Krita"),
-                                   i18n("<p>The document <b>'%1'</b> has been \
                modified.</p><p>Do you want to save it?</p>", name),
-                                   QMessageBox::Yes | QMessageBox::No | \
                QMessageBox::Cancel, QMessageBox::Yes);
-
-    switch (res) {
-    case QMessageBox::Yes :
-        save(); // NOTE: External files always in native format. ###TODO: Handle \
                non-native format
-        setModified(false);   // Now when queryClose() is called by closeEvent it \
                won't do anything.
-        break;
-    case QMessageBox::No :
-        removeAutoSaveFiles();
-        setModified(false);   // Now when queryClose() is called by closeEvent it \
                won't do anything.
-        break;
-    default : // case QMessageBox::Cancel :
-        return res; // cancels the rest of the files
-    }
-    return res;
-}
-
 QString KisDocument::prettyPathOrUrl() const
 {
     QString _url( url().pathOrUrl() );
@@ -2275,8 +2241,13 @@ bool KisDocument::closeUrl(bool promptToSave)
 {
     if (promptToSave) {
         if ( d->document->isReadWrite() && d->document->isModified()) {
-            if (!queryClose())
-                return false;
+            foreach(KisView *view, KisPart::instance()->views()) {
+                if (view && view->document() == this) {
+                    if (!view->queryClose()) {
+                        return false;
+                    }
+                }
+            }
         }
     }
     // Not modified => ok and delete temp file.
@@ -2388,55 +2359,6 @@ void KisDocument::setLocalFilePath( const QString \
&localFilePath )  d->m_file = localFilePath;
 }
 
-bool KisDocument::queryClose()
-{
-    if ( !d->document->isReadWrite() || !d->document->isModified() )
-        return true;
-
-    QString docName = url().fileName();
-    if (docName.isEmpty()) docName = i18n( "Untitled" );
-
-
-    int res = QMessageBox::warning(0,
-                                   i18nc("@title:window", "Close Document"),
-                                   i18n("The document \"%1\" has been modified.\n"
-                                        "Do you want to save your changes or discard \
                them?" ,  docName),
-                                   QMessageBox::Yes | QMessageBox::No | \
                QMessageBox::Cancel, QMessageBox::Yes );
-
-    bool abortClose=false;
-    bool handled=false;
-
-    switch(res) {
-    case QMessageBox::Yes :
-        if (!handled)
-        {
-            if (d->m_url.isEmpty())
-            {
-                KisMainWindow *mainWindow = 0;
-                if (KisPart::instance()->mainWindows().count() > 0) {
-                    mainWindow = KisPart::instance()->mainWindows()[0];
-                }
-                KoFileDialog dialog(mainWindow, KoFileDialog::SaveFile, \
                "SaveDocument");
-                KUrl url = dialog.url();
-                if (url.isEmpty())
-                    return false;
-
-                saveAs( url );
-            }
-            else
-            {
-                save();
-            }
-        } else if (abortClose) return false;
-        return waitSaveComplete();
-    case QMessageBox::No :
-        return true;
-    default : // case QMessageBox::Cancel :
-        return false;
-    }
-}
-
-
 bool KisDocument::saveToUrl()
 {
     if ( d->m_url.isLocalFile() ) {
diff --git a/krita/ui/KisDocument.h b/krita/ui/KisDocument.h
index 4cb3b9d..094bbde 100644
--- a/krita/ui/KisDocument.h
+++ b/krita/ui/KisDocument.h
@@ -458,8 +458,6 @@ public:
      */
     bool isLoading() const;
 
-    int queryCloseDia();
-
     /**
      * Sets the backup path of the document
      */
@@ -824,7 +822,6 @@ private:
 
     QString prettyPathOrUrl() const;
 
-    bool queryClose();
     bool saveToUrl();
     bool openUrlInternal(const KUrl &url);
 
diff --git a/krita/ui/KisMainWindow.cpp b/krita/ui/KisMainWindow.cpp
index 289315d..fcdfc15 100644
--- a/krita/ui/KisMainWindow.cpp
+++ b/krita/ui/KisMainWindow.cpp
@@ -1006,7 +1006,10 @@ void KisMainWindow::closeEvent(QCloseEvent *e)
         e->setAccepted(false);
         return;
     }
-    if (queryClose()) {
+
+    QList<QMdiSubWindow*> childrenList = d->mdiArea->subWindowList();
+
+    if (childrenList.isEmpty()) {
         d->deferredClosingEvent = e;
 
         if (!d->dockerStateBeforeHiding.isEmpty()) {
@@ -1103,53 +1106,6 @@ void KisMainWindow::dropEvent(QDropEvent *event)
     }
 }
 
-bool KisMainWindow::queryClose()
-{
-    if (!d->activeView || d->activeView->document() == 0)
-        return true;
-
-    //kDebug(30003) <<"KisMainWindow::queryClose() viewcount=" << \
                d->activeView->document()->viewCount()
-    //               << " mainWindowCount=" << \
                d->activeView->document()->mainWindowCount() << endl;
-    if (KisPart::instance()->mainwindowCount() > 1)
-        // there are more open, and we are closing just one, so no problem for \
                closing
-        return true;
-
-    // main doc + internally stored child documents
-    if (d->activeView->document()->isModified()) {
-        QString name;
-        if (d->activeView->document()->documentInfo()) {
-            name = d->activeView->document()->documentInfo()->aboutInfo("title");
-        }
-        if (name.isEmpty())
-            name = d->activeView->document()->url().fileName();
-
-        if (name.isEmpty())
-            name = i18n("Untitled");
-
-        int res = QMessageBox::warning(this,
-                                       i18nc("@title:window", "Krita"),
-                                       i18n("<p>The document <b>'%1'</b> has been \
                modified.</p><p>Do you want to save it?</p>", name),
-                                       QMessageBox::Yes | QMessageBox::No | \
                QMessageBox::Cancel, QMessageBox::Yes);
-
-        switch (res) {
-        case QMessageBox::Yes : {
-            bool isNative = (d->activeView->document()->outputMimeType() == \
                d->activeView->document()->nativeFormatMimeType());
-            if (!saveDocument(d->activeView->document(), !isNative))
-                return false;
-            break;
-        }
-        case QMessageBox::No :
-            d->activeView->document()->removeAutoSaveFiles();
-            d->activeView->document()->setModified(false);   // Now when \
                queryClose() is called by closeEvent it won't do anything.
-            break;
-        default : // case QMessageBox::Cancel :
-            return false;
-        }
-    }
-
-    return true;
-}
-
 void KisMainWindow::slotFileNew()
 {
     KisPart::instance()->showStartUpWidget(this, true /*Always show widget*/);
diff --git a/krita/ui/KisMainWindow.h b/krita/ui/KisMainWindow.h
index 382a176..9cdcce5 100644
--- a/krita/ui/KisMainWindow.h
+++ b/krita/ui/KisMainWindow.h
@@ -378,11 +378,6 @@ private:
      */
     QDockWidget* createDockWidget(KoDockFactoryBase* factory);
 
-    /**
-     * Ask user about saving changes to the document upon exit.
-     */
-    bool queryClose();
-
     bool openDocumentInternal(const KUrl &url, KisDocument *newdoc = 0);
 
     /**
diff --git a/krita/ui/KisView.h b/krita/ui/KisView.h
index 76bac6b..32af2ed 100644
--- a/krita/ui/KisView.h
+++ b/krita/ui/KisView.h
@@ -218,6 +218,7 @@ public slots:
      */
     void slotClearStatusText();
 
+    bool queryClose();
 
 signals:
     // From KisImage
@@ -247,8 +248,6 @@ public slots:
 
 private:
 
-    bool queryClose();
-
     class Private;
     Private * const d;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic