Initial implementation of Spreadsheet module (C++ version) by Eivind Kvedalen.
Various fixes for Windows by Peter Lama <peterldev94@gmail.com> Werner Mayer <wmayer@users.sourceforge.net>
This commit is contained in:
79
src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp
Normal file
79
src/Mod/Spreadsheet/Gui/SpreadsheetDelegate.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Eivind Kvedalen (eivind@kvedalen.name) *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This file is based on the Qt spreadsheet example code. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "SpreadsheetDelegate.h"
|
||||
#include <QItemDelegate>
|
||||
#include <QLineEdit>
|
||||
|
||||
using namespace SpreadsheetGui;
|
||||
|
||||
SpreadsheetDelegate::SpreadsheetDelegate(QWidget *parent) :
|
||||
QItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *SpreadsheetDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem &,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *editor = new QLineEdit(parent);
|
||||
|
||||
connect(editor, SIGNAL(returnPressed()), this, SLOT(commitAndCloseEditor()));
|
||||
return editor;
|
||||
}
|
||||
|
||||
void SpreadsheetDelegate::commitAndCloseEditor()
|
||||
{
|
||||
QLineEdit *editor = qobject_cast<QLineEdit *>(sender());
|
||||
emit commitData(editor);
|
||||
emit closeEditor(editor);
|
||||
}
|
||||
|
||||
void SpreadsheetDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
|
||||
if (edit) {
|
||||
edit->setText(index.model()->data(index, Qt::EditRole).toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SpreadsheetDelegate::setModelData(QWidget *editor,
|
||||
QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
|
||||
if (edit) {
|
||||
model->setData(index, edit->text());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QSize SpreadsheetDelegate::sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||
{
|
||||
return QSize();
|
||||
}
|
||||
|
||||
#include "moc_SpreadsheetDelegate.cpp"
|
||||
|
||||
Reference in New Issue
Block a user