~ubuntu-branches/ubuntu/quantal/kdevplatform/quantal-proposed

« back to all changes in this revision

Viewing changes to project/projectitemlineedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-24 00:06:18 UTC
  • mfrom: (0.3.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101024000618-7otebin77mfcmt3b
Tags: 1.1.0-0ubuntu1
* New upstream release
  - Bump build-dependencies
  - Build against libboost-serialization1.42-dev
  - Update kdevplatform1-libs.install
  - Update kdevplatform-dev.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <interfaces/iproject.h>
31
31
#include <klocale.h>
32
32
#include <kaction.h>
 
33
#include <QMenu>
 
34
#include <KDialog>
 
35
#include <QTreeView>
 
36
#include "projectproxymodel.h"
 
37
#include <QBoxLayout>
 
38
#include <QLayout>
 
39
#include <QLabel>
 
40
#include <QHeaderView>
33
41
 
34
42
static const QChar sep = '/';
35
43
static const QChar escape = '\\';
81
89
QString ProjectItemCompleter::pathFromIndex(const QModelIndex& index) const
82
90
{
83
91
    QString postfix;
84
 
    if(mModel->item(index)->folder())
 
92
    if(mModel->itemFromIndex(index)->folder())
85
93
        postfix=sep;
86
94
    qDebug() << "path from index:" << index << removeProjectBasePath( mModel->pathFromIndex(index), mBase );
87
95
    return KDevelop::joinWithEscaping(removeProjectBasePath( mModel->pathFromIndex(index), mBase ), sep, escape)+postfix;
143
151
{
144
152
    setCompleter( m_completer );
145
153
    setValidator( m_validator );
146
 
    setClearButtonShown( true );
147
154
    setClickMessage( i18n("Enter the path to an item from the projects tree" ) );
148
 
}
149
 
 
 
155
    
 
156
    KAction* selectItemAction = new KAction(KIcon("folder-document"), i18n("Select..."), this);
 
157
    connect(selectItemAction, SIGNAL(triggered()), SLOT(selectItemDialog()));
 
158
    addAction(selectItemAction);
 
159
    
 
160
    setContextMenuPolicy(Qt::CustomContextMenu);
 
161
    connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showCtxMenu(QPoint)));
 
162
}
 
163
 
 
164
void ProjectItemLineEdit::showCtxMenu(const QPoint& p)
 
165
{
 
166
    QScopedPointer<QMenu> menu(createStandardContextMenu());
 
167
    menu->addActions(actions());
 
168
    menu->exec(mapToGlobal(p));
 
169
}
 
170
 
 
171
void ProjectItemLineEdit::selectItemDialog()
 
172
{
 
173
    KDevelop::ProjectModel* model=KDevelop::ICore::self()->projectController()->projectModel();
 
174
    
 
175
    QWidget* w=new QWidget;
 
176
    w->setLayout(new QVBoxLayout(w));
 
177
    QTreeView* view = new QTreeView(w);
 
178
    ProjectProxyModel* proxymodel = new ProjectProxyModel(view);
 
179
    proxymodel->setSourceModel(model);
 
180
    view->header()->hide();
 
181
    view->setModel(proxymodel);
 
182
    view->setSelectionMode(QAbstractItemView::SingleSelection);
 
183
    w->layout()->addWidget(new QLabel(i18n("Select the item you want to get the path from.")));
 
184
    w->layout()->addWidget(view);
 
185
    
 
186
    QScopedPointer<KDialog> dialog(new KDialog);
 
187
    dialog->setButtons(KDialog::Ok | KDialog::Cancel);
 
188
    dialog->setCaption(i18n("Select an item..."));
 
189
    dialog->setMainWidget(w);
 
190
    int res = dialog->exec();
 
191
    
 
192
    if(res==KDialog::Accepted && view->selectionModel()->hasSelection()) {
 
193
        QModelIndex idx=proxymodel->mapToSource(view->selectionModel()->selectedIndexes().first());
 
194
        
 
195
        setText(KDevelop::joinWithEscaping(model->pathFromIndex(idx), sep, escape));
 
196
        selectAll();
 
197
    }
 
198
}
150
199
 
151
200
void ProjectItemLineEdit::setItemPath(const QStringList& list)
152
201
{