File indexing completed on 2024-04-14 04:31:21

0001 /* This file is part of KDevelop
0002    Copyright 2007-2008 Hamish Rodda <rodda@kde.org>
0003    Copyright 2011 Sebastien Rannou <mxs@sbrk.org>
0004    Copyright 2016 Anton Anikin <anton@anikin.xyz>
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This program is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014    General Public License for more details.
0015 
0016    You should have received a copy of the GNU General Public License
0017    along with this program; see the file COPYING.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #include "toolviewfactory.h"
0023 
0024 #include "debug.h"
0025 #include "plugin.h"
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <QTabWidget>
0030 
0031 namespace Valgrind
0032 {
0033 
0034 class ToolView : public QTabWidget
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     explicit ToolView(QWidget* parent);
0040     ~ToolView() override = default;
0041 };
0042 
0043 ToolView::ToolView(QWidget* parent)
0044     : QTabWidget(parent)
0045 {
0046     setWindowIcon(QIcon::fromTheme("fork"));
0047     setWindowTitle(i18n("Valgrind Output"));
0048 
0049     setWhatsThis(i18n("<b>Valgrind</b><p>Shows the output of valgrind. Valgrind detects:<br/>"
0050                       "use of uninitialized memory;<br/>"
0051                       "reading/writing memory after it has been free'd;<br/>"
0052                       "reading/writing off the end of malloc'd blocks;<br/>"
0053                       "reading/writing inappropriate areas on the stack;<br/>"
0054                       "memory leaks &mdash; where pointers to malloc'd blocks are lost forever;<br/>"
0055                       "passing of uninitialised and/or unaddressable memory to system calls;<br/>"
0056                       "mismatched use of malloc/new/new [] vs free/delete/delete [];<br/>"
0057                       "some abuses of the POSIX pthread API.</p>"));
0058 
0059     setTabsClosable(true);
0060 
0061     connect(this, &ToolView::tabCloseRequested, this, [this](int index) {
0062         delete widget(index);
0063         removeTab(index);
0064     });
0065 
0066     connect(Plugin::self(), &Plugin::addView, this, [this](QWidget* view, const QString& name) {
0067         Q_ASSERT(view);
0068 
0069         addTab(view, name);
0070         setCurrentWidget(view);
0071         setMovable(true);
0072     });
0073 }
0074 
0075 QWidget* ToolViewFactory::create(QWidget* parent)
0076 {
0077     return new ToolView(parent);
0078 }
0079 
0080 Qt::DockWidgetArea ToolViewFactory::defaultPosition() const
0081 {
0082     return Qt::BottomDockWidgetArea;
0083 }
0084 
0085 QString ToolViewFactory::id() const
0086 {
0087     return QStringLiteral("org.kdevelop.ValgrindView");
0088 }
0089 
0090 }
0091 
0092 #include "toolviewfactory.moc"