Skip to content

Commit

Permalink
add append/replace buttons to the differences widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed May 13, 2019
1 parent 9039a7f commit 59ffbab
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 8 deletions.
13 changes: 13 additions & 0 deletions qtbleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,10 @@ void QTblEditor::showDifferences()
{
diffWidget = new TablesDifferencesWidget(this, diffType);
connect(diffWidget->listWidget(), SIGNAL(currentTextChanged(const QString &)), _leftTableWidget, SLOT(tableDifferencesItemChanged(const QString &)));
if (!ui.actionSyncScrolling->isChecked())
connect(diffWidget->listWidget(), SIGNAL(currentTextChanged(const QString &)), _rightTableWidget, SLOT(tableDifferencesItemChanged(const QString &)));
connect(diffWidget, SIGNAL(refreshRequested(TablesDifferencesWidget *)), SLOT(refreshDifferences(TablesDifferencesWidget *)));
connect(diffWidget, SIGNAL(modifyTextRequested(bool,bool)), SLOT(modifyText(bool,bool)));
}
diffWidget->addRows(differenceRows);
diffWidget->resize(diffWidget->sizeHint());
Expand All @@ -1415,6 +1418,16 @@ void QTblEditor::refreshDifferences(TablesDifferencesWidget *w)
w->addRows(differentStrings(w->diffType()));
}

void QTblEditor::modifyText(bool fromLeftToRight, bool append)
{
QTableWidget *acceptor = fromLeftToRight ? _rightTableWidget : _leftTableWidget, *donor = inactiveTableWidget(acceptor);
QTableWidgetItem *acceptorItem = acceptor->item(acceptor->currentRow(), 1);
QString prefix;
if (append)
prefix = acceptorItem->text();
acceptorItem->setText(prefix + donor->item(donor->currentRow(), 1)->text());
}

void QTblEditor::syncScrollingChanged(bool isSyncing)
{
QScrollBar *leftScrollbar = _leftTableWidget->verticalScrollBar(), *rightScrollbar = _rightTableWidget->verticalScrollBar();
Expand Down
1 change: 1 addition & 0 deletions qtbleditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private slots:
void updateWindow(bool isModified = true);
void updateItem(QTableWidgetItem *item);
void refreshDifferences(TablesDifferencesWidget *w);
void modifyText(bool fromLeftToRight, bool append);

private:
Ui::QTblEditorClass ui;
Expand Down
54 changes: 48 additions & 6 deletions tablesdifferenceswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,60 @@ TablesDifferencesWidget::TablesDifferencesWidget(QWidget *parent, DiffType diffT
setWindowFlags(Qt::Tool);
setAttribute(Qt::WA_DeleteOnClose);

if (diffType == TablesDifferencesWidget::Keys)
setWindowTitle(tr("Different keys"));
else if (diffType == TablesDifferencesWidget::Strings)
setWindowTitle(tr("Different strings"));
else
setWindowTitle(tr("Different keys & strings"));
QString title;
switch (diffType)
{
case TablesDifferencesWidget::Keys:
title = tr("Different keys");
break;
case TablesDifferencesWidget::Strings:
title = tr("Different strings");
break;
case TablesDifferencesWidget::KeysOrStrings:
title = tr("Different keys & strings");
break;
case TablesDifferencesWidget::SameStrings:
title = tr("Same strings");
break;
default:
break;
}
setWindowTitle(title);

connect(ui.refreshButton, SIGNAL(clicked()), SLOT(refreshButtonClicked()));
foreach (QPushButton *b, QList<QPushButton *>() << ui.replaceL2RButton << ui.replaceR2LButton << ui.appendL2RButton << ui.appendR2LButton)
connect(b, SIGNAL(clicked()), SLOT(modifyTextClicked()));
}

void TablesDifferencesWidget::addRows(const QStringList &rowStrings)
{
ui.rowsListWidget->addItems(rowStrings);
ui.rowsListWidget->setToolTip(QString("%1 items").arg(rowStrings.size()));
}

void TablesDifferencesWidget::modifyTextClicked()
{
bool fromLeftToRight, append;
QPushButton *b = qobject_cast<QPushButton *>(sender());
if (b == ui.replaceL2RButton)
{
fromLeftToRight = true;
append = false;
}
else if (b == ui.replaceR2LButton)
{
fromLeftToRight = false;
append = false;
}
else if (b == ui.appendL2RButton)
{
fromLeftToRight = true;
append = true;
}
else // appendR2LButton
{
fromLeftToRight = false;
append = true;
}
emit modifyTextRequested(fromLeftToRight, append);
}
2 changes: 2 additions & 0 deletions tablesdifferenceswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class TablesDifferencesWidget : public QWidget

signals:
void refreshRequested(TablesDifferencesWidget *w);
void modifyTextRequested(bool fromLeftToRight, bool append);

private slots:
void refreshButtonClicked() { emit refreshRequested(this); }
void modifyTextClicked();

private:
Ui::TablesDifferencesWidget ui;
Expand Down
36 changes: 34 additions & 2 deletions tablesdifferenceswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>102</width>
<height>253</height>
<width>244</width>
<height>360</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -34,6 +34,38 @@
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="replaceL2RButton">
<property name="text">
<string>Replace →</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="replaceR2LButton">
<property name="text">
<string>Replace ←</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="appendL2RButton">
<property name="text">
<string>Append →</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="appendR2LButton">
<property name="text">
<string>Append ←</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit 59ffbab

Please sign in to comment.