You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
402 lines
12 KiB
402 lines
12 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
|
||
|
Copyright 2004 Laurent Montel <montel@kde.org>
|
||
|
|
||
|
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., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kspread_genvalidationstyle.h"
|
||
|
#include "kspread_cell.h"
|
||
|
#include <KoXmlWriter.h>
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
|
GenValidationStyles::GenValidationStyles()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
GenValidationStyles::~GenValidationStyles()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyles::lookup( const GenValidationStyle& style )
|
||
15 years ago
|
{
|
||
14 years ago
|
StyleMap::iterator it = m_styles.find( style );
|
||
15 years ago
|
if ( it == m_styles.end() ) {
|
||
|
|
||
14 years ago
|
TQString styleName( "val" );
|
||
15 years ago
|
styleName = makeUniqueName( styleName );
|
||
|
m_names.insert( styleName, true );
|
||
|
it = m_styles.insert( style, styleName );
|
||
|
}
|
||
|
return it.data();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyles::makeUniqueName( const TQString& base ) const
|
||
15 years ago
|
{
|
||
|
int num = 1;
|
||
14 years ago
|
TQString name;
|
||
15 years ago
|
do {
|
||
|
name = base;
|
||
14 years ago
|
name += TQString::number( num++ );
|
||
14 years ago
|
} while ( m_names.find( name ) != m_names.end() );
|
||
15 years ago
|
return name;
|
||
|
}
|
||
|
|
||
|
void GenValidationStyles::writeStyle( KoXmlWriter& writer )
|
||
|
{
|
||
|
if ( m_styles.count()>0 )
|
||
|
{
|
||
|
writer.startElement( "table:content-validations" );
|
||
|
StyleMap::Iterator it;
|
||
|
for ( it = m_styles.begin(); it != m_styles.end(); ++it )
|
||
|
{
|
||
|
writer.startElement( "table:content-validation" );
|
||
|
writer.addAttribute( "table:name", it.data() );
|
||
|
writer.addAttribute( "table:allow-empty-cell", it.key().allowEmptyCell );
|
||
|
writer.addAttribute( "table:condition", it.key().condition );
|
||
|
|
||
|
writer.startElement( "table:help-message" );
|
||
|
writer.addAttribute( "table:title", it.key().title );
|
||
|
writer.addAttribute( "table:display", it.key().displayValidationInformation );
|
||
|
|
||
14 years ago
|
TQStringList text = TQStringList::split( "\n", it.key().messageInfo );
|
||
|
for ( TQStringList::Iterator it2 = text.begin(); it2 != text.end(); ++it2 ) {
|
||
15 years ago
|
writer.startElement( "text:p" );
|
||
|
writer.addTextNode( *it2 );
|
||
|
writer.endElement();
|
||
|
}
|
||
|
writer.endElement();
|
||
|
|
||
|
writer.startElement( "table:error-message" );
|
||
|
writer.addAttribute( "table:message-type", it.key().messageType );
|
||
|
|
||
|
writer.addAttribute("table:title", it.key().titleInfo);
|
||
|
writer.addAttribute("table:display", it.key().displayMessage);
|
||
14 years ago
|
text = TQStringList::split( "\n", it.key().message );
|
||
|
for ( TQStringList::Iterator it3 = text.begin(); it3 != text.end(); ++it3 ) {
|
||
15 years ago
|
writer.startElement( "text:p" );
|
||
|
writer.addTextNode( *it3 );
|
||
|
writer.endElement();
|
||
|
}
|
||
|
writer.endElement();
|
||
|
|
||
|
writer.endElement();
|
||
|
}
|
||
|
writer.endElement();//close sheet:content-validation
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void GenValidationStyle::initVal( Validity *_val )
|
||
|
{
|
||
|
if ( _val )
|
||
|
{
|
||
|
allowEmptyCell = ( _val->allowEmptyCell ? "true" : "false" );
|
||
|
condition = createValidationCondition( _val );
|
||
|
title = _val->title;
|
||
|
displayValidationInformation = ( _val->displayValidationInformation ? "true" : "false" );
|
||
|
messageInfo = _val->messageInfo;
|
||
|
|
||
|
switch( _val->m_action )
|
||
|
{
|
||
|
case Action::Warning:
|
||
|
messageType = "warning";
|
||
|
break;
|
||
|
case Action::Information:
|
||
|
messageType = "information";
|
||
|
break;
|
||
|
case Action::Stop:
|
||
|
messageType = "stop";
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
titleInfo = _val->titleInfo;
|
||
|
displayMessage = ( _val->displayMessage ? "true" : "false" );
|
||
|
message = _val->message;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result;
|
||
15 years ago
|
switch( _val->m_restriction )
|
||
|
{
|
||
|
case Restriction::None:
|
||
|
//nothing
|
||
|
break;
|
||
|
case Restriction::Text:
|
||
|
//doesn't exist into oo spec
|
||
|
result = "cell-content-is-text()";
|
||
|
break;
|
||
|
case Restriction::Time:
|
||
|
result = createTimeValidationCondition( _val );
|
||
|
break;
|
||
|
case Restriction::Date:
|
||
|
result = createDateValidationCondition( _val );
|
||
|
break;
|
||
|
case Restriction::Integer:
|
||
|
case Restriction::Number:
|
||
|
result = createNumberValidationCondition( _val );
|
||
|
break;
|
||
|
case Restriction::TextLength:
|
||
|
result = createTextValidationCondition( _val );
|
||
|
break;
|
||
|
case Restriction::List:
|
||
|
result = createListValidationCondition( _val );
|
||
|
break;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createListValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result = "oooc:cell-content-is-in-list(";
|
||
15 years ago
|
result = _val->listValidity.join( ";" );
|
||
|
result +=")";
|
||
|
return result;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createNumberValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result;
|
||
15 years ago
|
if ( _val->m_restriction == Restriction::Number )
|
||
|
result = "oooc:cell-content-is-whole-number() and ";
|
||
|
else if ( _val->m_restriction == Restriction::Integer )
|
||
|
result = "oooc:cell-content-is-decimal-number() and ";
|
||
|
switch( _val->m_cond )
|
||
|
{
|
||
|
case Conditional::None:
|
||
|
//nothing
|
||
|
break;
|
||
|
case Conditional::Equal:
|
||
|
result+="cell-content()";
|
||
|
result+="=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Superior:
|
||
|
result+="cell-content()";
|
||
|
result+=">";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Inferior:
|
||
|
result+="cell-content()";
|
||
|
result+="<";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::SuperiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+=">=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::InferiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+="<=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Different:
|
||
|
result+="cell-content()";
|
||
|
result+="!=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Between:
|
||
|
result+="cell-content-is-between(";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
result+=",";
|
||
14 years ago
|
result+=TQString::number( _val->valMax );
|
||
15 years ago
|
result+=")";
|
||
|
break;
|
||
|
case Conditional::DifferentTo:
|
||
|
result+="cell-content-is-not-between(";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
result+=",";
|
||
14 years ago
|
result+=TQString::number( _val->valMax );
|
||
15 years ago
|
result+=")";
|
||
|
break;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createTimeValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result( "oooc:cell-content-is-time() and " );
|
||
15 years ago
|
switch( _val->m_cond )
|
||
|
{
|
||
|
case Conditional::None:
|
||
|
//nothing
|
||
|
break;
|
||
|
case Conditional::Equal:
|
||
|
result+="cell-content()";
|
||
|
result+="=";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::Superior:
|
||
|
result+="cell-content()";
|
||
|
result+=">";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::Inferior:
|
||
|
result+="cell-content()";
|
||
|
result+="<";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::SuperiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+=">=";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::InferiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+="<=";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::Different:
|
||
|
result+="cell-content()";
|
||
|
result+="!=";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
break;
|
||
|
case Conditional::Between:
|
||
|
result+="cell-content-is-between(";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
result+=",";
|
||
|
result+=_val->timeMax.toString( );
|
||
|
result+=")";
|
||
|
break;
|
||
|
case Conditional::DifferentTo:
|
||
|
result+="cell-content-is-not-between(";
|
||
|
result+=_val->timeMin.toString( );
|
||
|
result+=",";
|
||
|
result+=_val->timeMax.toString( );
|
||
|
result+=")";
|
||
|
break;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createDateValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result( "oooc:cell-content-is-date() and " );
|
||
15 years ago
|
switch( _val->m_cond )
|
||
|
{
|
||
|
case Conditional::None:
|
||
|
//nothing
|
||
|
break;
|
||
|
case Conditional::Equal:
|
||
|
result+="cell-content()";
|
||
|
result+="=";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::Superior:
|
||
|
result+="cell-content()";
|
||
|
result+=">";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::Inferior:
|
||
|
result+="cell-content()";
|
||
|
result+="<";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::SuperiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+=">=";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::InferiorEqual:
|
||
|
result+="cell-content()";
|
||
|
result+="<=";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::Different:
|
||
|
result+="cell-content()";
|
||
|
result+="!=";
|
||
|
result+=_val->dateMin.toString();
|
||
|
break;
|
||
|
case Conditional::Between:
|
||
|
result+="cell-content-is-between(";
|
||
|
result+=_val->dateMin.toString();
|
||
|
result+=",";
|
||
|
result+=_val->dateMax.toString();
|
||
|
result+=")";
|
||
|
break;
|
||
|
case Conditional::DifferentTo:
|
||
|
result+="cell-content-is-not-between(";
|
||
|
result+=_val->dateMin.toString();
|
||
|
result+=",";
|
||
|
result+=_val->dateMax.toString();
|
||
|
result+=")";
|
||
|
break;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString GenValidationStyle::createTextValidationCondition( Validity* _val )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString result;
|
||
15 years ago
|
switch( _val->m_cond )
|
||
|
{
|
||
|
case Conditional::None:
|
||
|
//nothing
|
||
|
break;
|
||
|
case Conditional::Equal:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+="=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Superior:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+=">";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Inferior:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+="<";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::SuperiorEqual:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+=">=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::InferiorEqual:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+="<=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Different:
|
||
|
result+="oooc:cell-content-text-length()";
|
||
|
result+="!=";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
break;
|
||
|
case Conditional::Between:
|
||
|
result+="oooc:cell-content-text-length-is-between(";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
result+=",";
|
||
14 years ago
|
result+=TQString::number( _val->valMax );
|
||
15 years ago
|
result+=")";
|
||
|
break;
|
||
|
case Conditional::DifferentTo:
|
||
|
result+="oooc:cell-content-text-length-is-not-between(";
|
||
14 years ago
|
result+=TQString::number( _val->valMin );
|
||
15 years ago
|
result+=",";
|
||
14 years ago
|
result+=TQString::number( _val->valMax );
|
||
15 years ago
|
result+=")";
|
||
|
break;
|
||
|
}
|
||
|
return result;
|
||
|
}
|