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
|
/// Register backend
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public:
|
|||||||
static QString idToName( const QString& id );
|
static QString idToName( const QString& id );
|
||||||
static QString nameToId( const QString& name );
|
static QString nameToId( const QString& name );
|
||||||
static SourceType idToType( const QString& id );
|
static SourceType idToType( const QString& id );
|
||||||
|
static QString indexToId( int index );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
///
|
///
|
||||||
/// Constructor
|
/// Constructor
|
||||||
///
|
///
|
||||||
MergeRecord::MergeRecord() : mSelected( false )
|
MergeRecord::MergeRecord() : mSelected( true )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ void MergeText::open()
|
|||||||
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
|
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
|
||||||
|
|
||||||
mKeys.clear();
|
mKeys.clear();
|
||||||
|
mNFieldsMax = 0;
|
||||||
|
|
||||||
if ( mLine1HasKeys && mFile.isOpen() )
|
if ( mLine1HasKeys && mFile.isOpen() )
|
||||||
{
|
{
|
||||||
|
|||||||
+56
-2
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "LabelModel.h"
|
#include "LabelModel.h"
|
||||||
#include "MergeFactory.h"
|
#include "MergeFactory.h"
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileInfo>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
@@ -54,8 +56,18 @@ void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
|
|||||||
mModel = model;
|
mModel = model;
|
||||||
mUndoRedoModel = undoRedoModel;
|
mUndoRedoModel = undoRedoModel;
|
||||||
|
|
||||||
|
// Initialize CWD
|
||||||
|
if ( model->fileName().isEmpty() )
|
||||||
|
{
|
||||||
|
mCwd = ".";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mCwd = QFileInfo( model->fileName() ).absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
onMergeChanged();
|
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()
|
void MergeView::onMergeChanged()
|
||||||
{
|
{
|
||||||
int index = mMergeFormatNames.indexOf( MergeFactory::idToName( mModel->merge()->id() ) );
|
int index = mMergeFormatNames.indexOf( MergeFactory::idToName( mModel->merge()->id() ) );
|
||||||
|
mOldFormatComboIndex = index;
|
||||||
formatCombo->setCurrentIndex( index );
|
formatCombo->setCurrentIndex( index );
|
||||||
|
|
||||||
switch ( MergeFactory::idToType( mModel->merge()->id() ) )
|
switch ( MergeFactory::idToType( mModel->merge()->id() ) )
|
||||||
@@ -81,7 +94,7 @@ void MergeView::onMergeChanged()
|
|||||||
locationButton->setEnabled( true );
|
locationButton->setEnabled( true );
|
||||||
if ( mModel->merge()->source().isEmpty() )
|
if ( mModel->merge()->source().isEmpty() )
|
||||||
{
|
{
|
||||||
locationButton->setText( "" );
|
locationButton->setText( "Select file..." );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -94,6 +107,8 @@ void MergeView::onMergeChanged()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recordsTable->clear();
|
||||||
|
recordsTable->setColumnCount( 0 );
|
||||||
loadHeaders( mModel->merge() );
|
loadHeaders( mModel->merge() );
|
||||||
loadTable( mModel->merge() );
|
loadTable( mModel->merge() );
|
||||||
|
|
||||||
@@ -109,6 +124,10 @@ void MergeView::onMergeChanged()
|
|||||||
///
|
///
|
||||||
void MergeView::onMergeSourceChanged()
|
void MergeView::onMergeSourceChanged()
|
||||||
{
|
{
|
||||||
|
locationButton->setText( mModel->merge()->source() );
|
||||||
|
|
||||||
|
recordsTable->clear();
|
||||||
|
recordsTable->setColumnCount( 0 );
|
||||||
loadHeaders( mModel->merge() );
|
loadHeaders( mModel->merge() );
|
||||||
loadTable( 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
|
/// Select all button clicked handler
|
||||||
///
|
///
|
||||||
@@ -177,6 +228,8 @@ void MergeView::loadHeaders( Merge* merge )
|
|||||||
mPrimaryKey = merge->primaryKey();
|
mPrimaryKey = merge->primaryKey();
|
||||||
mKeys = merge->keyList();
|
mKeys = merge->keyList();
|
||||||
|
|
||||||
|
if ( mKeys.size() > 0 )
|
||||||
|
{
|
||||||
recordsTable->setColumnCount( mKeys.size() + 1 ); // Include extra column
|
recordsTable->setColumnCount( mKeys.size() + 1 ); // Include extra column
|
||||||
|
|
||||||
// First column = primay Key
|
// First column = primay Key
|
||||||
@@ -205,6 +258,7 @@ void MergeView::loadHeaders( Merge* merge )
|
|||||||
recordsTable->setHorizontalHeaderItem( iCol, fillItem );
|
recordsTable->setHorizontalHeaderItem( iCol, fillItem );
|
||||||
recordsTable->horizontalHeader()->setStretchLastSection( true );
|
recordsTable->horizontalHeader()->setStretchLastSection( true );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ private slots:
|
|||||||
void onMergeSourceChanged();
|
void onMergeSourceChanged();
|
||||||
void onMergeSelectionChanged();
|
void onMergeSelectionChanged();
|
||||||
|
|
||||||
|
void onFormatComboActivated();
|
||||||
|
void onLocationButtonClicked();
|
||||||
void onSelectAllButtonClicked();
|
void onSelectAllButtonClicked();
|
||||||
void onUnselectAllButtonClicked();
|
void onUnselectAllButtonClicked();
|
||||||
void onCellChanged( int iRow, int iCol );
|
void onCellChanged( int iRow, int iCol );
|
||||||
@@ -85,7 +87,10 @@ private:
|
|||||||
QStringList mKeys;
|
QStringList mKeys;
|
||||||
QString mPrimaryKey;
|
QString mPrimaryKey;
|
||||||
|
|
||||||
|
QString mCwd;
|
||||||
|
|
||||||
bool mBlock;
|
bool mBlock;
|
||||||
|
int mOldFormatComboIndex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -147,11 +147,11 @@
|
|||||||
<sender>locationButton</sender>
|
<sender>locationButton</sender>
|
||||||
<signal>clicked()</signal>
|
<signal>clicked()</signal>
|
||||||
<receiver>MergeView</receiver>
|
<receiver>MergeView</receiver>
|
||||||
<slot>onUnselectAllButtonClicked()</slot>
|
<slot>onLocationButtonClicked()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>175</x>
|
<x>174</x>
|
||||||
<y>85</y>
|
<y>93</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>570</x>
|
<x>570</x>
|
||||||
@@ -163,15 +163,15 @@
|
|||||||
<sender>formatCombo</sender>
|
<sender>formatCombo</sender>
|
||||||
<signal>activated(int)</signal>
|
<signal>activated(int)</signal>
|
||||||
<receiver>MergeView</receiver>
|
<receiver>MergeView</receiver>
|
||||||
<slot>onFormatComboChanged()</slot>
|
<slot>onFormatComboActivated()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>166</x>
|
<x>162</x>
|
||||||
<y>48</y>
|
<y>48</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>565</x>
|
<x>563</x>
|
||||||
<y>56</y>
|
<y>50</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
@@ -180,6 +180,6 @@
|
|||||||
<slot>onSelectAllButtonClicked()</slot>
|
<slot>onSelectAllButtonClicked()</slot>
|
||||||
<slot>onUnselectAllButtonClicked()</slot>
|
<slot>onUnselectAllButtonClicked()</slot>
|
||||||
<slot>onLocationButtonClicked()</slot>
|
<slot>onLocationButtonClicked()</slot>
|
||||||
<slot>onFormatComboChanged()</slot>
|
<slot>onFormatComboActivated()</slot>
|
||||||
</slots>
|
</slots>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user