#include "pivaluetree_edit_reorder.h"

#include "piqt.h"


PIValueTreeEditReorder::PIValueTreeEditReorder(QWidget * parent): QDialog(parent) {
	setupUi(this);
}


PIValueTreeEditReorder::~PIValueTreeEditReorder() {}


bool PIValueTreeEditReorder::showFor(PIValueTree & vt) {
	setWindowTitle(tr("Reorder of \"%1\"").arg(PI2QString(vt.name())));

	PIStringList old_list;
	for (const auto & c: vt.children())
		old_list << c.name();
	listWidget->clear();
	listWidget->addItems(PI2QStringList(old_list));

	if (exec() != QDialog::Accepted) return false;

	map.clear();
	for (int i = 0; i < listWidget->count(); ++i)
		map[i] = old_list.indexOf(Q2PIString(listWidget->item(i)->text()));

	return true;
}
