src/checkboxgroup.h

Mon, 13 May 2013 00:04:54 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 13 May 2013 00:04:54 +0300
changeset 193
ce8e25ccbaf6
parent 191
9bb6a17305ad
permissions
-rw-r--r--

Added wireframe mode

#include <QGroupBox>
#include <QCheckBox>
#include <QBoxLayout>
#include <map>

QBoxLayout::Direction makeDirection (Qt::Orientation orient, bool invert = false);

template<class T> class CheckBoxGroup : public QGroupBox {
public:
	CheckBoxGroup (const char* label, Qt::Orientation orient = Qt::Horizontal, QWidget* parent = null) : QGroupBox (parent) {
		m_layout = new QBoxLayout (makeDirection (orient));
		setTitle (label);
		setLayout (m_layout);
	}
	
	void addCheckBox (const char* label, T key, bool checked = false) {
		if (m_vals.find (key) != m_vals.end ())
			return;
		
		QCheckBox* box = new QCheckBox (label);
		box->setChecked (checked);
		
		m_vals[key] = box;
		m_layout->addWidget (box);
	}
	
	std::vector<T> checkedValues () const {
		std::vector<T> vals;
		
		for (const auto& kv : m_vals)
			if (kv.second->isChecked ())
				vals.push_back (kv.first);
		
		return vals;
	}
	
private:
	QBoxLayout* m_layout;
	std::map<T, QCheckBox*> m_vals;
};

mercurial