Files
create/src/Mod/Spreadsheet/Gui/SheetModel.h
Zheng, Lei 0c2c334f87 Spreadsheet: support cell binding
Cell binding allows one to bind a range of cells of one sheet to another
range of cells of an arbitary sheet, including any empty cells in the
range.

The binding is implemented with PropertyExpressionEngine and
PropertySheet::setPathValue(), which binds a special path of
PropertySheet, such as

    .cells.Bind.A1.D1

to an expression, such as

     tuple(.cells, <<A2>>, <<A5>>)

The A1 and D1 in the example above specifies the binding start and end
cell address. And <<A2>> and <<A5>> are the range of cells to bind to.
Note that you can use any expression that evalutes to string for the
binding destination, e.g. <<A%d>> % B1, which uses the value inside B1
to construct the binding destination. The '.cells' in the tuple shown
above is an example to bind cells of the same PropertySheet. It can be
change to to reference to any other spreadsheet, even those outside the
current document, e.g. Document#Spreadsheet001.cells
2021-12-21 21:41:02 -07:00

67 lines
2.8 KiB
C++

/***************************************************************************
* Copyright (c) Eivind Kvedalen (eivind@kvedalen.name) 2015 *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* 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 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 *
* *
***************************************************************************/
#ifndef SHEETMODEL_H
#define SHEETMODEL_H
#include <QAbstractTableModel>
#include <Mod/Spreadsheet/App/Utils.h>
#include <App/Range.h>
namespace Spreadsheet {
class Sheet;
}
namespace SpreadsheetGui {
class SheetModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit SheetModel(Spreadsheet::Sheet * _sheet, QObject *parent = 0);
~SheetModel();
SheetModel(QObject *parent);
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
Qt::ItemFlags flags(const QModelIndex &) const;
private:
void cellUpdated(App::CellAddress address);
void rangeUpdated(const App::Range &range);
boost::signals2::scoped_connection cellUpdatedConnection;
boost::signals2::scoped_connection rangeUpdatedConnection;
Spreadsheet::Sheet * sheet;
QColor aliasBgColor;
QColor textFgColor;
QColor positiveFgColor;
QColor negativeFgColor;
};
}
#endif // SHEETMODEL_H