Exemplo n.º 1
0
void View::infoSelected(QTreeWidgetItem* item, int column)
{
  Q_UNUSED(column);

  QString path = item->data(0, Qt::ToolTipRole).toString();
  uint line = item->data(1, Qt::ToolTipRole).toUInt();
  uint col = item->data(2, Qt::ToolTipRole).toUInt();

  if(!path.isEmpty() && QFile::exists(path)) {
    KUrl url(path);
    KTextEditor::View* kv = mw->openUrl(url);
    if(line > 0) {
      kv->setCursorPosition(KTextEditor::Cursor(line - 1, col - 1));
    } else {
      // Line = 0 is used to show information about a file.
      // Just go to the beginning.
      kv->setCursorPosition(KTextEditor::Cursor(0, 0));
    }
    kv->setFocus();
    kDebug() << "Opened file: " << path;
  } else {
    setStatus(i18n("File not found: %1", path));
  }
}
Exemplo n.º 2
0
void DataOutputWidget::slotExport()
{
  if (m_model->rowCount() <= 0)
    return;

  while (m_model->canFetchMore())
    m_model->fetchMore();

  if (!m_view->selectionModel()->hasSelection())
    m_view->selectAll();

  ExportWizard wizard(this);

  if (wizard.exec() != QDialog::Accepted)
    return;

  bool outputInDocument = wizard.field("outDocument").toBool();
  bool outputInClipboard = wizard.field("outClipboard").toBool();
  bool outputInFile = wizard.field("outFile").toBool();

  bool exportColumnNames = wizard.field("exportColumnNames").toBool();
  bool exportLineNumbers = wizard.field("exportLineNumbers").toBool();

  Options opt = NoOptions;

  if (exportColumnNames)
    opt |= ExportColumnNames;
  if (exportLineNumbers)
    opt |= ExportLineNumbers;

  bool quoteStrings = wizard.field("checkQuoteStrings").toBool();
  bool quoteNumbers = wizard.field("checkQuoteNumbers").toBool();

  QChar stringsQuoteChar = (quoteStrings) ? wizard.field("quoteStringsChar").toString().at(0) : '\0';
  QChar numbersQuoteChar = (quoteNumbers) ? wizard.field("quoteNumbersChar").toString().at(0) : '\0';

  QString fieldDelimiter = wizard.field("fieldDelimiter").toString();

  if (outputInDocument)
  {
    Kate::MainWindow *mw = Kate::application()->activeMainWindow();
    KTextEditor::View *kv = mw->activeView();

    if (!kv)
      return;

    QString text;
    QTextStream stream(&text);

    exportData(stream, stringsQuoteChar, numbersQuoteChar, fieldDelimiter, opt);

    kv->insertText(text);
    kv->setFocus();
  }
  else if (outputInClipboard)
  {
    QString text;
    QTextStream stream(&text);

    exportData(stream, stringsQuoteChar, numbersQuoteChar, fieldDelimiter, opt);

    kapp->clipboard()->setText(text);
  }
  else if (outputInFile)
  {
    QString url = wizard.field("outFileUrl").toString();
    QFile data(url);
    if (data.open(QFile::WriteOnly | QFile::Truncate))
    {
      QTextStream stream(&data);

      exportData(stream, stringsQuoteChar, numbersQuoteChar, fieldDelimiter, opt);

      stream.flush();
    }
    else
    {
      KMessageBox::error(this, i18nc("@info", "Unable to open file <filename>%1</filename>").arg(url));
    }
  }
}