This patch aims to improve the "Stop Button" as current one just sets
current query to 0.

  - Smit Shah (My real name)
diff --git a/querymodel.cpp b/querymodel.cpp
index d78a865..6c7c82e 100644
--- a/querymodel.cpp
+++ b/querymodel.cpp
@@ -1,20 +1,4 @@
 /*
-   Copyright (c) 2010 Sebastian Trueg <[email protected]>
-   Copyright (c) 2011 Vishesh Handa <[email protected]>
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License or (at your option) version 3 or any later version
-   accepted by the membership of KDE e.V. (or its successor approved
-   by the membership of KDE e.V.), which shall act as a proxy
-   defined in Section 14 of version 3 of the license.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -37,13 +21,13 @@
 
 
 namespace {
-void splitUri( const QUrl& uri, QUrl& ns, QString& name )
-{
-    const QString uriStr = uri.toString();
-    const int i = uriStr.lastIndexOf( QRegExp(QLatin1String("[/#]")) ) + 1;
-    ns = uriStr.left( i );
-    name = uriStr.mid( i );
-}
+    void splitUri( const QUrl& uri, QUrl& ns, QString& name )
+    {
+        const QString uriStr = uri.toString();
+        const int i = uriStr.lastIndexOf( QRegExp(QLatin1String("[/#]")) ) + 1;
+        ns = uriStr.left( i );
+        name = uriStr.mid( i );
+    }
 }
 
 class Nepomuk::QueryModel::Private
@@ -108,13 +92,13 @@ QString Nepomuk::QueryModel::Private::resourceToString(const QUrl &uri) const
 
 Nepomuk::QueryModel::QueryModel( QObject* parent )
     : QAbstractTableModel( parent ),
-      d(new Private( this ))
+    d(new Private( this ))
 {
     Soprano::NRLModel nrlModel( ResourceManager::instance()->mainModel() );
     nrlModel.setEnableQueryPrefixExpansion( true );
     QHash<QString, QUrl> queryPrefixes = nrlModel.queryPrefixes();
     for( QHash<QString, QUrl>::const_iterator it = queryPrefixes.constBegin();
-         it != queryPrefixes.constEnd(); ++it ) {
+    it != queryPrefixes.constEnd(); ++it ) {
         d->m_bnames.insert( it.value(), it.key() );
     }
 }
@@ -150,18 +134,18 @@ QVariant Nepomuk::QueryModel::data( const QModelIndex& index, int role ) const
     if( index.isValid() &&
         index.row() < d->m_bindings.count() ) {
         const Soprano::Node node = d->m_bindings[index.row()][index.column()];
-            switch( role ) {
-            case Qt::DisplayRole:
-                if( node.isResource() ) {
-                    return d->resourceToString(node.uri());
-                }
-                else {
-                    return node.toString();
-                }
-
-            case Qt::ToolTipRole:
+        switch( role ) {
+        case Qt::DisplayRole:
+            if( node.isResource() ) {
+                return d->resourceToString(node.uri());
+            }
+            else {
                 return node.toString();
             }
+
+            case Qt::ToolTipRole:
+            return node.toString();
+        }
     }
 
     return QVariant();
@@ -213,13 +197,9 @@ Soprano::Node Nepomuk::QueryModel::nodeForIndex( const QModelIndex& index ) cons
 
 void Nepomuk::QueryModel::slotNextResultReady(Soprano::Util::AsyncQuery* query)
 {
-    if( query != d->m_currentQuery ) {
-        query->close();
-        return;
-    }
-    
+
     beginInsertRows( QModelIndex(), d->m_bindings.size(), d->m_bindings.size() );
-    
+
     if( query->isBool() ) {
         Soprano::BindingSet set;
         set.insert( QLatin1String( "result" ), Soprano::LiteralValue( query->boolValue() ) );
@@ -227,7 +207,7 @@ void Nepomuk::QueryModel::slotNextResultReady(Soprano::Util::AsyncQuery* query)
     }
     else if ( query->isGraph() ) {
         query->next();
-        
+
         const Soprano::Statement s = query->currentStatement();
         Soprano::BindingSet set;
         set.insert( QLatin1String( "subject" ), s.subject() );
@@ -240,9 +220,9 @@ void Nepomuk::QueryModel::slotNextResultReady(Soprano::Util::AsyncQuery* query)
         query->next();
         d->m_bindings << query->currentBindings();
     }
-    
+
     endInsertRows();
-    
+
     // This is called because columnCount would return 0 initially
     if( d->m_bindings.size() == 1 ) {
         emit layoutAboutToBeChanged();
@@ -258,7 +238,7 @@ void Nepomuk::QueryModel::slotQueryFinished(Soprano::Util::AsyncQuery* query)
     kDebug() << query->lastError().message();
     if( query->lastError() != Soprano::Error::ErrorNone )
         emit queryError( query->lastError() );
-    
+
     d->m_queryTime = d->m_queryTimer.elapsed();
     emit queryFinished();
 }
@@ -270,9 +250,19 @@ int Nepomuk::QueryModel::queryTime() const
 
 void Nepomuk::QueryModel::stopQuery()
 {
-    d->m_currentQuery = 0;
+    if(d->m_currentQuery)
+    {
+        d->m_currentQuery->close();
+        d->m_currentQuery->disconnect(this);
+        d->m_queryTime = d->m_queryTimer.elapsed();
+        emit queryFinished();
+    }
 }
 
 
-
 #include "querymodel.moc"
+
+
+
+
+
diff --git a/querymodel.h b/querymodel.h
index 698dfee..ab37aa0 100644
--- a/querymodel.h
+++ b/querymodel.h
@@ -55,7 +55,7 @@ namespace Nepomuk {
     public Q_SLOTS:
         void setQuery( const QString& query );
         void stopQuery();
-
+        
     private Q_SLOTS:
         void slotNextResultReady( Soprano::Util::AsyncQuery* query );
         void slotQueryFinished( Soprano::Util::AsyncQuery* );
diff --git a/resourcequerywidget.cpp b/resourcequerywidget.cpp
index 79876eb..b34932d 100644
--- a/resourcequerywidget.cpp
+++ b/resourcequerywidget.cpp
@@ -1,19 +1,4 @@
 /*
-   Copyright (c) 2010 Sebastian Trueg <[email protected]>
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License or (at your option) version 3 or any later version
-   accepted by the membership of KDE e.V. (or its successor approved
-   by the membership of KDE e.V.), which shall act as a proxy
-   defined in Section 14 of version 3 of the license.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -38,7 +23,7 @@
 
 ResourceQueryWidget::ResourceQueryWidget( QWidget* parent )
     : QWidget( parent ),
-      m_queryHistoryIndex( 0 )
+    m_queryHistoryIndex( 0 )
 {
     setupUi( this );
 
@@ -68,6 +53,7 @@ ResourceQueryWidget::ResourceQueryWidget( QWidget* parent )
     connect( m_shorten, SIGNAL(clicked()),this,SLOT(slotQueryShortenButtonClicked()));
     m_buttonForward->setEnabled( false );
     m_buttonBack->setEnabled( false );
+    m_stopQueryButton->setEnabled(false);
 
     // the empty string representing the current query
     m_queryHistory << QString();
@@ -78,7 +64,6 @@ ResourceQueryWidget::~ResourceQueryWidget()
 {
 }
 
-
 QStringList ResourceQueryWidget::queryHistory() const
 {
     // do not return the non-executed query, ie. the last element in the list
@@ -117,6 +102,7 @@ void ResourceQueryWidget::slotQueryButtonClicked()
         m_queryHistory.insert(m_queryHistory.count()-1, m_queryEdit->toPlainText() );
     }
     m_queryModel->setQuery( query );
+    m_stopQueryButton->setEnabled(true);
     updateHistoryButtonStates();
 }
 
@@ -188,11 +174,15 @@ void ResourceQueryWidget::slotQueryError(const Soprano::Error::Error& error)
 void ResourceQueryWidget::slotQueryFinished()
 {
     m_statusLabel->setText( i18n("Elapsed: %1", KGlobal::locale()->formatDuration(m_queryModel->queryTime())) );
+    m_stopQueryButton->setEnabled(false);
+
 }
 
 void ResourceQueryWidget::slotQueryStopButtonClicked()
 {
     m_queryModel->stopQuery();
+    m_stopQueryButton->setEnabled(false);
+
 }
 
 void ResourceQueryWidget::slotQueryShortenButtonClicked()
diff --git a/resourcequerywidget.h b/resourcequerywidget.h
index a91e41b..22224fc 100644
--- a/resourcequerywidget.h
+++ b/resourcequerywidget.h
@@ -64,6 +64,7 @@ private Q_SLOTS:
     void slotQueryError( const Soprano::Error::Error & error );
     void slotQueryFinished();
     void slotQueryShortenButtonClicked();
+
 private:
     void updateHistoryButtonStates();
 
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to