@ -10,6 +10,7 @@
# include <QGridLayout>
# include <QGridLayout>
# include <QMessageBox>
# include <QMessageBox>
# include <QModelIndex>
# include <QModelIndex>
# include <QDir>
# include <assert.h>
# include <assert.h>
ContentSelectorView : : ContentSelector : : ContentSelector ( QWidget * parent ) :
ContentSelectorView : : ContentSelector : : ContentSelector ( QWidget * parent ) :
@ -33,13 +34,7 @@ void ContentSelectorView::ContentSelector::buildGameFileView()
{
{
ui . gameFileView - > setVisible ( true ) ;
ui . gameFileView - > setVisible ( true ) ;
mGameFileProxyModel = new QSortFilterProxyModel ( this ) ;
mGameFileProxyModel - > setFilterRegExp ( QString : : number ( ( int ) ContentSelectorModel : : ContentType_GameFile ) ) ;
mGameFileProxyModel - > setFilterRole ( Qt : : UserRole ) ;
mGameFileProxyModel - > setSourceModel ( mContentModel ) ;
ui . gameFileView - > setPlaceholderText ( QString ( " Select a game file... " ) ) ;
ui . gameFileView - > setPlaceholderText ( QString ( " Select a game file... " ) ) ;
ui . gameFileView - > setModel ( mGameFileProxyModel ) ;
connect ( ui . gameFileView , SIGNAL ( currentIndexChanged ( int ) ) ,
connect ( ui . gameFileView , SIGNAL ( currentIndexChanged ( int ) ) ,
this , SLOT ( slotCurrentGameFileIndexChanged ( int ) ) ) ;
this , SLOT ( slotCurrentGameFileIndexChanged ( int ) ) ) ;
@ -129,6 +124,15 @@ void ContentSelectorView::ContentSelector::addFiles(const QString &path)
{
{
mContentModel - > addFiles ( path ) ;
mContentModel - > addFiles ( path ) ;
// add any game files to the combo box
foreach ( const QString gameFileName , mContentModel - > gameFiles ( ) )
{
if ( ui . gameFileView - > findText ( gameFileName ) = = - 1 )
{
ui . gameFileView - > addItem ( gameFileName ) ;
}
}
if ( ui . gameFileView - > currentIndex ( ) ! = - 1 )
if ( ui . gameFileView - > currentIndex ( ) ! = - 1 )
ui . gameFileView - > setCurrentIndex ( - 1 ) ;
ui . gameFileView - > setCurrentIndex ( - 1 ) ;
@ -150,29 +154,33 @@ void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int i
{
{
static int oldIndex = - 1 ;
static int oldIndex = - 1 ;
QAbstractItemModel * const model = ui . gameFileView - > model ( ) ;
QSortFilterProxyModel * proxy = dynamic_cast < QSortFilterProxyModel * > ( model ) ;
if ( proxy )
proxy - > setDynamicSortFilter ( false ) ;
if ( index ! = oldIndex )
if ( index ! = oldIndex )
{
{
if ( oldIndex > - 1 )
if ( oldIndex > - 1 )
model - > setData ( model - > index ( oldIndex , 0 ) , false , Qt : : UserRole + 1 ) ;
{
setGameFileSelected ( oldIndex , false ) ;
}
oldIndex = index ;
oldIndex = index ;
model- > setData ( model - > index ( index , 0 ) , true , Qt : : UserRole + 1 ) ;
setGameFileSelected( index , true ) ;
mContentModel - > checkForLoadOrderErrors ( ) ;
mContentModel - > checkForLoadOrderErrors ( ) ;
}
}
if ( proxy )
proxy - > setDynamicSortFilter ( true ) ;
emit signalCurrentGamefileIndexChanged ( index ) ;
emit signalCurrentGamefileIndexChanged ( index ) ;
}
}
void ContentSelectorView : : ContentSelector : : setGameFileSelected ( int index , bool selected )
{
QString fileName = ui . gameFileView - > itemText ( index ) ;
const ContentSelectorModel : : EsmFile * file = mContentModel - > item ( fileName ) ;
if ( file ! = NULL )
{
QModelIndex index ( mContentModel - > indexFromItem ( file ) ) ;
mContentModel - > setData ( index , selected , Qt : : UserRole + 1 ) ;
}
}
void ContentSelectorView : : ContentSelector : : slotAddonTableItemActivated ( const QModelIndex & index )
void ContentSelectorView : : ContentSelector : : slotAddonTableItemActivated ( const QModelIndex & index )
{
{
QModelIndex sourceIndex = mAddonProxyModel - > mapToSource ( index ) ;
QModelIndex sourceIndex = mAddonProxyModel - > mapToSource ( index ) ;