Finished fleshing out MergeView for now.
This commit is contained in:
@@ -140,6 +140,22 @@ MergeFactory::SourceType MergeFactory::idToType( const QString& id )
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Lookup ID from index
|
||||
///
|
||||
QString MergeFactory::indexToId( int index )
|
||||
{
|
||||
QList<QString> ids = mBackendIdMap.keys();
|
||||
|
||||
if ( (index > 0) && (index < ids.size()) )
|
||||
{
|
||||
return ids[index];
|
||||
}
|
||||
|
||||
return "None";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Register backend
|
||||
///
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
static QString idToName( const QString& id );
|
||||
static QString nameToId( const QString& name );
|
||||
static SourceType idToType( const QString& id );
|
||||
static QString indexToId( int index );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
MergeRecord::MergeRecord() : mSelected( false )
|
||||
MergeRecord::MergeRecord() : mSelected( true )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ void MergeText::open()
|
||||
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
|
||||
|
||||
mKeys.clear();
|
||||
mNFieldsMax = 0;
|
||||
|
||||
if ( mLine1HasKeys && mFile.isOpen() )
|
||||
{
|
||||
|
||||
+56
-2
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "LabelModel.h"
|
||||
#include "MergeFactory.h"
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
@@ -54,8 +56,18 @@ void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
|
||||
mModel = model;
|
||||
mUndoRedoModel = undoRedoModel;
|
||||
|
||||
// Initialize CWD
|
||||
if ( model->fileName().isEmpty() )
|
||||
{
|
||||
mCwd = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
mCwd = QFileInfo( model->fileName() ).absolutePath();
|
||||
}
|
||||
|
||||
onMergeChanged();
|
||||
connect( mModel, SIGNAL(changed()), this, SLOT(onMergeChanged()) );
|
||||
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +77,7 @@ void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
|
||||
void MergeView::onMergeChanged()
|
||||
{
|
||||
int index = mMergeFormatNames.indexOf( MergeFactory::idToName( mModel->merge()->id() ) );
|
||||
mOldFormatComboIndex = index;
|
||||
formatCombo->setCurrentIndex( index );
|
||||
|
||||
switch ( MergeFactory::idToType( mModel->merge()->id() ) )
|
||||
@@ -81,7 +94,7 @@ void MergeView::onMergeChanged()
|
||||
locationButton->setEnabled( true );
|
||||
if ( mModel->merge()->source().isEmpty() )
|
||||
{
|
||||
locationButton->setText( "" );
|
||||
locationButton->setText( "Select file..." );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -94,6 +107,8 @@ void MergeView::onMergeChanged()
|
||||
break;
|
||||
}
|
||||
|
||||
recordsTable->clear();
|
||||
recordsTable->setColumnCount( 0 );
|
||||
loadHeaders( mModel->merge() );
|
||||
loadTable( mModel->merge() );
|
||||
|
||||
@@ -109,6 +124,10 @@ void MergeView::onMergeChanged()
|
||||
///
|
||||
void MergeView::onMergeSourceChanged()
|
||||
{
|
||||
locationButton->setText( mModel->merge()->source() );
|
||||
|
||||
recordsTable->clear();
|
||||
recordsTable->setColumnCount( 0 );
|
||||
loadHeaders( mModel->merge() );
|
||||
loadTable( mModel->merge() );
|
||||
}
|
||||
@@ -136,6 +155,38 @@ void MergeView::onMergeSelectionChanged()
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Format combo changed handler
|
||||
void MergeView::onFormatComboActivated()
|
||||
{
|
||||
int index = formatCombo->currentIndex();
|
||||
if ( index != mOldFormatComboIndex )
|
||||
{
|
||||
mOldFormatComboIndex = index;
|
||||
|
||||
mModel->setMerge( MergeFactory::createMerge( MergeFactory::indexToId(index) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Location button clicked handler
|
||||
///
|
||||
void MergeView::onLocationButtonClicked()
|
||||
{
|
||||
QString fileName =
|
||||
QFileDialog::getOpenFileName( this,
|
||||
tr("Select merge file"),
|
||||
mCwd,
|
||||
tr("All files (*)") );
|
||||
if ( !fileName.isEmpty() )
|
||||
{
|
||||
mModel->merge()->setSource( fileName );
|
||||
mCwd = QFileInfo( fileName ).absolutePath(); // Update CWD
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select all button clicked handler
|
||||
///
|
||||
@@ -177,6 +228,8 @@ void MergeView::loadHeaders( Merge* merge )
|
||||
mPrimaryKey = merge->primaryKey();
|
||||
mKeys = merge->keyList();
|
||||
|
||||
if ( mKeys.size() > 0 )
|
||||
{
|
||||
recordsTable->setColumnCount( mKeys.size() + 1 ); // Include extra column
|
||||
|
||||
// First column = primay Key
|
||||
@@ -204,6 +257,7 @@ void MergeView::loadHeaders( Merge* merge )
|
||||
fillItem->setFlags( Qt::NoItemFlags );
|
||||
recordsTable->setHorizontalHeaderItem( iCol, fillItem );
|
||||
recordsTable->horizontalHeader()->setStretchLastSection( true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ private slots:
|
||||
void onMergeSourceChanged();
|
||||
void onMergeSelectionChanged();
|
||||
|
||||
void onFormatComboActivated();
|
||||
void onLocationButtonClicked();
|
||||
void onSelectAllButtonClicked();
|
||||
void onUnselectAllButtonClicked();
|
||||
void onCellChanged( int iRow, int iCol );
|
||||
@@ -85,7 +87,10 @@ private:
|
||||
QStringList mKeys;
|
||||
QString mPrimaryKey;
|
||||
|
||||
QString mCwd;
|
||||
|
||||
bool mBlock;
|
||||
int mOldFormatComboIndex;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -147,11 +147,11 @@
|
||||
<sender>locationButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>MergeView</receiver>
|
||||
<slot>onUnselectAllButtonClicked()</slot>
|
||||
<slot>onLocationButtonClicked()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>175</x>
|
||||
<y>85</y>
|
||||
<x>174</x>
|
||||
<y>93</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>570</x>
|
||||
@@ -163,15 +163,15 @@
|
||||
<sender>formatCombo</sender>
|
||||
<signal>activated(int)</signal>
|
||||
<receiver>MergeView</receiver>
|
||||
<slot>onFormatComboChanged()</slot>
|
||||
<slot>onFormatComboActivated()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>166</x>
|
||||
<x>162</x>
|
||||
<y>48</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>565</x>
|
||||
<y>56</y>
|
||||
<x>563</x>
|
||||
<y>50</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
@@ -180,6 +180,6 @@
|
||||
<slot>onSelectAllButtonClicked()</slot>
|
||||
<slot>onUnselectAllButtonClicked()</slot>
|
||||
<slot>onLocationButtonClicked()</slot>
|
||||
<slot>onFormatComboChanged()</slot>
|
||||
<slot>onFormatComboActivated()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user