GridAccount rendering is now like wxWidgets GridAccount
This commit is contained in:
parent
34112f7762
commit
f035692ea3
|
@ -20,15 +20,15 @@
|
|||
#ifndef CHOICEDELEGATE_H
|
||||
#define CHOICEDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include <QString>
|
||||
|
||||
class ChoiceDelegate : public QItemDelegate
|
||||
class ChoiceDelegate : public TableViewDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ChoiceDelegate(QWidget *parent = 0, QString* values=0, int nbValues=0) : QItemDelegate(parent), _values(values), _nbValues(nbValues) {}
|
||||
ChoiceDelegate(QWidget *parent = 0, QString* values=0, int nbValues=0) : TableViewDelegate(parent), _values(values), _nbValues(nbValues) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
#ifndef DATEDELEGATE_H
|
||||
#define DATEDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include <QString>
|
||||
|
||||
class DateDelegate : public QItemDelegate
|
||||
class DateDelegate : public TableViewDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
DateDelegate(QWidget *parent = 0, int month=0, int year=0) : QItemDelegate(parent), _day(1), _month(month), _year(year) {}
|
||||
DateDelegate(QWidget *parent = 0, int month=0, int year=0) : TableViewDelegate(parent), _day(1), _month(month), _year(year) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
|
|
@ -20,15 +20,15 @@
|
|||
#ifndef FLOATDELEGATE_H
|
||||
#define FLOATDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include <QString>
|
||||
|
||||
class FloatDelegate : public QItemDelegate
|
||||
class FloatDelegate : public TableViewDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
FloatDelegate(QWidget *parent = 0) : QItemDelegate(parent) {}
|
||||
FloatDelegate(QWidget *parent = 0) : TableViewDelegate(parent) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
#ifndef FORMULADELEGATE_H
|
||||
#define FORMULADELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include <QString>
|
||||
#include <model/model.hpp>
|
||||
|
||||
class FormulaDelegate : public QItemDelegate
|
||||
class FormulaDelegate : public TableViewDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
FormulaDelegate(QWidget *parent = 0, std::vector<Operation>* operations=0) : QItemDelegate(parent), _operations(operations) {}
|
||||
FormulaDelegate(QWidget *parent = 0, std::vector<Operation>* operations=0) : TableViewDelegate(parent), _operations(operations) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QCheckBox>
|
||||
|
||||
#include "GridAccount.hpp"
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include "ChoiceDelegate.hpp"
|
||||
#include "DateDelegate.hpp"
|
||||
#include "FloatDelegate.hpp"
|
||||
|
@ -47,8 +48,8 @@
|
|||
GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
|
||||
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase)
|
||||
: QTableWidget(parent), _fixCosts(0), _week1(0),
|
||||
_week2(0), _week3(0), _week4(0), _parent(parent), _kiss(kiss),
|
||||
_canAddOperation(canAddOperation), _setWeek(setWeek),
|
||||
_week2(0), _week3(0), _week4(0), _canAddOperation(canAddOperation),
|
||||
_parent(parent), _kiss(kiss), _setWeek(setWeek),
|
||||
_databaseSynchronization(synchronizeWithDatabase), _loadOperations(false),
|
||||
_curMonth(0), _curYear(0), _signalMapper(this)
|
||||
{
|
||||
|
@ -65,6 +66,7 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
|
|||
setRowCount(1);
|
||||
verticalHeader()->setHidden(true);
|
||||
horizontalHeader()->setHidden(true);
|
||||
setShowGrid(false);
|
||||
|
||||
setColumnWidth (DESCRIPTION, columnWidth(DESCRIPTION)*3);
|
||||
//SetDefaultCellFont(font);
|
||||
|
@ -116,6 +118,8 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
|
|||
resizeColumnToContents(CHECKED);
|
||||
|
||||
connect(&_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnMetaClicked(int)));
|
||||
|
||||
setItemDelegate(new TableViewDelegate(this));
|
||||
}
|
||||
|
||||
GridAccount::~GridAccount()
|
||||
|
@ -124,26 +128,6 @@ GridAccount::~GridAccount()
|
|||
delete[] _accounts;
|
||||
}
|
||||
|
||||
// wxPen GridAccount::GetColGridLinePen (int col)
|
||||
// {return wxPen(*wxBLACK, 1, wxSOLID);}
|
||||
|
||||
// wxPen GridAccount::GetRowGridLinePen (int row) {
|
||||
// if (_canAddOperation)
|
||||
// {
|
||||
// if (row == 0 || row == _fixCosts ||
|
||||
// row == _week1 ||
|
||||
// row == _week2 ||
|
||||
// row == _week3 ||
|
||||
// row == _week4)
|
||||
// return wxPen(*wxBLACK, 1, wxSOLID);
|
||||
// }
|
||||
// else
|
||||
// if (row == 0)
|
||||
// return wxPen(*wxBLACK, 1, wxSOLID);
|
||||
|
||||
// return GetCellBackgroundColour(row, 0);
|
||||
// }
|
||||
|
||||
void GridAccount::ResetWeeks()
|
||||
{
|
||||
_week1 = _week2 = _week3 = _week4 = 0;
|
||||
|
@ -280,7 +264,7 @@ void GridAccount::LoadOperations(std::vector<Operation>* operations, int month,
|
|||
void GridAccount::ComputeWeeks()
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int curLine;//, curWeek, week, i;
|
||||
int curLine, curWeek, week, i;
|
||||
|
||||
if (!_canAddOperation) return;
|
||||
|
||||
|
@ -295,18 +279,18 @@ void GridAccount::ComputeWeeks()
|
|||
|
||||
ResetWeeks();
|
||||
|
||||
// curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
// it++;
|
||||
// for (i=1; it != _displayedOperations.end(); it++, curLine++)
|
||||
// {
|
||||
// if (!it->id || it->parent) continue;
|
||||
// week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth();
|
||||
// if (week != curWeek)
|
||||
// {
|
||||
// SetWeek(i++, curLine);
|
||||
// curWeek = week;
|
||||
// }
|
||||
// }
|
||||
curWeek = QDate(it->year, it->month+1, it->day+1).weekNumber();
|
||||
it++;
|
||||
for (i=1; it != _displayedOperations.end(); it++, curLine++)
|
||||
{
|
||||
if (!it->id || it->parent) continue;
|
||||
week = QDate(it->year, it->month+1, it->day+1).weekNumber();
|
||||
if (week != curWeek)
|
||||
{
|
||||
SetWeek(i++, curLine);
|
||||
curWeek = week;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperationWithWeek(User* user, Operation& op, int line, bool fix, int month, int year)
|
||||
|
@ -451,12 +435,8 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
|||
_signalMapper.setMapping(button, op.id);
|
||||
connect(button, SIGNAL(clicked()), &_signalMapper, SLOT(map()));
|
||||
|
||||
//button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
//button->resize(button->minimumSize());
|
||||
button->setMaximumSize(QSize(height, height));
|
||||
setCellWidget(line, TREE, button);
|
||||
// SetCellRenderer(line, TREE, new wxGridCellTreeButtonRenderer());
|
||||
// SetCellEditor(line, TREE, new wxGridCellTreeButtonEditor());
|
||||
|
||||
SET_READ_ONLY(this->item(line, OP_DATE));
|
||||
SET_READ_ONLY(this->item(line, CREDIT));
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
|
||||
int _fixCosts;
|
||||
int _week1, _week2, _week3, _week4;
|
||||
bool _canAddOperation;
|
||||
std::vector<Operation> _displayedOperations;
|
||||
|
||||
private slots:
|
||||
|
@ -80,7 +81,7 @@ private:
|
|||
QWidget* _parent;
|
||||
KissCount* _kiss;
|
||||
bool _displayLines;
|
||||
bool _canAddOperation, _setWeek;
|
||||
bool _setWeek;
|
||||
bool _databaseSynchronization;
|
||||
QString* _categories, *_accounts;
|
||||
std::vector<Operation>* _operations;
|
||||
|
|
|
@ -20,16 +20,15 @@
|
|||
#ifndef TABDELEGATE_H
|
||||
#define TABDELEGATE_H
|
||||
|
||||
#include <QItemDelegate>
|
||||
#include "TableViewDelegate.hpp"
|
||||
#include <QString>
|
||||
#include <model/model.hpp>
|
||||
|
||||
class TabDelegate : public QItemDelegate
|
||||
class TabDelegate : public TableViewDelegate
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
TabDelegate(QWidget *parent = 0, std::vector<Operation>* operations=0) : QItemDelegate(parent), _operations(operations) {}
|
||||
TabDelegate(QWidget *parent = 0, std::vector<Operation>* operations=0) : TableViewDelegate(parent), _operations(operations) {}
|
||||
|
||||
QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
|
|
73
src/view/grid/TableViewDelegate.hpp
Normal file
73
src/view/grid/TableViewDelegate.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TABLEVIEWDELEGATE_H
|
||||
#define TABLEVIEWDELEGATE_H
|
||||
|
||||
#include <QtGui>
|
||||
#include "GridAccount.hpp"
|
||||
|
||||
class TableViewDelegate : public QStyledItemDelegate
|
||||
{
|
||||
private:
|
||||
GridAccount* _grid;
|
||||
|
||||
public:
|
||||
// "Nomme" les rôles utilisés par ce delegate
|
||||
// pour récupèrer les nouvelles propriétés d'un item
|
||||
enum Roles {
|
||||
BorderWidthRole = Qt::UserRole,
|
||||
BorderColorRole,
|
||||
};
|
||||
|
||||
TableViewDelegate(QObject *parent = 0) : QStyledItemDelegate(parent), _grid(qobject_cast<GridAccount*>(parent))
|
||||
{
|
||||
}
|
||||
|
||||
void paint (QPainter * painter,
|
||||
const QStyleOptionViewItem & option,
|
||||
const QModelIndex & index ) const
|
||||
{
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!_grid) return;
|
||||
|
||||
QPen pen(Qt::black);
|
||||
int row = index.row();
|
||||
painter->setPen(pen);
|
||||
|
||||
// Always paint column
|
||||
painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
|
||||
|
||||
if (row == 0)
|
||||
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
||||
else if (_grid->_canAddOperation)
|
||||
{
|
||||
if (row == _grid->_fixCosts ||
|
||||
row == _grid->_week1 ||
|
||||
row == _grid->_week2 ||
|
||||
row == _grid->_week3 ||
|
||||
row == _grid->_week4)
|
||||
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user