本文整理汇总了C++中DataFile::fileName方法的典型用法代码示例。如果您正苦于以下问题:C++ DataFile::fileName方法的具体用法?C++ DataFile::fileName怎么用?C++ DataFile::fileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataFile
的用法示例。
在下文中一共展示了DataFile::fileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
QVariant DocumentModel::data( const QModelIndex &index, int role ) const
{
if( !hasIndex( index.row(), index.column() ) )
return QVariant();
DataFile file = d->b->dataFiles().at( index.row() );
switch( role )
{
case Qt::ForegroundRole:
switch( index.column() )
{
case Size: return QColor(Qt::gray);
default: return QVariant();
}
case Qt::DisplayRole:
switch( index.column() )
{
case Id: return from( file.id() );
case Name: return from( file.fileName() );
case Mime: return from( file.mediaType() );
case Size: return FileDialog::fileSize( file.fileSize() );
default: return QVariant();
}
case Qt::TextAlignmentRole:
switch( index.column() )
{
case Name:
case Mime: return int(Qt::AlignLeft|Qt::AlignVCenter);
case Size: return int(Qt::AlignRight|Qt::AlignVCenter);
default: return Qt::AlignCenter;
}
case Qt::ToolTipRole:
switch( index.column() )
{
case Save: return tr("Save");
case Remove: return tr("Remove");
default: return tr("Filename: %1\nFilesize: %2\nMedia type: %3")
.arg( from( file.fileName() ) )
.arg( FileDialog::fileSize( file.fileSize() ) )
.arg( from( file.mediaType() ) );
}
case Qt::DecorationRole:
switch( index.column() )
{
case Save: return QPixmap(":/images/ico_save.png");
case Remove: return QPixmap(":/images/ico_delete.png");
default: return QVariant();
}
case Qt::SizeHintRole:
switch( index.column() )
{
case Save:
case Remove: return QSize( 20, 20 );
default: return QVariant();
}
default: return QVariant();
}
}
示例2: save
QString DocumentModel::save( const QModelIndex &index, const QString &path ) const
{
if( !hasIndex( index.row(), index.column() ) )
return QString();
DataFile file = d->b->dataFiles().at( index.row() );
QFileInfo info( from( file.fileName() ) );
QString dst = path;
if( dst.isEmpty() )
{
dst = QDir::tempPath() + "/" + info.fileName();
if( QFile::exists( dst ) )
{
for( unsigned int i = 1; i < 100; ++i )
{
dst = QString( "%1/%2_%3.%4").arg( QDir::tempPath() ).arg( info.baseName() ).arg( i ).arg( info.completeSuffix() );
if( !QFile::exists( dst ) )
break;
}
}
}
if( QFileInfo( path ).isDir() )
{
QString filename = info.fileName();
#if defined(Q_OS_WIN)
filename.replace( QRegExp( "[\\\\/*:?\"<>|]" ), "_" );
#else
filename.replace( QRegExp( "[\\\\]"), "_" );
#endif
dst += path.isEmpty() ? filename : QDir::toNativeSeparators( "/" + filename );
}
QFile::remove( dst );
file.saveAs( dst.toUtf8().constData() );
return dst;
}