File indexing completed on 2025-02-23 04:34:24
0001 /** 0002 * \file tablemodeledit.cpp 0003 * Widget to edit a table model in-place. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 3 Jan 2018 0008 * 0009 * Copyright (C) 2018-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include "tablemodeledit.h" 0028 #include <QTableView> 0029 #include <QHeaderView> 0030 0031 TableModelEdit::TableModelEdit(QAbstractItemModel* model, QWidget* parent) 0032 : AbstractListEdit(m_tableView = new QTableView, model, parent) 0033 { 0034 setObjectName(QLatin1String("TableModelEdit")); 0035 setAddButtonText(tr("&Add")); 0036 hideEditButton(); 0037 m_tableView->setSelectionMode(QAbstractItemView::SingleSelection); 0038 m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); 0039 m_tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 0040 } 0041 0042 void TableModelEdit::addItem() 0043 { 0044 QAbstractItemModel* model = getItemView()->model(); 0045 int row = -1; 0046 if (QItemSelectionModel* selModel = getItemView()->selectionModel()) { 0047 if (QModelIndexList indexes = selModel->selectedIndexes(); 0048 !indexes.isEmpty()) { 0049 row = indexes.first().row(); 0050 } 0051 } 0052 if (row < 0 || row > model->rowCount()) { 0053 row = model->rowCount(); 0054 } 0055 model->insertRow(row); 0056 } 0057 0058 void TableModelEdit::editItem() 0059 { 0060 }