Ejemplo n.º 1
0
    void ConsoleWidget::clearExceptSeparators()
    {
        int rowCount = mModel->rowCount();

        for(int index = rowCount - 1; index >= 0; --index)
        {
            QStandardItem *item = mModel->item(index);

            Type type = item->data(TypeRole).value<Type>();

            if(type != Separator)
                mModel->removeRow(index);
        }

        if(mModel->rowCount() == 0)
            ui->clearPushButton->setEnabled(false);
    }
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
bool tCZoneModesModel::ModeStateOn( int modeIndex )
{
    QStandardItem* pItem = item( modeIndex );

    if (pItem != 0)
    {
        bool ok = false;
        int circuitIndex = pItem->data( INDEX_ROLE ).toInt( &ok );
        if ( ok )
        {
            tDigitalData state( tDataId( DATA_TYPE_SWITCH_STATE, circuitIndex, DATA_ENGINE_CZONE_SELECTION ) );
            bool on = (state.Value() > 0) ? true : false;
            return on;    
        }
    }

    return false;
}
Ejemplo n.º 3
0
void StandardItemModel::updateProgressItem(const QModelIndex& index, const int progressNumber) {

    QStandardItem* progressItem = this->getProgressItemFromIndex(index);

    int currentDownloadProgress = progressItem->data(ProgressRole).toInt();

    if (currentDownloadProgress != progressNumber) {

        // set progression :
        progressItem->setData(progressNumber, ProgressRole);

        if (this->isNzbItem(progressItem)) {
            emit parentProgressItemChangedSignal();
        }

    }

}
	QList<RIEXItem> AcceptRIEXDialog::GetSelectedItems () const
	{
		QList<RIEXItem> result;

		const auto itp = Core::Instance ().GetProxy ()->GetTagsManager ();
		for (int i = 0, size = Model_->rowCount (); i < size; ++i)
		{
			QStandardItem *item = Model_->item (i);
			if (item->checkState () != Qt::Checked)
				continue;

			auto riex = item->data ().value<RIEXItem> ();
			riex.Groups_ = itp->Split (Model_->item (i, Column::Groups)->text ());
			result << riex;
		}

		return result;
	}
Ejemplo n.º 5
0
QStringList Channel::findUsersByPrefix(QString searchStr)
{
    QStringList userList = QStringList();

    // prevents bug when trying to tab before connected to a channel
    if (this != NULL)
    {
        QModelIndex startIndex = users->index(0, 0);
        QModelIndexList foundUsers = users->match(startIndex, User::UserDataName, searchStr, -1, Qt::MatchStartsWith);
        for(QModelIndexList::Iterator iter = foundUsers.begin(); iter != foundUsers.end(); iter++) {
            QStandardItem *user = users->itemFromIndex(*iter);
            QString username = user->data(User::UserDataName).value<QString>();
            userList.append(username);
        }
    }

    return userList;
}
Ejemplo n.º 6
0
void GlobalSearchView::LazyLoadArt(const QModelIndex& proxy_index) {
    if (!proxy_index.isValid() || proxy_index.model() != front_proxy_) {
        return;
    }

    // Already loading art for this item?
    if (proxy_index.data(GlobalSearchModel::Role_LazyLoadingArt).isValid()) {
        return;
    }

    // Should we even load art at all?
    if (!app_->library_model()->use_pretty_covers()) {
        return;
    }

    // Is this an album?
    const LibraryModel::GroupBy container_type = LibraryModel::GroupBy(
                proxy_index.data(LibraryModel::Role_ContainerType).toInt());
    if (container_type != LibraryModel::GroupBy_Album &&
            container_type != LibraryModel::GroupBy_AlbumArtist &&
            container_type != LibraryModel::GroupBy_YearAlbum &&
            container_type != LibraryModel::GroupBy_OriginalYearAlbum) {
        return;
    }

    // Mark the item as loading art
    const QModelIndex source_index = front_proxy_->mapToSource(proxy_index);
    QStandardItem* item = front_model_->itemFromIndex(source_index);
    item->setData(true, GlobalSearchModel::Role_LazyLoadingArt);

    // Walk down the item's children until we find a track
    while (item->rowCount()) {
        item = item->child(0);
    }

    // Get the track's Result
    const SearchProvider::Result result =
        item->data(GlobalSearchModel::Role_Result)
        .value<SearchProvider::Result>();

    // Load the art.
    int id = engine_->LoadArtAsync(result);
    art_requests_[id] = source_index;
}
Ejemplo n.º 7
0
void ModelProjectImpl::doubleClickedTree(QModelIndex index)
{
    if (!index.isValid()) {
        return;
    }
    QStandardItem *item = m_file->model()->itemFromIndex(index);
    if (!item) {
        return;
    }
    bool ok;
    int itemType = item->data().toInt(&ok);
    if (ok && ( itemType == ModelFileImpl::ItemFile ||
               itemType == ModelFileImpl::ItemProFile ) ) {
        QString fileName = m_file->fileNameToFullPath(item->text());
        if (!fileName.isEmpty()) {
            m_liteApp->fileManager()->openEditor(fileName);
        }
    }
}
Ejemplo n.º 8
0
/** Export one playlist at a time. */
void PlaylistDialog::exportSelectedPlaylist()
{
	QString exportedPlaylistLocation;
	SettingsPrivate *settings = SettingsPrivate::instance();
	if (settings->value("locationForExportedPlaylist").isNull()) {
		exportedPlaylistLocation = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
	} else {
		exportedPlaylistLocation = settings->value("locationForExportedPlaylist").toString();
	}
	auto indexes = savedPlaylists->selectionModel()->selectedIndexes();
	if (indexes.isEmpty()) {
		return;
	}

	QStandardItem *item = _savedPlaylistModel->itemFromIndex(indexes.first());
	uint playlistId = item->data(PlaylistID).toUInt();
	auto db = SqlDatabase::instance();
	PlaylistDAO dao = db->selectPlaylist(playlistId);
	QString title = this->convertNameToValidFileName(dao.title());

	// Open a file dialog and ask the user to choose a location
	QString newName = QFileDialog::getSaveFileName(this, tr("Export playlist"), exportedPlaylistLocation + QDir::separator() + title, tr("Playlist (*.m3u8)"));
	if (QFile::exists(newName)) {
		QFile removePreviousOne(newName);
		if (!removePreviousOne.remove()) {
			qDebug() << Q_FUNC_INFO << "Cannot remove" << newName;
		}
	}
	if (newName.isEmpty()) {
		return;
	} else {
		QFile f(newName);
		if (f.open(QIODevice::ReadWrite | QIODevice::Text)) {
			QTextStream stream(&f);
			QList<TrackDAO> tracks = db->selectPlaylistTracks(playlistId);
			for (TrackDAO t : tracks) {
				stream << t.uri();
				endl(stream);
			}
		}
		f.close();
	}
}
Ejemplo n.º 9
0
// 打开菜单
void RelateDocDialog::openRelateDoc()
{
    QItemSelectionModel *selections = docsView->selectionModel();
    QModelIndexList selected = selections->selectedIndexes();

    // 选择第一个
    QModelIndex index = selected.at(0);
    QStandardItem* item = model->item(index.row(), 3);
    QString docUuid = qvariant_cast<QString>(item->data(Qt::DisplayRole));

    Doc doc = DocDao::selectDoc(docUuid);
    QString filepath = doc.DOCUMENT_LOCATION;
    QFileInfo fileInfo(filepath);
    if(!fileInfo.exists()){
        QMessageBox::warning(this, tr("Warning"), tr("Please Confirm The original file  has Deleted Or Moved. "), QMessageBox::Yes);
        return;
    }
    QDesktopServices::openUrl ( QUrl::fromLocalFile(filepath) );
}
Ejemplo n.º 10
0
void InternetModel::RemoveService(InternetService* service) {
  if (!sServices->contains(service->name())) return;

  // Find and remove the root item that this service created
  for (int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
    QStandardItem* item = invisibleRootItem()->child(i);
    if (!item ||
        item->data(Role_Service).value<InternetService*>() == service) {
      invisibleRootItem()->removeRow(i);
      break;
    }
  }

  // Remove the service from the list
  sServices->remove(service->name());

  // Disconnect the service
  disconnect(service, 0, this, 0);
}
Ejemplo n.º 11
0
void TelescopeDialog::retranslate()
{
	if (dialog)
	{
		ui->retranslateUi(dialog);
		setAboutText();
		setHeaderNames();
		updateWarningTexts();
		
		//Retranslate type strings
		for (int i = 0; i < telescopeListModel->rowCount(); i++)
		{
			QStandardItem* item = telescopeListModel->item(i, ColumnType);
			QString original = item->data(Qt::UserRole).toString();
			QModelIndex index = telescopeListModel->index(i, ColumnType);
			telescopeListModel->setData(index, q_(original), Qt::DisplayRole);
		}
	}
}
Ejemplo n.º 12
0
	void BookmarksManagerDialog::on_AddButton__released ()
	{
		if (!CurrentEditor_)
		{
			qWarning () << Q_FUNC_INFO
					<< "no editor available";
			return;
		}

		QStandardItem *selected = GetSelectedItem ();
		const QVariantMap& data = selected ?
				selected->data ().toMap () :
				CurrentEditor_->GetIdentifyingData ();

		QStandardItem *item = new QStandardItem (data.value ("HumanReadableName").toString ());
		item->setData (data);
		BMModel_->appendRow (item);
		Ui_.BookmarksTree_->setCurrentIndex (BMModel_->indexFromItem (item));
	}
Ejemplo n.º 13
0
	void BookmarksManagerDialog::on_RemoveButton__released ()
	{
		QStandardItem *item = GetSelectedItem ();
		if (!item)
			return;

		const auto& data = item->data ().toMap ();

		if (QMessageBox::question (this,
				"LeechCraft",
				tr ("Are you sure you want to delete the bookmark %1?")
					.arg (data.value ("HumanReadableName").toString ()),
				QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
			return;

		BMModel_->removeRow (item->row ());

		Save ();
	}
Ejemplo n.º 14
0
bool FileOrganiserWidget::ownedBy(const QString &pFileName,
                                  QStandardItem *pItem)
{
    // Check whether pFileName is already owned by pItem

    for (int i = 0, iMax = pItem->rowCount(); i < iMax; ++i) {
        // Check whether the current item is a file with pFileName as its name

        QStandardItem *crtItem = pItem->child(i);

        if (   !crtItem->data(Item::Folder).toBool()
            && (crtItem->data(Item::Path).toString() == pFileName))
            return true;
    }

    // We couldn't find a file with pFileName as its name in pItem, so...

    return false;
}
Ejemplo n.º 15
0
// assumes model is not modified while we are writing it out
void UpdatingFileModel::saveModelToFile()
{
  QFile file(fileName);
  if (!file.open(QFile::WriteOnly | QIODevice::Text)) {
    qWarning() << "Cannot load model from file" << fileName;
    return;
  }

  QTextStream out(&file);

  QStandardItem* root = invisibleRootItem();
  int r = root->rowCount();
  for (int i = 0; i < r; ++i) {
    QStandardItem* it = root->child(i);
    out << it->data(Qt::DisplayRole).toString() << "\n";
  }

  file.close();
}
Ejemplo n.º 16
0
	void RoomConfigWidget::on_ModifyPerm__released ()
	{
		QStandardItem *stdItem = GetCurrentItem ();
		if (!stdItem)
			return;

		QStandardItem *parent = stdItem->parent ();
		if (!Aff2Cat_.values ().contains (parent))
		{
			qWarning () << Q_FUNC_INFO
					<< "bad parent"
					<< parent
					<< "for"
					<< stdItem;
			return;
		}

		const QXmppMucItem::Affiliation aff = Aff2Cat_.key (parent);
		const QString& jid = stdItem->text ();

		std::unique_ptr<AffiliationSelectorDialog> dia (new AffiliationSelectorDialog (this));
		dia->SetJID (jid);
		dia->SetAffiliation (aff);
		dia->SetReason (stdItem->data (ItemRoles::Reason).toString ());
		if (dia->exec () != QDialog::Accepted)
			return;

		const QString& newJid = dia->GetJID ();
		if (newJid.isEmpty ())
			return;

		parent->removeRow (stdItem->row ());

		QXmppMucItem item;
		item.setJid (newJid);
		item.setAffiliation (dia->GetAffiliation ());
		item.setReason (dia->GetReason ());
		SendItem (item);

		if (item.affiliation () != QXmppMucItem::NoAffiliation)
			handlePermsReceived ({ item });
	}
Ejemplo n.º 17
0
/// Vergleich zwischen zwei Items für Sortierung.
/// Ordner haben Vorrang vor Dateien und sonst wird alphabetisch sortiert.
bool Structureelement::operator< (const QStandardItem& other) const
{

    if ((typeEX != fileItem) && (other.type() == fileItem))
    {
        return true;
    }
    else if ((typeEX == fileItem) && (other.type() != fileItem))
    {
        return false;
    }
    else if (typeEX == messageItem)
    {
        return (data(dateRole) < other.data(dateRole));
    }
    else
    {
        return (text().toLower() < other.text().toLower());
    }
}
Ejemplo n.º 18
0
/**
  * SLOT
  * Load songs from playlist
  * selected in QTreeView ui->tvPlaylists
  */
void MainWindow::loadPlaylist()
{
    QStandardItemModel *model = (QStandardItemModel*)ui->tvPlaylists->model();
    QStandardItem *item = model->itemFromIndex(ui->tvPlaylists->selectionModel()->currentIndex());
    int data = item->data(DATA_KEY_PLAYLIST).toInt();

    switch(data) {
        case DATA_SEARCH:
            loadSearchResults();
            break;
        case DATA_EMPTY:
            break; // do nothing
        case DATA_HISTORY:
            loadHistory();
            break;
        default:
            loadPlaylist(data);
            break;
    }
}
Ejemplo n.º 19
0
void BrowserView::mark_tag(MenuCheckBox *m, int state)
{
	DatabaseLocker lock(db_);

	QModelIndexList selected = this->selectedIndexes();
	if(selected.isEmpty())
		return ;

	for(const QModelIndex& index: selected)
	{
		QStandardItem* qitem = ((QStandardItemModel*)model())->itemFromIndex(index);
		file_hash_t hash = qitem->data(IMAGE_QVARIANT_ROLE).value<file_hash_t>();
		ImageDescription_ptr e = db_->images().get_image_description(hash);

		if(state == Qt::Unchecked)
			db_->tags().erase_tag(e->hash, m->tagid);
		else
			db_->tags().add_tag(e->hash, m->tagid);
	}
}
Ejemplo n.º 20
0
void BrowserView::copy_filepath()
{
	QModelIndexList selected = this->selectedIndexes();
	if(selected.isEmpty())
		return ;


	DatabaseLocker l(db_);

	QString path;
	for(const QModelIndex& index: selected)
	{
		QStandardItem* qitem = ((QStandardItemModel*)model())->itemFromIndex(index);
		file_hash_t hash = qitem->data(IMAGE_QVARIANT_ROLE).value<file_hash_t>();
		ImageDescription_ptr desc = db_->images().get_image_description(hash);

		path += ("\"file:///" + db_->images().storage_location() + "/" + desc->path + "\" ");
	}
	QApplication::clipboard()->setText(path);
}
Ejemplo n.º 21
0
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void tCZoneModesModel::SelectMode( int modeIndex )
{
    QStandardItem* pItem = item( modeIndex );

    if (pItem != 0)
    {
        bool ok;
        int circuitIndex = pItem->data( INDEX_ROLE ).toInt( &ok );
        if ( ok )
        {
            tCZoneKeyPressJob keyPressJob;
            keyPressJob.m_index = circuitIndex;
            keyPressJob.m_turningOn = pItem->checkState() == Qt::Unchecked;
            m_keyPressJobs.append( keyPressJob );

            m_CZoneLibrary->KeyPressed( circuitIndex, keyPressJob.m_turningOn );
            QTimer::singleShot( 50, this, SLOT( KeyReleaseTimerHandler() ) );
        }
    }
}
Ejemplo n.º 22
0
void BrowserView::clear_tags()
{
	QModelIndexList selected = this->selectedIndexes();
	if(selected.isEmpty())
		return ;

	if(QMessageBox::question(this, "Clear tags",
		"Are you sure you want to clear all tags from selected files?",
		QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
	{
		DatabaseLocker l(db_);

		for(const QModelIndex& index: selected)
		{
			QStandardItem* qitem = ((QStandardItemModel*)model())->itemFromIndex(index);
			file_hash_t hash = qitem->data(IMAGE_QVARIANT_ROLE).value<file_hash_t>();

			db_->tags().erase_all_tags(hash);
		}
	}
}
Ejemplo n.º 23
0
void SearchDialog::artistWasDoubleClicked(const QModelIndex &artistIndex)
{
	const QStandardItemModel *m = qobject_cast<const QStandardItemModel*>(artistIndex.model());
	QStandardItem *item = m->itemFromIndex(artistIndex);

	SqlDatabase db;

	QSqlQuery q(db);
	q.prepare("SELECT uri FROM cache WHERE artist = ?");
	q.addBindValue(item->data(Miam::DF_Artist).toString());
	if (q.exec()) {
		QList<QMediaContent> tracks;
		while (q.next()) {
			tracks.append(QMediaContent(QUrl::fromLocalFile(q.record().value(0).toString())));
		}

		Playlist *p = _viewPlaylists->tabPlaylists->currentPlayList();
		p->insertMedias(-1, tracks);
	}
	this->clear();
}
/**
 * @brief Returns the item with the specified directory name.
 * @param parent The parent item.
 * @param dir_name Name of the subdirectory to get.
 * @return The child. It is created if it does not exist yet.
 */
QStandardItem* ResourceModel::find_or_create_dir_item(
    QStandardItem& parent, const QString& dir_name) {

  for (int i = 0; i < parent.rowCount(); ++i) {
    QStandardItem* child = parent.child(i, 0);
    QString name = child->data(Qt::DisplayRole).toString();
    if (name == dir_name) {
      return child;
    }

    if (name > dir_name) {
      child = create_dir_item(dir_name);
      parent.insertRow(i, child);
      return child;
    }
  }

  QStandardItem* child = create_dir_item(dir_name);
  parent.appendRow(child);
  return child;
}
Ejemplo n.º 25
0
void CodeEditor::select(QStandardItem *parent,const QStandardItem *sourceParent)
{
    for (int i=0; i<sourceParent->rowCount(); ++i)
    {
       QStandardItem *child = sourceParent->child(i);

       QStandardItem *item = child->QStandardItem::clone();
       item->setToolTip(child->toolTip());
       assert(item);

       QString text = child->data(Item::DescriptionRole).toStringList().join('\n');
       QStandardItem *desitem = new QStandardItem(text);
       desitem->setForeground(Qt::darkGreen);
       desitem->setEditable(false);

       parent->appendRow(QList<QStandardItem *>() << item << desitem);

       if(child->hasChildren())
           select(item,child);
    }
}
Ejemplo n.º 26
0
void BE::Contacts::manageContact(const QString &mail, const QString &prettyName)
{
    QStandardItemModel *model = m_abook->model();
    for (int i = 0; i < model->rowCount(); ++i) {
        QStandardItem *item = model->item(i);
        if (QString::compare(item->data(Gui::AbookAddressbook::Mail).toString(), mail, Qt::CaseInsensitive) == 0) {
            setContact(model->index(i, 0));
            return;
        }
    }

    // no match -> create one
    addContact();
    m_ui2->mail->setText(mail);
    if (!prettyName.isEmpty()) {
        m_ui2->name->setText(prettyName);
        m_currentContact->setText(prettyName);
    } else {
        m_ui2->name->setText("[name]");
    }
}
QModelIndex AbstractCameraManager::detectNewCamerasAndExpand() {
    std::vector<AbstractCamera*> newCameras;
    std::vector<QStandardItem*> oldCameras;
    cameraTree_getCameraList(cameraTree.invisibleRootItem(), &oldCameras);
    detectNewCameras(&newCameras);
    qDebug() << "oldCameras" << oldCameras.size();
    qDebug() << "newCameras" << newCameras.size();
    //removing disconnected cameras
    for(unsigned int i=0; i<oldCameras.size(); i++) {
        QStandardItem* item = oldCameras.at(i);
        AbstractCamera* cam = reinterpret_cast<AbstractCamera *>( item->data(CameraRole).value<quintptr>() );
        qDebug() << "oldCameras(" << i << "):" << cam;
        bool found = false;
        for(int j=newCameras.size()-1; j>=0; j--) {
            if(cam->equalsTo(newCameras.at(j))) {
                found = true;
                newCameras.erase(newCameras.begin()+j);
                continue;
            }
        }
        if( !found ) { //remove if disconnected
            activateCamera(cam, item, false);
            item->parent()->removeRow(item->row());
        }
    }
    qDebug() << "newCameras" << newCameras.size();
    //adding new cameras
    for(unsigned int i=0; i<newCameras.size(); i++) {
        AbstractCamera* cam = newCameras.at(i);
        QStandardItem *item = new QStandardItem(cam->getString().c_str());
        item->setData(QVariant::fromValue( reinterpret_cast<quintptr>(cam) ), CameraRole);
        //qDebug() << "setData " << camera << " data " << item->data(CameraRole).value<AbstractCamera *>();
        item->setCheckable(true);
        item->setCheckState(Qt::Unchecked);
        item->setDropEnabled(false);
        newCameraList.appendRow(item);
    }

    return newCameraList.index();
}
Ejemplo n.º 28
0
QStandardItem* HistoryContentsWidget::findEntry(qint64 entry)
{
	for (int i = 0; i < m_model->rowCount(); ++i)
	{
		QStandardItem *groupItem = m_model->item(i, 0);

		if (groupItem)
		{
			for (int j = 0; j < groupItem->rowCount(); ++j)
			{
				QStandardItem *entryItem = groupItem->child(j, 0);

				if (entryItem && entry == entryItem->data(Qt::UserRole).toLongLong())
				{
					return entryItem;
				}
			}
		}
	}

	return NULL;
}
Ejemplo n.º 29
0
// 删除关联文档
void RelateDocDialog::deleteRelateDoc()
{

    int ret = QMessageBox::question(this, "", tr("Are you sure that delete the related Doc ?"),
                                    QMessageBox::Yes, QMessageBox::No);
    if(ret == QMessageBox::Yes){

        QItemSelectionModel *selections = docsView->selectionModel();
        QModelIndexList selected = selections->selectedIndexes();
        QMap<int, int> rowMap;

        foreach (QModelIndex index, selected)
        {
            rowMap.insert(index.row(), 0);

            QStandardItem* item = model->item(index.row(), 3);
            QString relateDocUuid = qvariant_cast<QString>(item->data(Qt::DisplayRole));
            RelateDoc relateDoc;
            relateDoc.DOCUMENT_GUID = m_docUuid;
            relateDoc.DOCUMENT_GUID = relateDocUuid;
            RelateDocDao::deleteRelateDoc(relateDoc);
        }
Ejemplo n.º 30
0
	void CookiesEditModel::RemoveCookie (const QModelIndex& index)
	{
		if (!index.isValid ())
			return;
	
		QStandardItem *item = itemFromIndex (index);
		int i = item->data ().toInt ();
		if (i == -1)
		{
			for (int j = 0; j < item->rowCount (); ++j)
			{
				Cookies_.remove (item->child (j)->data ().toInt ());
			}
			qDeleteAll (takeRow (item->row ()));
		}
		else
		{
			Cookies_.remove (i);
			qDeleteAll (item->parent ()->takeRow (item->row ()));
		}
		Jar_->setAllCookies (Cookies_.values ());
	}