mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
drag&drop of dictionaries: adds only non-existing dictionaries to group
This commit is contained in:
parent
9d83a95a64
commit
dbbd6a2311
|
@ -120,18 +120,19 @@ QVariant DictListModel::data( QModelIndex const & index, int role ) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
|
// #### Ars: probably there is no more need in this method.
|
||||||
{
|
//bool DictListModel::insertRows( int row, int count, const QModelIndex & parent )
|
||||||
if ( isSource )
|
//{
|
||||||
return false;
|
// if ( isSource )
|
||||||
|
// return false;
|
||||||
beginInsertRows( parent, row, row + count - 1 );
|
//
|
||||||
dictionaries.insert( dictionaries.begin() + row, count,
|
// beginInsertRows( parent, row, row + count - 1 );
|
||||||
sptr< Dictionary::Class >() );
|
// dictionaries.insert( dictionaries.begin() + row, count,
|
||||||
endInsertRows();
|
// sptr< Dictionary::Class >() );
|
||||||
|
// endInsertRows();
|
||||||
return true;
|
//
|
||||||
}
|
// return true;
|
||||||
|
//}
|
||||||
|
|
||||||
bool DictListModel::removeRows( int row, int count,
|
bool DictListModel::removeRows( int row, int count,
|
||||||
const QModelIndex & parent )
|
const QModelIndex & parent )
|
||||||
|
@ -160,24 +161,25 @@ bool DictListModel::setData( QModelIndex const & index, const QVariant & value,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( role == Qt::EditRole )
|
// #### Ars: probably there is no more need in this code.
|
||||||
{
|
// if ( role == Qt::EditRole )
|
||||||
Config::Group g;
|
// {
|
||||||
|
// Config::Group g;
|
||||||
g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
|
//
|
||||||
|
// g.dictionaries.push_back( Config::DictionaryRef( value.toString(), QString() ) );
|
||||||
Instances::Group i( g, *allDicts );
|
//
|
||||||
|
// Instances::Group i( g, *allDicts );
|
||||||
if ( i.dictionaries.size() == 1 )
|
//
|
||||||
{
|
// if ( i.dictionaries.size() == 1 )
|
||||||
// Found that dictionary
|
// {
|
||||||
dictionaries[ index.row() ] = i.dictionaries.front();
|
// // Found that dictionary
|
||||||
|
// dictionaries[ index.row() ] = i.dictionaries.front();
|
||||||
emit dataChanged( index, index );
|
//
|
||||||
|
// emit dataChanged( index, index );
|
||||||
return true;
|
//
|
||||||
}
|
// return true;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -243,6 +245,7 @@ void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source )
|
||||||
if ( allDicts->at( i )->getId() == list.at( j ) )
|
if ( allDicts->at( i )->getId() == list.at( j ) )
|
||||||
{
|
{
|
||||||
dictionaries.push_back( allDicts->at( i ) );
|
dictionaries.push_back( allDicts->at( i ) );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,6 +291,16 @@ std::vector< sptr< Dictionary::Class > > const &
|
||||||
return model.getCurrentDictionaries();
|
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::DictGroupsWidget( QWidget * parent ):
|
DictGroupsWidget::DictGroupsWidget( QWidget * parent ):
|
||||||
|
|
|
@ -29,6 +29,8 @@ public:
|
||||||
|
|
||||||
/// Marks that this model is used as an immutable dictionary source
|
/// Marks that this model is used as an immutable dictionary source
|
||||||
void setAsSource();
|
void setAsSource();
|
||||||
|
bool sourceModel() const { return isSource; }
|
||||||
|
|
||||||
/// Returns the dictionaries the model currently has listed
|
/// Returns the dictionaries the model currently has listed
|
||||||
std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const;
|
std::vector< sptr< Dictionary::Class > > const & getCurrentDictionaries() const;
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ public:
|
||||||
Qt::ItemFlags flags( QModelIndex const &index ) const;
|
Qt::ItemFlags flags( QModelIndex const &index ) const;
|
||||||
int rowCount( QModelIndex const & parent ) const;
|
int rowCount( QModelIndex const & parent ) const;
|
||||||
QVariant data( QModelIndex const & index, int role ) 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 removeRows( int row, int count, const QModelIndex & parent );
|
||||||
bool setData( QModelIndex const & index, const QVariant & value, int role );
|
bool setData( QModelIndex const & index, const QVariant & value, int role );
|
||||||
|
|
||||||
|
@ -73,8 +75,10 @@ public:
|
||||||
DictListModel * getModel()
|
DictListModel * getModel()
|
||||||
{ return & model; }
|
{ return & model; }
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
virtual void dropEvent ( QDropEvent * event );
|
||||||
|
|
||||||
|
private:
|
||||||
DictListModel model;
|
DictListModel model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue