Commit 4b05ae71 authored by Dag Andersen's avatar Dag Andersen
Browse files

Fix text alignment in data models

Use default for all genuine text data, and
right alignment for numeric data even when
it is issued to the view as text.

BUG: 277291
Column alignments in task table are incorrect
parent 092dde65
......@@ -134,10 +134,7 @@ QVariant AccountModel::headerData( int property, int role ) const
}
}
if ( role == Qt::TextAlignmentRole ) {
switch (property) {
case AccountModel::Description: return Qt::AlignLeft;
default: return QVariant();
}
return QVariant();
}
if ( role == Qt::ToolTipRole ) {
switch ( property ) {
......@@ -1077,7 +1074,7 @@ QVariant CostBreakdownItemModel::headerData( int section, Qt::Orientation orient
switch ( section ) {
case 0: return QVariant();
case 1: return QVariant();
default: return Qt::AlignRight;
default: return (int)(Qt::AlignRight|Qt::AlignVCenter);
}
return QVariant();
}
......
......@@ -2231,6 +2231,118 @@ QVariant NodeModel::headerData( int section, int role )
default: return QVariant();
}
}
if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case NodeName:
case NodeType:
case NodeResponsible:
case NodeAllocation:
case NodeEstimateType:
case NodeEstimateCalendar:
return QVariant(); // text, use default alignment
case NodeEstimate:
case NodeOptimisticRatio:
case NodePessimisticRatio:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeRisk:
case NodeConstraint:
return QVariant(); // text, use default alignment
case NodeConstraintStart:
case NodeConstraintEnd:
case NodeRunningAccount:
case NodeStartupAccount:
return QVariant(); // text, use default alignment
case NodeStartupCost:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeShutdownAccount:
return QVariant(); // text, use default alignment
case NodeShutdownCost:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeDescription:
return QVariant(); // text, use default alignment
// Based on edited values
case NodeExpected:
case NodeVarianceEstimate:
case NodeOptimistic:
case NodePessimistic:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
// After scheduling
case NodeStartTime:
case NodeEndTime:
case NodeEarlyStart:
case NodeEarlyFinish:
case NodeLateStart:
case NodeLateFinish:
return QVariant(); // text, use default alignment
case NodePositiveFloat:
case NodeFreeFloat:
case NodeNegativeFloat:
case NodeStartFloat:
case NodeFinishFloat:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeAssignments:
return QVariant(); // text, use default alignment
// Based on scheduled values
case NodeDuration:
case NodeVarianceDuration:
case NodeOptimisticDuration:
case NodePessimisticDuration:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
// Completion
case NodeStatus:
return QVariant(); // text, use default alignment
case NodeCompleted:
case NodePlannedEffort:
case NodeActualEffort:
case NodeRemainingEffort:
case NodePlannedCost:
case NodeActualCost:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeActualStart:
case NodeStarted:
case NodeActualFinish:
case NodeFinished:
case NodeStatusNote:
return QVariant(); // text, use default alignment
// Scheduling errors
case NodeSchedulingStatus:
case NodeNotScheduled:
case NodeAssignmentMissing:
case NodeResourceOverbooked:
case NodeResourceUnavailable:
case NodeConstraintsError:
case NodeEffortNotMet:
case NodeSchedulingError:
return QVariant(); // text, use default alignment
case NodeWBSCode:
return QVariant(); // text, use default alignment
case NodeLevel:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
// Performance
case NodeBCWS:
case NodeBCWP:
case NodeACWP:
case NodePerformanceIndex:
return (int)(Qt::AlignRight|Qt::AlignBottom); // number
case NodeCritical:
case NodeCriticalPath:
return QVariant(); // text, use default alignment
case WPOwnerName:
case WPTransmitionStatus:
case WPTransmitionTime:
return QVariant(); // text, use default alignment
default:
return QVariant();
}
}
if ( role == Qt::WhatsThisRole ) {
switch ( section ) {
case NodeNegativeFloat: return WhatsThis::nodeNegativeFloat();
......@@ -3115,6 +3227,9 @@ bool NodeItemModel::setFinishedTime( Node *node, const QVariant &value, int role
QVariant NodeItemModel::data( const QModelIndex &index, int role ) const
{
QVariant result;
if ( role == Qt::TextAlignmentRole ) {
return headerData( index.column(), Qt::Horizontal, role );
}
Node *n = node( index );
if ( n != 0 ) {
result = m_nodemodel.data( n, index.column(), role );
......@@ -3181,14 +3296,8 @@ bool NodeItemModel::setData( const QModelIndex &index, const QVariant &value, in
QVariant NodeItemModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Horizontal ) {
if ( role == Qt::DisplayRole ) {
if ( role == Qt::DisplayRole || role == Qt::TextAlignmentRole ) {
return m_nodemodel.headerData( section, role );
} else if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case NodeModel::NodeName: return Qt::AlignLeft;
case NodeModel::NodeType: return Qt::AlignCenter;
default: return QVariant();
}
}
}
if ( role == Qt::ToolTipRole ) {
......@@ -4366,6 +4475,9 @@ bool MilestoneItemModel::setShutdownCost( Node *node, const QVariant &value, int
QVariant MilestoneItemModel::data( const QModelIndex &index, int role ) const
{
QVariant result;
if ( role == Qt::TextAlignmentRole ) {
return headerData( index.column(), Qt::Horizontal, role );
}
Node *n = node( index );
if ( n != 0 ) {
if ( index.column() == NodeModel::NodeType && role == KDGantt::ItemTypeRole ) {
......@@ -4415,14 +4527,8 @@ bool MilestoneItemModel::setData( const QModelIndex &index, const QVariant &valu
QVariant MilestoneItemModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Horizontal ) {
if ( role == Qt::DisplayRole ) {
if ( role == Qt::DisplayRole || role == Qt::TextAlignmentRole) {
return m_nodemodel.headerData( section, role );
} else if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case NodeModel::NodeName: return Qt::AlignLeft;
case NodeModel::NodeType: return Qt::AlignCenter;
default: return QVariant();
}
}
}
if ( role == Qt::ToolTipRole ) {
......
......@@ -261,11 +261,7 @@ QVariant CriticalPathItemModel::headerData( int section, Qt::Orientation orienta
QVariant CriticalPathItemModel::alignment( int column ) const
{
switch ( column ) {
case 0: return QVariant(); // use default for column 0
default: return Qt::AlignCenter;
}
return QVariant();
return m_nodemodel.headerData( column, Qt::TextAlignmentRole );
}
int CriticalPathItemModel::columnCount( const QModelIndex & ) const
......@@ -771,11 +767,7 @@ QVariant PertResultItemModel::headerData( int section, Qt::Orientation orientati
QVariant PertResultItemModel::alignment( int column ) const
{
switch ( column ) {
case 0: return QVariant(); // use default for column 0
default: return Qt::AlignCenter;
}
return QVariant();
return m_nodemodel.headerData( column, Qt::TextAlignmentRole );
}
QAbstractItemDelegate *PertResultItemModel::createDelegate( int column, QWidget * /*parent*/ ) const
......
......@@ -621,7 +621,7 @@ QVariant ResourceAppointmentsItemModel::total( const Resource *res, int role ) c
case Qt::WhatsThisRole:
return QVariant();
case Qt::TextAlignmentRole:
return Qt::AlignRight;
return (int)(Qt::AlignRight|Qt::AlignVCenter);
}
return QVariant();
}
......@@ -659,7 +659,7 @@ QVariant ResourceAppointmentsItemModel::total( const Resource *res, const QDate
case Qt::WhatsThisRole:
return QVariant();
case Qt::TextAlignmentRole:
return Qt::AlignRight;
return (int)(Qt::AlignRight|Qt::AlignVCenter);
case Qt::BackgroundRole: {
if ( res->calendar() && res->calendar()->state( date ) != CalendarDay::Working ) {
QColor c( 0xf0f0f0 );
......@@ -697,7 +697,7 @@ QVariant ResourceAppointmentsItemModel::total( const Appointment *a, int role )
case Qt::WhatsThisRole:
return QVariant();
case Qt::TextAlignmentRole:
return Qt::AlignRight;
return (int)(Qt::AlignRight|Qt::AlignVCenter);
case Qt::ForegroundRole:
if ( m_externalEffortMap.contains( a ) ) {
return QVariant( Qt::blue );
......@@ -741,7 +741,7 @@ QVariant ResourceAppointmentsItemModel::assignment( const Appointment *a, const
case Qt::WhatsThisRole:
return QVariant();
case Qt::TextAlignmentRole:
return Qt::AlignRight;
return (int)(Qt::AlignRight|Qt::AlignVCenter);
case Qt::ForegroundRole:
if ( m_externalEffortMap.contains( a ) ) {
return QVariant( Qt::blue );
......@@ -790,6 +790,9 @@ QVariant ResourceAppointmentsItemModel::data( const QModelIndex &index, int role
kDebug()<<"Invalid index:"<<index;
return result;
}
if ( role == Qt::TextAlignmentRole ) {
return headerData( index.column(), Qt::Horizontal, role );
}
Resource *r = resource( index );
if ( r ) {
switch ( index.column() ) {
......@@ -932,7 +935,7 @@ QVariant ResourceAppointmentsItemModel::headerData( int section, Qt::Orientation
} else if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case 0: return QVariant();
default: return Qt::AlignRight;
default: return (int)(Qt::AlignRight|Qt::AlignVCenter);
}
}
}
......@@ -1506,6 +1509,9 @@ QVariant ResourceAppointmentsRowModel::data( const QModelIndex &index, int role
if ( ! index.isValid() ) {
return QVariant();
}
if ( role == Qt::TextAlignmentRole ) {
return headerData( index.column(), Qt::Horizontal, role );
}
return static_cast<Private*>(index.internalPointer() )->data( index.column(), id(), role );
}
......@@ -1523,6 +1529,17 @@ QVariant ResourceAppointmentsRowModel::headerData( int section, Qt::Orientation
case Load: return i18nc( "@title:column noun", "Load" );
}
}
if ( role == Qt::TextAlignmentRole ) {
switch ( section ) {
case Name:
case Type:
case StartTime:
case EndTime:
return (int)(Qt::AlignLeft|Qt::AlignVCenter);;
case Load:
return (int)(Qt::AlignRight|Qt::AlignVCenter);
}
}
return ItemModelBase::headerData( section, orientation, role );
}
......
......@@ -445,8 +445,24 @@ QVariant ResourceModel::headerData( int section, int role )
}
} else if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case 0: return QVariant();
default: return Qt::AlignCenter;
case ResourceName:
case ResourceType:
case ResourceInitials:
case ResourceEmail:
case ResourceCalendar:
return QVariant();
case ResourceLimit:
return (int)(Qt::AlignRight|Qt::AlignVCenter);
case ResourceAvailableFrom:
case ResourceAvailableUntil:
return QVariant();
case ResourceNormalRate:
case ResourceOvertimeRate:
return (int)(Qt::AlignRight|Qt::AlignVCenter);
case ResourceAccount: return i18n( "Account" );
return QVariant();
default:
return QVariant();
}
} else if ( role == Qt::ToolTipRole ) {
switch ( section ) {
......@@ -1072,16 +1088,9 @@ bool ResourceItemModel::setData( const QModelIndex &index, const QVariant &value
QVariant ResourceItemModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Horizontal ) {
if ( role == Qt::DisplayRole ) {
if ( role == Qt::DisplayRole || role == Qt::TextAlignmentRole ) {
return m_model.headerData( section, role );
}
if ( role == Qt::TextAlignmentRole ) {
switch (section) {
case 0: return QVariant();
default: return Qt::AlignCenter;
}
return Qt::AlignCenter;
}
}
if ( role == Qt::ToolTipRole ) {
return m_model.headerData( section, role );
......
......@@ -700,6 +700,9 @@ QVariant ScheduleItemModel::data( const QModelIndex &index, int role ) const
{
//kDebug()<<index.row()<<","<<index.column();
QVariant result;
if ( role == Qt::TextAlignmentRole ) {
return headerData( index.column(), Qt::Horizontal, role );
}
switch ( index.column() ) {
case ScheduleModel::ScheduleName: result = name( index, role ); break;
case ScheduleModel::ScheduleState: result = state( index, role ); break;
......@@ -769,9 +772,7 @@ QVariant ScheduleItemModel::headerData( int section, Qt::Orientation orientation
default: return QVariant();
}
} else if ( role == Qt::TextAlignmentRole ) {
switch (section) {
default: return Qt::AlignCenter;
}
return QVariant();
}
}
if ( role == Qt::ToolTipRole ) {
......
......@@ -591,11 +591,7 @@ QVariant TaskStatusItemModel::headerData( int section, Qt::Orientation orientati
QVariant TaskStatusItemModel::alignment( int column ) const
{
switch ( column ) {
case 0: return QVariant(); // use default
default: return Qt::AlignCenter;
}
return QVariant();
return m_nodemodel.headerData( column, Qt::TextAlignmentRole );
}
QAbstractItemDelegate *TaskStatusItemModel::createDelegate( int column, QWidget *parent ) const
......
......@@ -92,6 +92,9 @@ QVariant TaskEditorItemModel::headerData( int section, Qt::Orientation orientati
QVariant TaskEditorItemModel::data( const QModelIndex &index, int role ) const
{
if ( role == Qt::TextAlignmentRole ) {
return NodeItemModel::data( index, role );
}
Node *n = node( index );
if ( n != 0 && index.column() == NodeModel::NodeType ) {
return type( n, role );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment