drag&drop of dictionaries: adds only non-existing dictionaries to group

This commit is contained in:
ars_goldendict 2009-05-02 19:57:52 +00:00
parent 9d83a95a64
commit dbbd6a2311
2 changed files with 49 additions and 32 deletions

View file

@ -120,18 +120,19 @@ QVariant DictListModel::data( QModelIndex const & index, int role ) const
return QVariant();
}
bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
{
if ( isSource )
return false;
beginInsertRows( parent, row, row + count - 1 );
dictionaries.insert( dictionaries.begin() + row, count,
sptr< Dictionary::Class >() );
endInsertRows();
return true;
}
// #### Ars: probably there is no more need in this method.
//bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
//{
// if ( isSource )
// return false;
//
// beginInsertRows( parent, row, row + count - 1 );
// dictionaries.insert( dictionaries.begin() + row, count,
// sptr< Dictionary::Class >() );
// endInsertRows();
//
// return true;
//}
bool DictListModel::removeRows( int row, int count,
const QModelIndex & parent )
@ -160,24 +161,25 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value,
return true;
}
if ( role == Qt::EditRole )
{
Config::Group g;
g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
Instances::Group i( g, *allDicts );
if ( i.dictionaries.size() == 1 )
{
// Found that dictionary
dictionaries[ index.row() ] = i.dictionaries.front();
emit dataChanged( index, index );
return true;
}
}
// #### Ars: probably there is no more need in this code.
// if ( role == Qt::EditRole )
// {
// Config::Group g;
//
// g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
//
// Instances::Group i( g, *allDicts );
//
// if ( i.dictionaries.size() == 1 )
// {
// // Found that dictionary
// dictionaries[ index.row() ] = i.dictionaries.front();
//
// emit dataChanged( index, index );
//
// return true;
// }
// }
return false;
}
@ -243,6 +245,7 @@ void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source )
if ( allDicts->at( i )->getId() == list.at( j ) )
{
dictionaries.push_back( allDicts->at( i ) );
break;
}
}
}
@ -288,6 +291,16 @@ std::vector< sptr< Dictionary::Class > > const &
return model.getCurrentDictionaries();
}
void DictListWidget::dropEvent ( QDropEvent * event )
{
DictListWidget * sourceList = dynamic_cast< DictListWidget* > ( event->source() );
if ( sourceList && sourceList->model.sourceModel() )
{
model.addSelectedUniqueFromModel( sourceList->selectionModel() );
}
}
// DictGroupsWidget
DictGroupsWidget::DictGroupsWidget( QWidget * parent ):

View file

@ -29,6 +29,8 @@ public:
/// Marks that this model is used as an immutable dictionary source
void setAsSource();
bool sourceModel() const { return isSource; }
/// Returns the dictionaries the model currently has listed
std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const;
@ -38,7 +40,7 @@ public:
Qt::ItemFlags flags( QModelIndex const &index ) const;
int rowCount( QModelIndex const & parent ) const;
QVariant data( QModelIndex const & index, int role ) const;
bool insertRows( int row, int count, const QModelIndex & parent );
//bool insertRows( int row, int count, const QModelIndex & parent );
bool removeRows( int row, int count, const QModelIndex & parent );
bool setData( QModelIndex const & index, const QVariant & value, int role );
@ -73,8 +75,10 @@ public:
DictListModel * getModel()
{ return & model; }
private:
protected:
virtual void dropEvent ( QDropEvent * event );
private:
DictListModel model;
};