Logo Search packages:      
Sourcecode: webissues version File versions  Download package

tablemodels.cpp

/**************************************************************************
* This file is part of the WebIssues program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007 WebIssues Team
*
* This program 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 2 of the License, or
* (at your option) any later version.
**************************************************************************/

#include "tablemodels.h"

#include <QPixmap>

#include "attributes/definitioninfo.h"
#include "attributes/definitionparser.h"
#include "attributes/definitionhelper.h"
#include "attributes/datetimehelper.h"
#include "data/rdb/tableiterators.h"
#include "data/datamanager.h"
#include "data/datarows.h"
#include "data/rowhelpers.h"
#include "data/updateevent.h"
#include "data/connectioninfo.h"
#include "connectionmanager.h"
#include "tablemodelshelper.h"
#include "linklocator.h"
#include "iconloader.h"

using namespace WebIssues;

00033 UsersTableModel::UsersTableModel( QObject* parent ) : AbstractTableModel( parent )
{
}

00037 UsersTableModel::~UsersTableModel()
{
}

00041 QString UsersTableModel::text( int id, Column column ) const
{
    const UserRow* row = dataManager->users()->find( id );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return row->name();
        case Column_Login:
            return row->login();
        case Column_Access:
            if ( row->access() == NormalAccess )
                return tr( "Regular User" );
            if ( row->access() == AdminAccess )
                return tr( "System Administrator" );
            return tr( "Disabled User" );
        default:
            return QString();
    }
}

00063 QPixmap UsersTableModel::icon( int id ) const
{
    const UserRow* row = dataManager->users()->find( id );
    if ( row ) {
        if ( row->access() == AdminAccess )
            return IconLoader::overlayedPixmap( "user", "overlay-admin" );
        if ( row->access() == NoAccess )
            return IconLoader::pixmap( "user-disabled" );
    }
    return IconLoader::pixmap( "user" );
}

00075 void UsersTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Users )
        emit tableChanged();
}

00081 MembersTableModel::MembersTableModel( int projectId, QObject* parent ) : AbstractTableModel( parent ),
    m_projectId( projectId )
{
}

00086 MembersTableModel::~MembersTableModel()
{
}

00090 QString MembersTableModel::text( int id, Column column ) const
{
    const MemberRow* row = dataManager->members()->find( id, m_projectId );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return TableModelsHelper::userName( row->userId() );
        case Column_Access:
            if ( row->access() == NormalAccess )
                return tr( "Regular Member" );
            if ( row->access() == AdminAccess )
                return tr( "Project Administrator" );
            return QString();
        default:
            return QString();
    }
}

00110 QPixmap MembersTableModel::icon( int id ) const
{
    const MemberRow* row = dataManager->members()->find( id, m_projectId );
    if ( row && row->access() == AdminAccess )
        return IconLoader::overlayedPixmap( "user", "overlay-admin" );

    return IconLoader::pixmap( "user" );
}

00119 void MembersTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Users )
        emit tableChanged();
}

00125 TypesTableModel::TypesTableModel( QObject* parent ) : AbstractTableModel( parent )
{
}

00129 TypesTableModel::~TypesTableModel()
{
}

00133 QString TypesTableModel::text( int id, Column column ) const
{
    const TypeRow* row = dataManager->types()->find( id );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return row->name();
        default:
            return QString();
    }
}

00147 QPixmap TypesTableModel::icon( int id ) const
{
    return IconLoader::pixmap( "type" );
}

00152 void TypesTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Types )
        emit tableChanged();
}

00158 AttributesTableModel::AttributesTableModel( QObject* parent ) : AbstractTableModel( parent )
{
}

00162 AttributesTableModel::~AttributesTableModel()
{
}

00166 QString AttributesTableModel::text( int id, Column column ) const
{
    const AttributeRow* row = dataManager->attributes()->find( id );
    if ( !row )
        return QString();

    if ( column == Column_Name )
        return row->name();

    DefinitionParser parser;
    DefinitionInfo info = parser.parse( row->definition() );

    switch ( column ) {
        case Column_Type:
            return DefinitionHelper::typeName( info.type() );
        case Column_DefaultValue:
            return info.defaultValue();
        case Column_Required:
            return info.required() ? tr( "Yes" ) : tr( "No" );
        case Column_Details:
            return DefinitionHelper::metadataDetails( info );
        default:
            return QString();
    }
}

00192 QPixmap AttributesTableModel::icon( int id ) const
{
    return IconLoader::pixmap( "attribute" );
}

00197 void AttributesTableModel::updateEvent( UpdateEvent* e )
{
}

00201 ProjectsTableModel::ProjectsTableModel( QObject* parent ) : AbstractTableModel( parent )
{
}

00205 ProjectsTableModel::~ProjectsTableModel()
{
}

00209 QString ProjectsTableModel::text( int id, Column column ) const
{
    const ProjectRow* row = dataManager->projects()->find( id );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return row->name();
        default:
            return QString();
    }
}

00223 QPixmap ProjectsTableModel::icon( int id ) const
{
    if ( connectionManager->connectionInfo()->access() == AdminAccess )
        return IconLoader::overlayedPixmap( "project", "overlay-admin" );

    int userId = connectionManager->connectionInfo()->userId();
    const MemberRow* member = dataManager->members()->find( userId, id );
    if ( member && member->access() == AdminAccess )
        return IconLoader::overlayedPixmap( "project", "overlay-admin" );

    return IconLoader::pixmap( "project" );
}

00236 void ProjectsTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Projects )
        emit tableChanged();
}

00242 FoldersTableModel::FoldersTableModel( QObject* parent ) : AbstractTableModel( parent )
{
}

00246 FoldersTableModel::~FoldersTableModel()
{
}

00250 QString FoldersTableModel::text( int id, Column column ) const
{
    const FolderRow* row = dataManager->folders()->find( id );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return row->name();
        case Column_Type:
            return TableModelsHelper::typeName( row->typeId() );
        default:
            return QString();
    }
}

00266 QPixmap FoldersTableModel::icon( int id ) const
{
    return IconLoader::pixmap( "folder" );
}

00271 void FoldersTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Folder )
        emit rowChanged( e->id() );
}

00277 IssuesTableModel::IssuesTableModel( int folderId, QObject* parent ) : AbstractTableModel( parent ),
    m_folderId( folderId )
{
}

00282 IssuesTableModel::~IssuesTableModel()
{
}

00286 QString IssuesTableModel::text( int id, Column column ) const
{
    const IssueRow* row = dataManager->issues()->find( id );
    if ( !row )
        return QString();

    if ( column > Column_UserDefined ) {
        int attributeId = column - Column_UserDefined;
        const ValueRow* value = dataManager->values()->find( attributeId, id );
        return value ? value->value() : QString();
    }

    switch ( column ) {
        case Column_Name:
            return row->name();
        case Column_ID:
            return TableModelsHelper::formatId( id );
        case Column_CreatedDate:
            return DateTimeHelper::formatDateTime( row->createdDate() );
        case Column_CreatedBy:
            return TableModelsHelper::userName( row->createdUser() );
        case Column_ModifiedDate:
            return DateTimeHelper::formatDateTime( row->modifiedDate() );
        case Column_ModifiedBy:
            return TableModelsHelper::userName( row->modifiedUser() );
        default:
            return QString();
    }
}

00316 QPixmap IssuesTableModel::icon( int id ) const
{
    return IconLoader::pixmap( "issue" );
}

00321 QString IssuesTableModel::toolTip( int id ) const
{
    const IssueRow* issue = dataManager->issues()->find( id );
    const FolderRow* folder = issue ? dataManager->folders()->find( issue->folderId() ) : NULL;
    if ( !folder )
        return QString();

    RDB::ForeignConstIterator<AttributeRow> it( dataManager->attributes()->parentIndex(), folder->typeId() );
    QList<const AttributeRow*> attributes = localeAwareSortRows( it, &AttributeRow::name );

    QString tip = "<table cellspacing=\"3\" cellpadding=\"0\" width=\"400\">";

    tip += "<tr><td><b>";
    tip += QString( "%1: %2" ).arg( TableModelsHelper::formatId( id ), LinkLocator::convertToHtml( issue->name(), 0 ) );
    tip += "</b></td></tr>";

    tip += "<tr><td>";
    tip += tr( "Created by %1 on %2" ).arg( TableModelsHelper::userName( issue->createdUser() ), DateTimeHelper::formatDateTime( issue->createdDate() ) );
    tip += "</td></tr>";

    if ( issue->stamp() > id ) {
        tip += "<tr><td>";
        tip += tr( "Modified by %1 on %2" ).arg( TableModelsHelper::userName( issue->modifiedUser() ), DateTimeHelper::formatDateTime( issue->modifiedDate() ) );
        tip += "</td></tr>";
    }

    tip += "</table><table cellspacing=\"3\" cellpadding=\"0\">";

    for ( int i = 0; i < attributes.count(); i++ ) {
        const AttributeRow* attribute = attributes.at( i );
        const ValueRow* value = dataManager->values()->find( attribute->attributeId(), id );
        if ( value ) {
            tip += "<tr><td>";
            tip += LinkLocator::escape( attribute->name() );
            tip += ":</td><td>";
            tip += LinkLocator::convertToHtml( value->value(), 0 );
            tip += "</td></tr>";
        }
    }

    tip += "</table>";

    return tip;
}

00366 int IssuesTableModel::compare( int id1, int id2, Column column ) const
{
    if ( column == Column_ID )
        return id1 - id2;

    if ( column == Column_CreatedDate || column == Column_ModifiedDate ) {
        const IssueRow* row1 = dataManager->issues()->find( id1 );
        const IssueRow* row2 = dataManager->issues()->find( id2 );

        if ( !row1 || !row2 )
            return 0;

        if ( column == Column_CreatedDate )
            return DateTimeHelper::compareDateTime( row1->createdDate(), row2->createdDate() );
        if ( column == Column_ModifiedDate )
            return DateTimeHelper::compareDateTime( row1->modifiedDate(), row2->modifiedDate() );
    }

    return AbstractTableModel::compare( id1, id2, column );
}

00387 void IssuesTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Folder && e->id() == m_folderId )
        emit tableChanged();

    if ( e->unit() == UpdateEvent::Issue ) {
        const IssueRow* row = dataManager->issues()->find( e->id() );
        if ( row && row->folderId() == m_folderId )
            emit rowChanged( e->id() );
    }

    if ( e->unit() == UpdateEvent::Users )
        emit rowsChanged();
}

00402 AttachmentsTableModel::AttachmentsTableModel( int issueId, QObject* parent ) : AbstractTableModel( parent ),
    m_issueId( issueId )
{
}

00407 AttachmentsTableModel::~AttachmentsTableModel()
{
}

00411 QString AttachmentsTableModel::text( int id, Column column ) const
{
    const AttachmentRow* row = dataManager->attachments()->find( id );
    if ( !row )
        return QString();

    switch ( column ) {
        case Column_Name:
            return row->name();
        case Column_ID:
            return TableModelsHelper::formatId( id );
        case Column_CreatedDate:
            return DateTimeHelper::formatDateTime( row->createdDate() );
        case Column_CreatedBy:
            return TableModelsHelper::userName( row->createdUser() );
        case Column_Size:
            return TableModelsHelper::formatSize( row->size() );
        case Column_Description:
            return row->description();
        default:
            return QString();
    }
}

00435 int AttachmentsTableModel::compare( int id1, int id2, Column column ) const
{
    if ( column == Column_ID )
        return id1 - id2;

    if ( column == Column_Size || column == Column_ModifiedDate ) {
        const AttachmentRow* row1 = dataManager->attachments()->find( id1 );
        const AttachmentRow* row2 = dataManager->attachments()->find( id2 );

        if ( !row1 || !row2 )
            return 0;

        if ( column == Column_Size )
            return row1->size() - row2->size();
        if ( column == Column_CreatedDate )
            return DateTimeHelper::compareDateTime( row1->createdDate(), row2->createdDate() );
    }

    return AbstractTableModel::compare( id1, id2, column );
}

00456 QPixmap AttachmentsTableModel::icon( int id ) const
{
    return IconLoader::pixmap( "file" );
}

00461 void AttachmentsTableModel::updateEvent( UpdateEvent* e )
{
    if ( e->unit() == UpdateEvent::Issue && e->id() == m_issueId )
        emit tableChanged();

    if ( e->unit() == UpdateEvent::Users )
        emit rowsChanged();
}

#include "tablemodels.moc"

Generated by  Doxygen 1.6.0   Back to index