connect( mProxy, SIGNAL( recordListChange() ), SLOT( slotRecordListChanged() ) );
		connect( mProxy, SIGNAL( updateRecordList() ), SLOT( slotUpdateRecordList() ) );
	}
}
	
void FieldCheckBox::slotRecordListChanged()
{
	if( mProxy && !mField.isEmpty() ){
		RecordList rl = mProxy->records();
		QList<QVariant> vals = rl.getValue( mField );
		QList<bool> boolVals;
		foreach( QVariant v, vals ) {
			boolVals.append( v.toBool() );
		}
		// get unique values
		boolVals = boolVals.toSet().toList();
		Qt::CheckState checkState = boolVals.size() == 1 ? (boolVals[0] ? Qt::Checked : Qt::Unchecked) : Qt::PartiallyChecked;
		setTristate( checkState == Qt::PartiallyChecked );
		setCheckState( checkState );
	}
}

void FieldCheckBox::slotUpdateRecordList()
{
	Qt::CheckState cs = checkState();
	if( cs != Qt::PartiallyChecked ) {
		mProxy->records().setValue( mField, bool(cs == Qt::Checked) );
	}
}

Example #2
0
void IconList::directoryChanged(const QString &path)
{
	QDir new_dir (path);
	if(m_dir.absolutePath() != new_dir.absolutePath())
	{
		m_dir.setPath(path);
		m_dir.refresh();
		if(is_watching)
			stopWatching();
		startWatching();
	}
	if(!m_dir.exists())
		if(!ensureFolderPathExists(m_dir.absolutePath()))
			return;
	m_dir.refresh();
	auto new_list = m_dir.entryList(QDir::Files, QDir::Name);
	for (auto it = new_list.begin(); it != new_list.end(); it++)
	{
		QString &foo = (*it);
		foo = m_dir.filePath(foo);
	}
	auto new_set = new_list.toSet();
	QList<QString> current_list;
	for (auto &it : icons)
	{
		if (!it.has(MMCIcon::FileBased))
			continue;
		current_list.push_back(it.m_images[MMCIcon::FileBased].filename);
	}
	QSet<QString> current_set = current_list.toSet();

	QSet<QString> to_remove = current_set;
	to_remove -= new_set;

	QSet<QString> to_add = new_set;
	to_add -= current_set;

	for (auto remove : to_remove)
	{
		QLOG_INFO() << "Removing " << remove;
		QFileInfo rmfile(remove);
		QString key = rmfile.baseName();
		int idx = getIconIndex(key);
		if (idx == -1)
			continue;
		icons[idx].remove(MMCIcon::FileBased);
		if (icons[idx].type() == MMCIcon::ToBeDeleted)
		{
			beginRemoveRows(QModelIndex(), idx, idx);
			icons.remove(idx);
			reindex();
			endRemoveRows();
		}
		else
		{
			dataChanged(index(idx), index(idx));
		}
		m_watcher->removePath(remove);
		emit iconUpdated(key);
	}

	for (auto add : to_add)
	{
		QLOG_INFO() << "Adding " << add;
		QFileInfo addfile(add);
		QString key = addfile.baseName();
		if (addIcon(key, QString(), addfile.filePath(), MMCIcon::FileBased))
		{
			m_watcher->addPath(add);
			emit iconUpdated(key);
		}
	}
}