1
|
diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp
|
2
|
index 33f2f20..4b87a88 100644
|
3
|
--- a/src/app/qgsbrowserdockwidget.cpp
|
4
|
+++ b/src/app/qgsbrowserdockwidget.cpp
|
5
|
@@ -287,9 +287,12 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
|
6
|
mBrowserView->expand( index );
|
7
|
}
|
8
|
|
9
|
- connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), mModel, SLOT( reload() ) );
|
10
|
- connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), mModel, SLOT( reload() ) );
|
11
|
- connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( reload() ) );
|
12
|
+ // connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), mModel, SLOT( reload() ) );
|
13
|
+ // connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), mModel, SLOT( reload() ) );
|
14
|
+ // connect( QgisApp::instance(), SIGNAL( newProject() ), mModel, SLOT( reload() ) );
|
15
|
+ connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ), this, SLOT( setProjectHome() ) );
|
16
|
+ connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), this, SLOT( setProjectHome() ) );
|
17
|
+ connect( QgisApp::instance(), SIGNAL( newProject() ), this, SLOT( setProjectHome() ) );
|
18
|
}
|
19
|
|
20
|
QDockWidget::showEvent( e );
|
21
|
@@ -425,7 +428,7 @@ void QgsBrowserDockWidget::refreshModel( const QModelIndex& index )
|
22
|
QgsDataItem *item = mModel->dataItem( index );
|
23
|
if ( item )
|
24
|
{
|
25
|
- QgsDebugMsg( "path = " + item->path() );
|
26
|
+ QgsDebugMsg( QString( "path %1 has %2 children" ).arg( item->path() ).arg( mModel->rowCount( index ) ) );
|
27
|
}
|
28
|
else
|
29
|
{
|
30
|
@@ -663,3 +666,9 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
|
31
|
return;
|
32
|
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
|
33
|
}
|
34
|
+
|
35
|
+void QgsBrowserDockWidget::setProjectHome()
|
36
|
+{
|
37
|
+ mModel->setProjectHome();
|
38
|
+ refresh();
|
39
|
+}
|
40
|
diff --git a/src/app/qgsbrowserdockwidget.h b/src/app/qgsbrowserdockwidget.h
|
41
|
index 2e7a87b..5ae8afb 100644
|
42
|
--- a/src/app/qgsbrowserdockwidget.h
|
43
|
+++ b/src/app/qgsbrowserdockwidget.h
|
44
|
@@ -67,6 +67,10 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge
|
45
|
QgsBrowserTreeView* mBrowserView;
|
46
|
QgsBrowserModel* mModel;
|
47
|
QgsBrowserTreeFilterProxyModel* mProxyModel;
|
48
|
+
|
49
|
+ protected slots:
|
50
|
+ void setProjectHome();
|
51
|
+
|
52
|
};
|
53
|
|
54
|
#endif // QGSBROWSERDOCKWIDGET_H
|
55
|
diff --git a/src/core/qgsbrowsermodel.cpp b/src/core/qgsbrowsermodel.cpp
|
56
|
index 334bc00..d33a827 100644
|
57
|
--- a/src/core/qgsbrowsermodel.cpp
|
58
|
+++ b/src/core/qgsbrowsermodel.cpp
|
59
|
@@ -43,13 +43,12 @@ void QgsBrowserModel::addRootItems()
|
60
|
{
|
61
|
QgsDirectoryItem *item;
|
62
|
|
63
|
+ // project home, default is current path (where application was started)
|
64
|
QString home = QgsProject::instance()->homePath();
|
65
|
-
|
66
|
- if ( !home.isNull() )
|
67
|
- {
|
68
|
- item = new QgsDirectoryItem( NULL, tr( "Project home" ), home );
|
69
|
- mRootItems << item;
|
70
|
- }
|
71
|
+ if ( home.isNull() )
|
72
|
+ home = QDir::currentPath();
|
73
|
+ item = new QgsDirectoryItem( NULL, tr( "Project home" ), home );
|
74
|
+ mRootItems << item;
|
75
|
|
76
|
// give the home directory a prominent second place
|
77
|
item = new QgsDirectoryItem( NULL, tr( "Home" ), QDir::homePath() );
|
78
|
@@ -261,11 +260,42 @@ QModelIndex QgsBrowserModel::findPath( QString path )
|
79
|
|
80
|
void QgsBrowserModel::reload()
|
81
|
{
|
82
|
+ QgsDebugMsg( "entered" );
|
83
|
removeRootItems();
|
84
|
addRootItems();
|
85
|
reset(); // Qt4.6 brings better methods beginResetModel + endResetModel
|
86
|
}
|
87
|
|
88
|
+void QgsBrowserModel::setProjectHome()
|
89
|
+{
|
90
|
+ // project home, default is current path (where application was started)
|
91
|
+ QString home = QgsProject::instance()->homePath();
|
92
|
+ if ( home.isNull() )
|
93
|
+ home = QDir::currentPath();
|
94
|
+
|
95
|
+ // search for project home item and replace it with new item
|
96
|
+ // if old home is same as new home, do nothing
|
97
|
+ // if not found something is broken because it should be created in addRootItems()
|
98
|
+ for( int i=0; i<mRootItems.count(); i++ )
|
99
|
+ {
|
100
|
+ QgsDataItem* item = mRootItems[i];
|
101
|
+ if ( item && item->name() == tr( "Project home" ) )
|
102
|
+ {
|
103
|
+ QgsDebugMsg( QString( "found project home item (%1), new home (%2)" ).arg( item->path() ).arg( home ) );
|
104
|
+ if ( item->path() != home )
|
105
|
+ {
|
106
|
+ delete item;
|
107
|
+ item = new QgsDirectoryItem( NULL, tr( "Project home" ), home );
|
108
|
+ mRootItems[i] = item;
|
109
|
+ item->refresh();
|
110
|
+ QgsDebugMsg( QString( "new project item has %1 children" ).arg( item->rowCount() ) );
|
111
|
+ }
|
112
|
+ break;
|
113
|
+ }
|
114
|
+ }
|
115
|
+
|
116
|
+}
|
117
|
+
|
118
|
/* Refresh dir path */
|
119
|
void QgsBrowserModel::refresh( QString path )
|
120
|
{
|
121
|
diff --git a/src/core/qgsbrowsermodel.h b/src/core/qgsbrowsermodel.h
|
122
|
index b0ef32f..e5807ef 100644
|
123
|
--- a/src/core/qgsbrowsermodel.h
|
124
|
+++ b/src/core/qgsbrowsermodel.h
|
125
|
@@ -92,6 +92,7 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
|
126
|
public slots:
|
127
|
// Reload the whole model
|
128
|
void reload();
|
129
|
+ void setProjectHome();
|
130
|
|
131
|
void beginInsertItems( QgsDataItem *parent, int first, int last );
|
132
|
void endInsertItems();
|