File indexing completed on 2025-01-19 05:20:13
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2012 Alex Richardson <alex.richardson@gmx.de> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "scriptloggerview.hpp" 0010 0011 #include <KComboBox> 0012 #include <QTableView> 0013 #include <QHeaderView> 0014 #include <QVBoxLayout> 0015 // Std 0016 #include <utility> 0017 0018 #include "scriptlogger.hpp" 0019 0020 ScriptLoggerView::ScriptLoggerView(const TopLevelDataInformation::List& data, QWidget* parent) 0021 : QWidget(parent) 0022 , mSelector(new KComboBox(this)) 0023 , mView(new QTableView(this)) 0024 , mList(data) 0025 { 0026 for (const auto& info : std::as_const(mList)) { 0027 mSelector->addItem(info->objectName()); 0028 } 0029 0030 mView->setShowGrid(false); 0031 mView->setSelectionBehavior(QAbstractItemView::SelectRows); 0032 mView->setWordWrap(false); 0033 QHeaderView* horizHeader = mView->horizontalHeader(); 0034 horizHeader->setAcceptDrops(false); 0035 horizHeader->setSectionResizeMode(QHeaderView::Interactive); 0036 horizHeader->setSortIndicatorShown(false); 0037 horizHeader->setStretchLastSection(true); 0038 if (!mList.isEmpty()) { 0039 mView->setModel(mList.at(0)->logger()); 0040 mView->resizeRowsToContents(); 0041 } 0042 connect(mSelector, qOverload<int>(&KComboBox::currentIndexChanged), 0043 this, &ScriptLoggerView::updateModel); 0044 auto* layout = new QVBoxLayout(); 0045 layout->setContentsMargins(0, 0, 0, 0); 0046 layout->addWidget(mSelector, 0); 0047 layout->addWidget(mView, 1); 0048 setLayout(layout); 0049 } 0050 0051 ScriptLoggerView::~ScriptLoggerView() = default; 0052 0053 void ScriptLoggerView::updateModel(int index) 0054 { 0055 Q_ASSERT(index >= 0 && index < mList.size()); 0056 mView->setModel(mList.at(index)->logger()); 0057 mView->resizeRowsToContents(); 0058 } 0059 0060 #include "moc_scriptloggerview.cpp"