[rkward/work/optionset_experiments] rkward: Clean up a lot of code that is no longer needed for the optionset

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Oct 29 19:54:33 UTC 2015


Git commit 942831bf09aaac226bec2a9af2b30860b82a1ef8 by Thomas Friedrichsmeier.
Committed on 29/10/2015 at 19:24.
Pushed by tfry into branch 'work/optionset_experiments'.

Clean up a lot of code that is no longer needed for the optionset

M  +1    -1    rkward/misc/rkaccordiontable.cpp
M  +24   -122  rkward/plugin/rkoptionset.cpp
M  +2    -26   rkward/plugin/rkoptionset.h
M  +1    -1    rkward/plugin/rkstandardcomponent.cpp

http://commits.kde.org/rkward/942831bf09aaac226bec2a9af2b30860b82a1ef8

diff --git a/rkward/misc/rkaccordiontable.cpp b/rkward/misc/rkaccordiontable.cpp
index d64f201..057edf9 100644
--- a/rkward/misc/rkaccordiontable.cpp
+++ b/rkward/misc/rkaccordiontable.cpp
@@ -477,7 +477,7 @@ void RKAccordionTable::setModel (QAbstractItemModel* model) {
 
 
 // TODO
-// - index column, and sets without manual add / remove
+// - index column, RKOptionSet::display_show_index
 // - expand / collapse indicator?
 // - drag-reordering?
 //   - will this make per-item add buttons obsolete?
diff --git a/rkward/plugin/rkoptionset.cpp b/rkward/plugin/rkoptionset.cpp
index 07abf93..b3a2b3d 100644
--- a/rkward/plugin/rkoptionset.cpp
+++ b/rkward/plugin/rkoptionset.cpp
@@ -45,24 +45,23 @@ RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_compon
 	updating = false;
 	last_known_status = Processing;
 	n_invalid_rows = n_unfinished_rows = 0;
+	display_show_index = false;
 
 	min_rows = xml->getIntAttribute (element, "min_rows", 0, DL_INFO);
 	min_rows_if_any = xml->getIntAttribute (element, "min_rows_if_any", 1, DL_INFO);
 	max_rows = xml->getIntAttribute (element, "max_rows", INT_MAX, DL_INFO);
-	exp_mode = (ExperimentalMode) xml->getMultiChoiceAttribute (element, "exp_mode", "regular;detached;accordion", 2, DL_INFO);
 
 	// build UI framework
 	QVBoxLayout *layout = new QVBoxLayout (this);
-	switcher = new QStackedWidget (exp_mode == Detached ? 0 : this);
-	if (exp_mode != Detached) layout->addWidget (switcher);
-	user_area = new KVBox (this);
-	switcher->addWidget (user_area);
-	if (exp_mode == Accordion) {
-		accordion = new RKAccordionTable (user_area);
-		connect (accordion, SIGNAL (activated(int)), this, SLOT(currentRowChanged(int)));
-		connect (accordion, SIGNAL (addRow(int)), this, SLOT(addRow(int)));
-		connect (accordion, SIGNAL (removeRow(int)), this, SLOT(removeRow(int)));
-	}
+	switcher = new QStackedWidget (this);
+	layout->addWidget (switcher);
+	accordion = new RKAccordionTable (this);
+	switcher->addWidget (accordion);
+
+	connect (accordion, SIGNAL (activated(int)), this, SLOT(currentRowChanged(int)));
+	connect (accordion, SIGNAL (addRow(int)), this, SLOT(addRow(int)));
+	connect (accordion, SIGNAL (removeRow(int)), this, SLOT(removeRow(int)));
+
 	updating_notice = new QLabel (i18n ("Updating status, please wait"), this);
 	switcher->addWidget (updating_notice);
 	update_timer.setInterval (0);
@@ -84,12 +83,11 @@ RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_compon
 	connect (current_row, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (currentRowPropertyChanged(RKComponentPropertyBase*)));
 
 	// first build the contents, as we will need to refer to the elements inside, later
-	model = 0;
-	display = 0;	// will be created from the builder, on demand -> createDisplay ()
-	contents_container = new RKComponent (this, exp_mode == RKOptionSet::Accordion ? accordion->editorWidget () : user_area);
+	model = new RKOptionSetDisplayModel (this);
+	contents_container = new RKComponent (this, accordion->editorWidget ());
 	QDomElement content_element = xml->getChildElement (element, "content", DL_ERROR);
 	RKComponentBuilder *builder = new RKComponentBuilder (contents_container, content_element);
-	builder->buildElement (content_element, *xml, exp_mode == Accordion ? accordion->editorWidget () : user_area, false);	// NOTE that parent widget != parent component, here, by intention. The point is that the display should not be disabled along with the contents
+	builder->buildElement (content_element, *xml, accordion->editorWidget (), false);	// NOTE that parent widget != parent component, here, by intention. The point is that the display should not be disabled along with the contents
 	builder->parseLogic (xml->getChildElement (element, "logic", DL_INFO), *xml, false);
 	builder->makeConnections ();
 	addChild ("contents", contents_container);
@@ -174,30 +172,9 @@ RKOptionSet::RKOptionSet (const QDomElement &element, RKComponent *parent_compon
 		}
 	}
 
-	if (display) {		// may or may not have been created
-		model->column_labels = visible_column_labels;
-		display->setItemsExpandable (false);
-		display->setRootIsDecorated (false);
-		display->setAlternatingRowColors (true);
-		if (display_show_index) display->resizeColumnToContents (0);
-		else display->setColumnHidden (0, true);
-		display->setModel (model);
-		if (exp_mode == Detached) display->setItemDelegate (new RKOptionSetDelegate (this));
-		display->setSelectionBehavior (QAbstractItemView::SelectRows);
-		display->setSelectionMode (QAbstractItemView::SingleSelection);
-		connect (display->selectionModel (), SIGNAL (selectionChanged(QItemSelection,QItemSelection)), this, SLOT (currentRowChanged()));
-
-		if (keycolumn) display_buttons->setVisible (false);
-		else {
-			connect (add_button, SIGNAL (clicked()), this, SLOT (addRow()));
-			connect (remove_button, SIGNAL (clicked()), this, SLOT (removeRow()));
-		}
-	}
-	if (exp_mode == Accordion) {
-		accordion->setShowAddRemoveButtons (!keycolumn);
-		accordion->setModel (model);
-		if (display) display->hide ();
-	}
+	model->column_labels = visible_column_labels;
+	accordion->setShowAddRemoveButtons (!keycolumn);
+	accordion->setModel (model);
 }
 
 RKOptionSet::~RKOptionSet () {
@@ -212,33 +189,6 @@ void RKOptionSet::fetchDefaults () {
 	contents_container->enablednessProperty ()->setBoolValue (rowCount () > 0);	// no current row; Do this *after* fetching default values, however. Otherwise most values will *not* be read, as the element is disabled
 }
 
-RKComponent *RKOptionSet::createDisplay (bool show_index, QWidget *parent) {
-	RK_TRACE (PLUGIN);
-
-	RKComponent* dummy = new RKComponent (this, exp_mode == Regular ? parent : parentWidget ());
-	QVBoxLayout *layout = new QVBoxLayout (dummy);
-	layout->setContentsMargins (0, 0, 0, 0);
-	KHBox *box = new KHBox (dummy);
-	layout->addWidget (box);
-
-	if (display) {
-		RK_DEBUG (PLUGIN, DL_ERROR, "cannot create more than one optiondisplay per optionset");
-	} else {
-		display = new QTreeView (box);
-		display_show_index = show_index;
-		model = new RKOptionSetDisplayModel (this);
-	}
-
-	display_buttons = new KHBox (dummy);
-	layout->addWidget (display_buttons);
-	add_button = new QPushButton (RKStandardIcons::getIcon (RKStandardIcons::ActionInsertRow), QString (), display_buttons);
-	RKCommonFunctions::setTips (i18n ("Add a row / element"), add_button);
-	remove_button = new QPushButton (RKStandardIcons::getIcon (RKStandardIcons::ActionDeleteRow), QString (), display_buttons);
-	RKCommonFunctions::setTips (i18n ("Remove a row / element"), remove_button);
-
-	return (dummy);
-}
-
 QString serializeList (const QStringList &list) {
 	QString ret;
 	for (int i = 0; i < list.size (); ++i) {
@@ -404,7 +354,7 @@ void RKOptionSet::updateUnfinishedRows () {
 	if (!n_unfinished_rows) {	// done
 		if (switcher->currentWidget () != updating_notice) return;
 		current_row->setIntValue (return_to_row);
-		switcher->setCurrentWidget (user_area);
+		switcher->setCurrentWidget (accordion);
 		return;
 	}
 
@@ -437,7 +387,7 @@ void RKOptionSet::addRow (int row) {
 	if (row < 0) row = nrows;
 	RK_ASSERT (!keycolumn);
 
-	if (display) model->beginInsertRows (QModelIndex (), row, row);
+	model->beginInsertRows (QModelIndex (), row, row);
 	// adjust values
 	updating = true;
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
@@ -460,7 +410,7 @@ void RKOptionSet::addRow (int row) {
 	row_count->setIntValue (nrows + 1);
 	current_row->setIntValue (active_row = row);
 	setContentsForRow (active_row);
-	if (display) model->endInsertRows ();
+	model->endInsertRows ();
 
 	current_row->setIntValue (row);  // Setting this _again_, as the view might have messed with it following endInsertRows ()
 
@@ -483,7 +433,7 @@ void RKOptionSet::removeRow (int row) {
 	}
 	RK_ASSERT (!keycolumn);
 
-	if (display) model->beginRemoveRows (QModelIndex (), row, row);
+	model->beginRemoveRows (QModelIndex (), row, row);
 	updating = true;
 	// adjust values
 	QMap<RKComponentPropertyStringList *, ColumnInfo>::iterator it = column_map.begin ();
@@ -505,7 +455,7 @@ void RKOptionSet::removeRow (int row) {
 	row_count->setIntValue (nrows - 1);
 	current_row->setIntValue (active_row = row);
 	setContentsForRow (row);
-	if (display) model->endRemoveRows ();
+	model->endRemoveRows ();
 
 	current_row->setIntValue (row);  // Setting this _again_, as the view might have messed with it following endRemoveRows ()
 
@@ -774,8 +724,6 @@ void RKOptionSet::setContentsForRow (int row) {
 		applyContentsFromExternalColumn (col, row);
 	}
 	contents_container->enablednessProperty ()->setBoolValue (row >= 0);
-
-	if (exp_mode == Detached) switcher->show ();
 }
 
 void RKOptionSet::storeRowSerialization (int row) {
@@ -787,31 +735,11 @@ void RKOptionSet::storeRowSerialization (int row) {
 	contents_container->fetchPropertyValuesRecursive (&(rows[row].full_row_map));
 }
 
-int getCurrentRowFromDisplay (QTreeView* display) {
-	if (!(display && display->selectionModel () && display->model ())) return - 1;	// can happen during initialization
-	QModelIndexList l = display->selectionModel ()->selectedRows ();
-	if (l.isEmpty ()) return -1;
-	return (l[0].row ());
-}
-
 void RKOptionSet::updateCurrentRowInDisplay () {
-	if (!(display && display->selectionModel () && display->model ())) return;	// can happen during initialization
-	if (active_row < 0) display->selectionModel ()->clearSelection ();
-	else {
-		display->selectionModel ()->select (display->model ()->index (active_row, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
-	}
+	if (!(accordion && model)) return;	// can happen during initialization
 
-	if (exp_mode == Accordion) {
-		if (active_row < 0) accordion->collapseAll ();
-		else accordion->activateRow (active_row);
-	}
-}
-
-void RKOptionSet::currentRowChanged () {
-	RK_TRACE (PLUGIN);
-
-	RK_ASSERT (display);
-	currentRowChanged (getCurrentRowFromDisplay (display));
+	if (active_row < 0) accordion->collapseAll ();
+	else accordion->activateRow (active_row);
 }
 
 void RKOptionSet::currentRowChanged (int row) {
@@ -974,30 +902,4 @@ Qt::DropActions RKOptionSetDisplayModel::supportedDropActions () const {
     return Qt::MoveAction;
 }
 
-#include <QApplication>
-RKOptionSetDelegate::RKOptionSetDelegate (RKOptionSet* parent) : QItemDelegate (parent) {
-	set = parent;
-}
-
-void RKOptionSetDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
-	if (index.column () == 0) {
-		QStyleOptionButton button;
-		button.rect = option.rect;
-		button.text = i18n ("Edit");
-		button.state = QStyle::State_Enabled;
-		QApplication::style ()->drawControl (QStyle::CE_PushButton, &button, painter);
-	} else {
-		QItemDelegate::paint (painter, option, index);
-	}
-}
-
-bool RKOptionSetDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
-	if (event->type() == QEvent::MouseButtonRelease) {
-		set->setContentsForRow (index.row ());
-//		return true;
-	}
-	return QItemDelegate::editorEvent (event, model, option, index);
-}
-
-
 #include "rkoptionset.moc"
diff --git a/rkward/plugin/rkoptionset.h b/rkward/plugin/rkoptionset.h
index 48f5902..00120ed 100644
--- a/rkward/plugin/rkoptionset.h
+++ b/rkward/plugin/rkoptionset.h
@@ -41,7 +41,7 @@ public:
 	RKOptionSet (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget);
 	~RKOptionSet ();
 	int type () { return ComponentOptionSet; };
-	RKComponent *createDisplay (bool show_index, QWidget *parent);
+	void setDisplayShowIndex (bool show_index) { display_show_index = show_index; };
 	bool isValid ();
 	/** reimplemented from RKComponent */
 	ComponentStatus recursiveStatus ();
@@ -56,7 +56,6 @@ private slots:
 	void addRow ();
 	void removeRow (int which);
 	void removeRow ();
-	void currentRowChanged ();
 	void currentRowChanged (int row);
 	void fetchDefaults ();
 	void slotUpdateUnfinishedRows ();
@@ -112,19 +111,14 @@ friend class RKOptionSetDisplayModel;
 	QHash<QString, PropertyValueMap> former_row_states;
 
 	RKComponent *contents_container;
-	QWidget *display_buttons;
-	QPushButton *remove_button;
-	QPushButton *add_button;
 	bool display_show_index;
 	ComponentStatus last_known_status;
 
 	RKOptionSetDisplayModel* model;
-	QTreeView *display;
+	RKAccordionTable *accordion;
 
 	QStackedWidget *switcher;
 	QWidget *updating_notice;
-	QWidget *user_area;
-	RKAccordionTable *accordion;
 	void updateUnfinishedRows ();
 	int return_to_row;
 	QTimer update_timer;
@@ -133,12 +127,6 @@ friend class RKOptionSetDisplayModel;
 	int min_rows_if_any;
 	int max_rows;
 
-	enum ExperimentalMode {
-		Regular,
-		Detached,
-		Accordion
-	} exp_mode;
-
 	bool updating;
 /** Sets the contents from the values in given row */
 	void setContentsForRow (int row);
@@ -172,16 +160,4 @@ private slots:
 	void doResetNow ();
 };
 
-#include <QItemDelegate>
-
-class RKOptionSetDelegate : public QItemDelegate {
-	Q_OBJECT
-public:
-	RKOptionSetDelegate (RKOptionSet *parent);
-	void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
-	bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
-private:
-	RKOptionSet *set;
-};
-
 #endif
diff --git a/rkward/plugin/rkstandardcomponent.cpp b/rkward/plugin/rkstandardcomponent.cpp
index 81641cc..22fca99 100644
--- a/rkward/plugin/rkstandardcomponent.cpp
+++ b/rkward/plugin/rkstandardcomponent.cpp
@@ -676,7 +676,7 @@ void RKComponentBuilder::buildElement (const QDomElement &element, XMLHelper &xm
 		} else if (e.tagName () == QLatin1String ("optiondisplay")) {
 			RKComponent *set = component ()->parentComponent ();
 			if (set->type () == RKComponentBase::ComponentOptionSet) {
-				widget = static_cast<RKOptionSet *> (set)->createDisplay (xml.getBoolAttribute (e, "index", true, DL_INFO), parent_widget);
+				static_cast<RKOptionSet *> (set)->setDisplayShowIndex (xml.getBoolAttribute (e, "index", false, DL_INFO));
 			} else {
 				xml.displayError (&e, QString ("optiondisplay element is not allowed outside of an optionset"), DL_ERROR);
 			}



More information about the rkward-tracker mailing list