[vlmc-devel] [PATCH 2/2] ProjectWizard: Use itemSelectionChanged to set a project path

Yikai Lu luyikei.qmltu at gmail.com
Mon Apr 11 10:55:14 CEST 2016


Since we don't necessarily get a project path from a selected item, we have to implement a slot of itemSelectionChanged to set a project path.
---
 src/Gui/wizard/WelcomePage.cpp | 24 ++++++++++++++++++++----
 src/Gui/wizard/WelcomePage.h   |  1 +
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/Gui/wizard/WelcomePage.cpp b/src/Gui/wizard/WelcomePage.cpp
index 7767a55..a034394 100644
--- a/src/Gui/wizard/WelcomePage.cpp
+++ b/src/Gui/wizard/WelcomePage.cpp
@@ -50,6 +50,7 @@ WelcomePage::WelcomePage( QWidget* parent )
              this, SLOT( selectOpenRadio() ) );
     connect( m_ui.projectsListWidget, SIGNAL( itemDoubleClicked(QListWidgetItem*) ),
              this, SLOT( projectDoubleClicked(QListWidgetItem*) ) );
+    connect( m_ui.projectsListWidget, &QListWidget::itemSelectionChanged, this, &WelcomePage::itemSelectionChanged);
 
     registerField( "loadProject", m_ui.projectsListWidget );
     m_projectPath = new QString();
@@ -94,15 +95,13 @@ WelcomePage::validatePage()
 {
     if ( m_ui.openRadioButton->isChecked() )
     {
-        if ( m_ui.projectsListWidget->selectedItems().count() == 0 )
+        if ( m_projectPath->isEmpty() == true )
         {
             QMessageBox::information( this, tr( "Sorry" ),
                                       tr( "You first need to select a project from "
                                       "the list.\nThen click next to continue..." ) );
             return false;
         }
-        QList<QListWidgetItem*> selected = m_ui.projectsListWidget->selectedItems();
-        setProjectPath( selected.at( 0 )->data( FilePath ).toString() );
         return true;
     }
     return true;
@@ -146,9 +145,14 @@ WelcomePage::loadProject()
         return;
     }
 
+    selectOpenRadio();
 
+    m_ui.projectsListWidget->clearSelection();
+    m_ui.projectsListWidget->clearFocus();
 
-    selectOpenRadio();
+    setProjectPath( projectPath );
+    if ( wizard() )
+        wizard()->next();
 }
 
 void
@@ -174,6 +178,18 @@ WelcomePage::selectOpenRadio()
 }
 
 void
+WelcomePage::itemSelectionChanged()
+{
+    if ( m_ui.projectsListWidget->selectedItems().count() == 0 )
+        setProjectPath( "" );
+    else
+    {
+        QList<QListWidgetItem*> selected = m_ui.projectsListWidget->selectedItems();
+        setProjectPath( selected.at( 0 )->data( FilePath ).toString() );
+    }
+}
+
+void
 WelcomePage::projectDoubleClicked( QListWidgetItem* item )
 {
     Q_UNUSED( item );
diff --git a/src/Gui/wizard/WelcomePage.h b/src/Gui/wizard/WelcomePage.h
index 470b9c3..341edcf 100644
--- a/src/Gui/wizard/WelcomePage.h
+++ b/src/Gui/wizard/WelcomePage.h
@@ -54,6 +54,7 @@ class WelcomePage : public QWizardPage
         void loadRecentsProjects();
         void projectDoubleClicked( QListWidgetItem* item );
         void selectOpenRadio();
+        void itemSelectionChanged();
 
     private:
         Ui::WelcomePage m_ui;
-- 
1.9.1



More information about the Vlmc-devel mailing list