aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/analyzerbase/analyzeroutputpane.cpp
blob: f1233360ede8e89e0dcb10e93d138f0da8e8c365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#include "analyzeroutputpane.h"
#include "analyzermanager.h"
#include "ianalyzertool.h"

#include <utils/qtcassert.h>
#include <utils/styledbar.h>

#include <QtCore/QVariant>
#include <QtCore/QDebug>

#include <QtGui/QWidget>
#include <QtGui/QStackedLayout>
#include <QtGui/QLabel>
#include <QtGui/QStackedWidget>

static const char dummyWidgetPropertyC[] = "dummyWidget";

enum { debug = 0 };
enum { dummyIndex = 0 };

namespace Analyzer {
namespace Internal {

static inline QWidget *createDummyWidget()
{
    QWidget *widget = new QWidget;
    widget->setProperty(dummyWidgetPropertyC, QVariant(true));
    return widget;
}

/*!
  \class AnalyzerPane::Internal::AnalyzerOutputPane

  \brief Common analysis output pane managing several tools.

  Output pane for all tools derived from IAnalyzerTool.
  The IAnalyzerOutputPaneAdapter (unless 0) provides
  \list
  \i Pane widget
  \i Optional toolbar widget
  \endlist

  Both are inserted into a pane stacked layout and a stacked toolbar widget respectively.

  The indexes of the stacked widgets/layouts and the adapter list go in sync
  (dummy widgets on the toolbar are used to achieve this).
  Dummy widgets that are shown  in case there is no tool with an output pane
  are added at index 0 to the stacks (usage of index 0 is to avoid using
  QStackedWidget::insert() when adding adapters, which causes flicker).

  Besides the tool-specific toolbar widget, the start/stop buttons and the combo
  box of the AnalyzerManager are shown in the toolbar.

  The initialization is a bit tricky here, as the sequence of calls to
  setTool(), outputWindow()/toolBarWidgets() is basically undefined. The pane widget
  should be created on the correct parent when outputWindow()
  is called, tools will typically be added before.

  \sa AnalyzerPane::Internal::IAnalyzerOutputPaneAdapter
*/

AnalyzerOutputPane::AnalyzerOutputPane(QObject *parent) :
    Core::IOutputPane(parent),
    m_paneWidget(0),
    m_paneStackedLayout(0),
    m_toolbarStackedWidget(0),
    m_toolBarSeparator(0)
{
    setObjectName(QLatin1String("AnalyzerOutputPane"));
}

void AnalyzerOutputPane::clearTool()
{
    // No tool. Show dummy label, which is the last widget.
    if (m_paneWidget) {
        m_paneStackedLayout->setCurrentIndex(dummyIndex);
        m_toolbarStackedWidget->setCurrentIndex(dummyIndex);
        emit navigateStateChanged();
    }
    hide();
}

int AnalyzerOutputPane::currentIndex() const
{
    return m_paneStackedLayout ? m_paneStackedLayout->currentIndex() : -1;
}

IAnalyzerOutputPaneAdapter *AnalyzerOutputPane::currentAdapter() const
{
    const int index = currentIndex(); // Rule out leading dummy widget
    if (index != dummyIndex && index < m_adapters.size())
        return m_adapters.at(index);
    return 0;
}

void AnalyzerOutputPane::setCurrentIndex(int i)
{
    QTC_ASSERT(isInitialized(), return )

    if (i != currentIndex()) {
        // Show up pane widget and optional toolbar widget. Hide
        // the toolbar if the toolbar widget is a dummy.
        m_paneStackedLayout->setCurrentIndex(i);
        m_toolbarStackedWidget->setCurrentIndex(i);
        const bool hasToolBarWidget = !m_toolbarStackedWidget->currentWidget()->property(dummyWidgetPropertyC).toBool();
        m_toolbarStackedWidget->setVisible(hasToolBarWidget);
        m_toolBarSeparator->setVisible(hasToolBarWidget);
        navigateStateChanged();
    }
}

void AnalyzerOutputPane::add(IAnalyzerOutputPaneAdapter *adapter)
{
    if (m_adapters.isEmpty())
        m_adapters.push_back(0); // Index for leading dummy widgets.
    m_adapters.push_back(adapter);
    connect(adapter, SIGNAL(navigationStatusChanged()), this, SLOT(slotNavigationStatusChanged()));
    connect(adapter, SIGNAL(popup(bool)), this, SLOT(slotPopup(bool)));
    if (isInitialized())
        addToWidgets(adapter);
}

void AnalyzerOutputPane::addToWidgets(IAnalyzerOutputPaneAdapter *adapter)
{
    QTC_ASSERT(m_paneWidget, return; )
    QWidget *toolPaneWidget =  adapter->paneWidget();
    QTC_ASSERT(toolPaneWidget, return; )
    m_paneStackedLayout->addWidget(toolPaneWidget);
    QWidget *toolBarWidget = adapter->toolBarWidget(); // Might be 0
    m_toolbarStackedWidget->addWidget(toolBarWidget ? toolBarWidget : createDummyWidget());
}

void AnalyzerOutputPane::setTool(IAnalyzerTool *t)
{
    if (debug)
        qDebug() << "AnalyzerOutputPane::setTool" << t;
    // No tool. show dummy label.
    IAnalyzerOutputPaneAdapter *adapter = t ? t->outputPaneAdapter() :
                                              static_cast<IAnalyzerOutputPaneAdapter *>(0);
    // Re-show or add.
    if (adapter) {
        int index = m_adapters.indexOf(adapter);
        if (index == -1) {
            index = m_adapters.size();
            add(adapter);
        }
        if (isInitialized()) {
            popup(false);
            setCurrentIndex(index);
        }
    } else {
        clearTool();
    }
}

QWidget * AnalyzerOutputPane::outputWidget(QWidget *parent)
{
    if (debug)
        qDebug() << "AnalyzerOutputPane::outputWidget";
    // Delayed creation of main pane widget. Add a trailing dummy widget
    // and add all adapters.
    if (!isInitialized())
        createWidgets(parent);
    return m_paneWidget;
}

void AnalyzerOutputPane::createWidgets(QWidget *paneParent)
{
    // Create pane and toolbar stack with leading dummy widget.
    m_paneWidget = new QWidget(paneParent);
    m_paneStackedLayout = new QStackedLayout(m_paneWidget);
    m_paneWidget->setObjectName(objectName() + QLatin1String("Widget"));
    m_paneStackedLayout->addWidget(new QLabel(tr("No current analysis tool"))); // placeholder

    // Temporarily assign to (wrong) parent to suppress flicker in conjunction with QStackedWidget.
    m_toolbarStackedWidget = new QStackedWidget(paneParent);
    m_toolbarStackedWidget->setObjectName(objectName() + QLatin1String("ToolBarStackedWidget"));
    m_toolbarStackedWidget->addWidget(createDummyWidget()); // placeholder
    m_toolBarSeparator = new Utils::StyledSeparator(paneParent);
    m_toolBarSeparator->setObjectName(objectName() + QLatin1String("ToolBarSeparator"));

    // Add adapters added before.
    const int adapterCount = m_adapters.size();
    const int firstAdapter = dummyIndex + 1;
    for (int i = firstAdapter; i < adapterCount; i++)
        addToWidgets(m_adapters.at(i));
    // Make last one current
    if (adapterCount > firstAdapter)
        setCurrentIndex(adapterCount - 1);
}

QWidgetList AnalyzerOutputPane::toolBarWidgets() const
{
    if (debug)
        qDebug() << "AnalyzerOutputPane::toolBarWidget";
    QTC_ASSERT(isInitialized(), return QWidgetList(); )

    QWidgetList list;
    list << m_toolBarSeparator << m_toolbarStackedWidget;
    AnalyzerManager::instance()->addOutputPaneToolBarWidgets(&list);
    return list;
}

QString AnalyzerOutputPane::displayName() const
{
    return tr("Analysis");
}

int AnalyzerOutputPane::priorityInStatusBar() const
{
    return -1; // Not visible in status bar.
}

void AnalyzerOutputPane::clearContents()
{
    if (IAnalyzerOutputPaneAdapter *adapter = currentAdapter())
        adapter->clearContents();
}

void AnalyzerOutputPane::visibilityChanged(bool v)
{
    Q_UNUSED(v)
}

void AnalyzerOutputPane::setFocus()
{
    if (IAnalyzerOutputPaneAdapter *adapter = currentAdapter())
        adapter->setFocus();
}

bool AnalyzerOutputPane::hasFocus()
{
    const IAnalyzerOutputPaneAdapter *adapter = currentAdapter();
    return adapter ? adapter->hasFocus() : false;
}

bool AnalyzerOutputPane::canFocus()
{
    const IAnalyzerOutputPaneAdapter *adapter = currentAdapter();
    return adapter ? adapter->canFocus() : false;
}

bool AnalyzerOutputPane::canNavigate()
{
    const IAnalyzerOutputPaneAdapter *adapter = currentAdapter();
    return adapter ? adapter->canNavigate() : false;
}

bool AnalyzerOutputPane::canNext()
{
    const IAnalyzerOutputPaneAdapter *adapter = currentAdapter();
    return adapter ? adapter->canNext() : false;
}

bool AnalyzerOutputPane::canPrevious()
{
    const IAnalyzerOutputPaneAdapter *adapter = currentAdapter();
    return adapter ? adapter->canPrevious() : false;
}

void AnalyzerOutputPane::goToNext()
{
    if (IAnalyzerOutputPaneAdapter *adapter = currentAdapter())
        adapter->goToNext();
}

void AnalyzerOutputPane::goToPrev()
{
    if (IAnalyzerOutputPaneAdapter *adapter = currentAdapter())
        adapter->goToPrev();
}

void AnalyzerOutputPane::slotPopup(bool withFocus)
{
    popup(withFocus);
}

void AnalyzerOutputPane::slotNavigationStatusChanged()
{
    IAnalyzerOutputPaneAdapter *adapter = qobject_cast<IAnalyzerOutputPaneAdapter *>(sender());
    const int index = m_adapters.indexOf(adapter);
    QTC_ASSERT(adapter != 0 && index != -1, return; )
    // Forward navigation status if it is the current pane.
    if (index == currentIndex())
        navigateStateChanged();
}

} // namespace Internal
} // namespace Analyzer