[vlmc-devel] [PATCH] ProjectWizard: Don't fake RecentProjects when a project is supposed to be opend

Yikai Lu luyikei.qmltu at gmail.com
Sun Apr 10 17:18:14 CEST 2016


---
 src/Gui/wizard/WelcomePage.cpp | 45 +++++++++++++++++++-----------------------
 src/Gui/wizard/WelcomePage.h   |  1 +
 2 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/src/Gui/wizard/WelcomePage.cpp b/src/Gui/wizard/WelcomePage.cpp
index 6e44cb8..dfe9fea 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;
@@ -132,6 +131,7 @@ WelcomePage::loadRecentsProjects()
 void
 WelcomePage::loadProject()
 {
+    m_ui.openRadioButton->setChecked( true );
     QString projectPath =
             QFileDialog::getOpenFileName( nullptr, tr( "Select a project file" ),
                                           VLMC_GET_STRING( "vlmc/WorkspaceLocation" ),
@@ -145,29 +145,12 @@ WelcomePage::loadProject()
                              tr("Please use an existing project file."));
         return;
     }
+    m_ui.projectsListWidget->clearSelection();
+    m_ui.projectsListWidget->clearFocus();
 
-    // Search if the item is already in the list
-    QListWidgetItem* item = nullptr;
-    for ( int i = 0; i < m_ui.projectsListWidget->count(); ++i )
-    {
-        item = m_ui.projectsListWidget->item( i );
-        if ( item->data( FilePath ).toString().contains( projectPath ) )
-            break;
-        item = nullptr;
-    }
-
-    // Item not in list, insert it temporarily
-    if ( !item )
-    {
-        QFileInfo fi( projectPath );
-        item = new QListWidgetItem( fi.fileName() );
-        item->setData( FilePath, fi.absoluteFilePath() );
-
-        m_ui.projectsListWidget->addItem( item );
-    }
-
-    item->setSelected( true );
-    selectOpenRadio();
+    setProjectPath( projectPath );
+    if ( wizard() )
+        wizard()->next();
 }
 
 void
@@ -193,6 +176,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