2012-03-01 11 views
1

ここにアイデアがあります:私はセクションごとにグループ化されたパラメータのリスト(名前、型、値、多分何か、入力用の正規表現)を持っています。それらはxmlファイルに格納されています(たとえば、おそらく他の形式)。私はこのファイルに依存する "標準的な"設定ダイアログを構築するモジュールを作りたいと思っています。このように settings セクション名はリストとして左側に、選択されたセクションにはパラメータが右側に表示されていなければなりません:名前はラベルの一部であり、入力フィールドの値はパラメータのタイプに依存します(テキストの場合はlineEdit 、spinEdit - 数字の場合は、checkBox - ブール値の場合など) 最後に質問:私の目的のために "ready-for-use"ダイアログがありますか? ありがとうございます。設定のダイアログを使用する準備ができましたか?

+0

をそれを見つけることができます。長い答えは、誰かがそれをしている可能性があるということなので、いくつかのGoogle検索を行います。まだ何かを見つけることができない場合は、自分で作って他の人が使用するために公開しないでください。 –

+0

ありがとう、ありがとう。私はたくさんの検索を行ったが、成功はなかった。もちろん、私はすぐに解決策を見つけることはできません。ところで、私はPSI IMでこれを見ました... – borisbn

答えて

0

私はしばらくの間検索しましたが、何の決定もありませんでした。だから私はそれを自分で書くことに決めました。 ここで少し説明です:

1メインコンセプト

あなたのプログラムは、あなたが、あなただけの、適切な形式のXMLファイルを記述したクラスのインスタンスを作成する必要がありますGUIから編集可能にすることを、いくつかのパラメータを持っている場合クラスコンフィグ

の最後にコンフィグ、コールスロットコンフィグ::ショー()とConfigを介して、必要なパラメータを求める::(取得)

2使用あなたはどこでもあなたが望むそれを作成することができます。 c-torまたはConfig :: load()メソッドの中でxmlファイル名/パスを指定することができます。 Config :: get()メソッドを呼び出すことによって、プログラムの任意の場所にある任意のパラメータを得ることができます。 クラスコンフィグの使用方法の例:

Config config("full/path/to/settings.xml"); 
connect(settingsAction, SIGNAL(trigger()), &config, SLOT(show())); 
... 
if (config.get("section_name", "param_name").toBool()) { 
    ... 
} 
QFile file(config.get("section_name", "directory_for_log").toString() + 
    "/prog.log"); 

3制限

ConfigがQtCore、QtGuiとQtXmlを必要としています。 C++ 11の機能を使用します。

4 XML-ファイル形式

申し訳ありませんが、私は完全な説明を記述するのが面倒だけど、私は、すべての機能を備えた完全な例を記述します。私は

std::ostream & operator<< (std::ostream & os, const QVariant & var) { 
    if (var.type() == QVariant::Bool) { 
     os << var.toBool(); 
    } 
    else if (var.type() == QVariant::Int) { 
     os << var.toInt(); 
    } 
    else if (var.type() == QVariant::String) { 
     os << qPrintable(var.toString()); 
    } 
    return os; } 

cout << "First group checked : " << cfg.get("First section name", "First group") << endl; 
cout << "Ip address:port : " << cfg.get("First section name", "Ip address:port") << endl; 
cout << "Some bool value : " << cfg.get("First section name", "Some bool value") << endl; 
cout << "Choose 1 : " << cfg.get("First section name", "Choose 1") << endl; 
cout << "Picture or sound : " << cfg.get("First section name", "Picture or sound") << endl; 
cout << "Choose 2 : " << cfg.get("First section name", "Choose 2") << endl; 
cout << "Dir for log : " << cfg.get("First section name", "Dir for log") << endl; 
cout << "Length : " << cfg.get("First section name", "Length") << endl; 
cout << "Weight : " << cfg.get("First section name", "Weight") << endl; 
cout << "Just bool : " << cfg.get("First section name", "Just bool") << endl; 
cout << "Greet me : " << cfg.get("Second sect", "Greet me") << endl; 
cout << "Invisible bool : " << cfg.get("Second sect", "Invisible bool") << endl; 

このファイルに絵が enter image description here

であり、ここでコンフィグの使用であるあなたが、ここでそれらをすべて:)

<?xml version="1.0" encoding="System"?> 
<config> 
    <section visible="true" name="First section name"> 
     <group visible="true" checkable="true" checked="true" name="First group"> 
      <value visible="true" type="text" value="192.168.1.1:1234" regexp="ip-addr:port" name="Ip address:port"/> 
      <value visible="true" type="bool" value="false" name="Some bool value"/> 
      <value visible="true" type="combo" value="Just three" items="The one;The two;Just three" name="Choose 1"/> 
      <value visible="true" type="file" value="/etc/some/file.jpg" name="Picture or sound" filters="Images (*.png *.jpg);;Sounds (*.mp3 *.wav)"/> 
      <value visible="true" type="radio" value="Fourth" items="First;Second;Third;Fourth" name="Choose 2"/> 
      <value visible="true" type="dir" value="/etc" name="Dir for log"/> 
     </group> 
     <group visible="true" checkable="false" checked="true" name="Second group"> 
      <value unit=" cm" visible="true" type="int" value="18" min="1" name="Length" max="33"/> 
      <value unit=" kg" visible="true" type="int" value="42" min="0" name="Weight" max="100"/> 
     </group> 
     <value visible="true" type="bool" value="true" name="Just bool"/> 
    </section> 
    <section visible="true" name="Second sect"> 
     <value visible="true" type="text" value="hello" regexp="(hello)+" name="Greet me"/> 
     <value visible="false" type="bool" value="true" name="Invisible bool"/> 
    </section> 
</config> 

を理解するだろうと、考え、最終的には、することができますソースコードを公開する最善の方法を教えてください。 ありがとうございます。

UPD:あなたは短い答えはノーである、ここでhttps://sourceforge.net/projects/guisettings/

0

このようなダイアログはありません。

"フル"ダイアログを手動で作成し、特定のケースで使用されていない要素を無効/非表示にする方法はありますか?

+0

私は "完全な"ダイアログが何かを理解できません...私はすべての(またはほとんどの)私のGUIプロジェクトのためにそのようなダイアログを使って多目的モジュールを作成したい、カスタマイズする必要があります – borisbn

+0

次にパーサーを作成する必要がありますxml/json /任意の設定を読み込み、GUIに特定のダイアログを追加します。 – neciu

+0

neciu、私はこれをはっきりと理解していますが、私は自転車を発明したくありません。準備が整ったモジュールが見つからない場合は、もちろん自分で作成します – borisbn

関連する問題